Merge pull request #470 from apollographql/main #173
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - "release-*" | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| release: | |
| name: Changesets Release | |
| # Prevents action from creating a PR on forks | |
| if: github.repository == 'apollographql/apollo-client' | |
| runs-on: ubuntu-latest | |
| # Permissions necessary for Changesets to push a new branch and open PRs | |
| # (for automated Version Packages PRs), and request the JWT for provenance. | |
| # More info: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| outputs: | |
| published: ${{ steps.changesets.outputs.published || steps.changesets-prerelease.outputs.published }} | |
| publishedPackages: ${{ steps.changesets.outputs.publishedPackages || steps.changesets-prerelease.outputs.publishedPackages }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| with: | |
| # Fetch entire git history so Changesets can generate changelogs | |
| # with the correct commits | |
| fetch-depth: 0 | |
| - name: Check for pre.json file existence | |
| id: check_files | |
| uses: andstor/[email protected] | |
| with: | |
| files: ".changeset/pre.json" | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24.x" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies (with cache) | |
| uses: bahmutov/npm-install@v1 | |
| - name: "[main] Create release PR or publish to npm + GitHub" | |
| id: changesets | |
| if: github.ref_name == 'main' && steps.check_files.outputs.files_exists == 'false' | |
| uses: changesets/action@v1 | |
| with: | |
| version: npm run changeset-version | |
| publish: npm run changeset-publish | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: "" | |
| - name: "[prerelease] Publish to npm + GitHub" | |
| id: changesets-prerelease | |
| # Only run publish if we're still in pre mode and the last commit was | |
| # via an automatically created Version Packages PR | |
| if: github.ref_name != 'main' && steps.check_files.outputs.files_exists == 'true' && startsWith(github.event.head_commit.message, 'Version Packages') | |
| uses: changesets/action@v1 | |
| with: | |
| version: echo "This step should never version" | |
| publish: npm run changeset-publish | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: "" | |
| slack-notification: | |
| name: Postrelease Slack Notification | |
| runs-on: ubuntu-latest | |
| needs: release | |
| if: needs.release.result == 'success' && needs.release.outputs.published == 'true' | |
| strategy: | |
| matrix: | |
| package: ${{ fromJSON(needs.release.outputs.publishedPackages) }} | |
| steps: | |
| - name: Send a Slack notification on publish | |
| id: slack | |
| uses: slackapi/[email protected] | |
| with: | |
| # Slack channel id, channel name, or user id to post message | |
| # See also: https://api.slack.com/methods/chat.postMessage#channels | |
| # You can pass in multiple channels to post to by providing | |
| # a comma-delimited list of channel IDs | |
| channel-id: "C01PS0CB41G" | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "A new version of `{{ matrix.package.name }}` was released :rocket:" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "fields": [ | |
| { | |
| "type": "mrkdwn", | |
| "text": "*Version:*\n`${{ matrix.package.version }}`" | |
| }, | |
| { | |
| "type": "mrkdwn", | |
| "text": "*Tag:*\n`${{ github.ref_name == 'main' && 'latest' || 'next' }}`" | |
| }, | |
| { | |
| "type": "mrkdwn", | |
| "text": "*GitHub release:*\n<https://github.com/apollographql/apollo-client/releases/tag/${{ matrix.package.name }}@${{ matrix.package.version }}|link>" | |
| }, | |
| { | |
| "type": "mrkdwn", | |
| "text": "*npm releases:*\n<https://www.npmjs.com/package/@apollo/client?activeTab=versions|link>" | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| env: | |
| SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
| tag-next: | |
| name: Postrelease Tag Next Release | |
| runs-on: ubuntu-latest | |
| needs: release | |
| if: github.ref_name != 'main' && needs.release.result == 'success' && needs.release.outputs.published == 'true' | |
| permissions: | |
| id-token: write | |
| strategy: | |
| matrix: | |
| package: ${{ fromJSON(needs.release.outputs.publishedPackages) }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24.x" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies with cache | |
| uses: bahmutov/npm-install@v1 | |
| - name: Tag release with next on npm | |
| run: | | |
| if NEXT=$(npm show ${{ matrix.package.name }}@next version) node -e 'process.exit(require("semver").gt("${{ matrix.package.version }}",process.env.NEXT)?0:1)'; then | |
| npm dist-tag add ${{ matrix.package.name }}@${{ matrix.package.version }} next; | |
| fi |