name: Build and Publish
on:
  push:
    branches: [main]
jobs:
  build_and_publish:
    name: "Build and publish"
    if: ${{ github.repository == 'microsoft/rnx-kit' }}
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup the toolchain
        uses: ./.github/actions/setup-toolchain
        with:
          go-version: "^1.14.0"
      - name: Install package dependencies
        uses: ./.github/actions/yarn
      - name: Build and test packages
        run: yarn build:ci:all
      - name: Bundle packages
        run: yarn bundle
      - name: Install package dependencies (docsite)
        uses: ./.github/actions/yarn
        with:
          working-directory: docsite
      - name: Build website
        run: yarn build
        working-directory: docsite
      - name: Create release PR or publish to npm
        uses: changesets/action@v1
        with:
          publish: yarn publish:changesets
          version: yarn version:changesets
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Deploy website
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docsite/build
          user_name: github-actions[bot]
          user_email: 41898282+github-actions[bot]@users.noreply.github.com
