soluble-io/cache-interop

View on GitHub
.github/workflows/release-or-pr-version.yml

Summary

Maintainability
Test Coverage
name: release-or-pr-version
on:
  push:
    branches:
      - main

# Seems required for now as setup/node might use it
env:
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
  release:
    name: Release and changelog
    if: ${{ github.repository == 'soluble-io/cache-interop' && contains('refs/heads/main',github.ref)}}
    permissions:
      contents: write #  to create release (changesets/action)
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
        with:
          # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
          fetch-depth: 0
          persist-credentials: true

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.x

      - name: 📥 Monorepo install
        uses: ./.github/actions/yarn-nm-install

      - name: Create Release Pull Request or Publish to npm
        id: changesets
        uses: changesets/action@v1
        with:
          publish: yarn g:release
          setupGitUser: true
        env:
          # See https://github.com/changesets/action/issues/147
          HOME: ${{ github.workspace }}
          # The regular GITHUB_TOKEN won't allow the created "Version Packages" pr to
          # trigger the regular CI workflow. This limitation can be circumvented by
          # setting a custom PAT token from a GH account and setting it the secrets.
          GITHUB_TOKEN: ${{ secrets.CACHE_INTEROP_RELEASE_BOT_GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}