ci: add canary and publish workflows, refactor review workflow #8
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: canary | |
| permissions: | |
| id-token: write | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| publish: | |
| if: github.repository_owner == 'prismicio' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: "https://registry.npmjs.org" | |
| - run: npm ci | |
| - id: version | |
| run: | | |
| SHORT_SHA=$(git rev-parse --short HEAD) | |
| CURRENT_VERSION=$(jq -r '.version' package.json) | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| PR_NUMBER=${{ github.event.number }} | |
| VERSION="${CURRENT_VERSION}-pr.${PR_NUMBER}.${SHORT_SHA}" | |
| TAG="pr-${PR_NUMBER}" | |
| else | |
| VERSION="${CURRENT_VERSION}-canary.${SHORT_SHA}" | |
| TAG="canary" | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | |
| - run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version | |
| - run: npm publish --provenance --tag ${{ steps.version.outputs.tag }} | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - if: github.event_name == 'push' | |
| run: | | |
| CURRENT_TAG=${{ steps.version.outputs.tag }} | |
| PACKAGE_NAME=$(jq -r ".name" package.json) | |
| PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$CURRENT_TAG" 2>/dev/null || echo "") | |
| if [ -n "$PREVIOUS_VERSION" ] && [ "$PREVIOUS_VERSION" != "${{ steps.version.outputs.version }}" ]; then | |
| npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Superseded by newer canary version ${{ steps.version.outputs.version }}" | |
| else | |
| echo "No previous canary to deprecate" | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |