|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 17.x.x |
| 6 | +permissions: {} |
| 7 | +jobs: |
| 8 | + check-publish: |
| 9 | + name: Check for publish need and prepare artifacts |
| 10 | + # Keep this guard on every job for defense-in-depth in case job dependencies are refactored. |
| 11 | + if: ${{ !github.event.repository.fork && github.repository == 'graphql/graphql-js' && github.ref_name == '17.x.x' }} |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + should_publish: ${{ steps.release_metadata.outputs.should_publish }} |
| 15 | + tag: ${{ steps.release_metadata.outputs.tag }} |
| 16 | + tarball_name: ${{ steps.release_metadata.outputs.tarball_name }} |
| 17 | + concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref_name }} |
| 19 | + cancel-in-progress: true |
| 20 | + permissions: |
| 21 | + contents: read # for actions/checkout |
| 22 | + steps: |
| 23 | + - name: Checkout repo |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + persist-credentials: false |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + cache: npm |
| 32 | + node-version-file: '.node-version' |
| 33 | + |
| 34 | + - name: Install Dependencies |
| 35 | + run: npm ci --ignore-scripts |
| 36 | + |
| 37 | + - name: Read release metadata |
| 38 | + id: release_metadata |
| 39 | + run: | |
| 40 | + npm run --silent release:metadata >> "${GITHUB_OUTPUT}" |
| 41 | +
|
| 42 | + - name: Log publish decision |
| 43 | + run: | |
| 44 | + if [ "${{ steps.release_metadata.outputs.should_publish }}" = "true" ]; then |
| 45 | + echo "${{ steps.release_metadata.outputs.package_spec }} is not published yet." |
| 46 | + else |
| 47 | + echo "${{ steps.release_metadata.outputs.package_spec }} is already published." |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Build NPM package |
| 51 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 52 | + run: npm run build:npm |
| 53 | + |
| 54 | + - name: Pack npmDist package |
| 55 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 56 | + run: npm pack ./npmDist --pack-destination . > /dev/null |
| 57 | + |
| 58 | + - name: Upload npm package tarball |
| 59 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: npmDist-tarball |
| 63 | + path: ./${{ steps.release_metadata.outputs.tarball_name }} |
| 64 | + |
| 65 | + publish-release: |
| 66 | + name: Publish, tag, and create release |
| 67 | + needs: check-publish |
| 68 | + # Keep this guard on every job for defense-in-depth in case job dependencies are refactored. |
| 69 | + if: ${{ !github.event.repository.fork && github.repository == 'graphql/graphql-js' && github.ref_name == '17.x.x' && needs.check-publish.outputs.should_publish == 'true' && needs.check-publish.result == 'success' }} |
| 70 | + runs-on: ubuntu-latest |
| 71 | + environment: release |
| 72 | + permissions: |
| 73 | + contents: write # for creating/pushing tag and creating GitHub release |
| 74 | + id-token: write # for npm trusted publishing via OIDC |
| 75 | + steps: |
| 76 | + - name: Checkout repo |
| 77 | + uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + persist-credentials: false |
| 80 | + |
| 81 | + - name: Setup Node.js |
| 82 | + uses: actions/setup-node@v4 |
| 83 | + with: |
| 84 | + node-version-file: '.node-version' |
| 85 | + |
| 86 | + - name: Download npmDist package |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + name: npmDist-tarball |
| 90 | + path: ./artifacts |
| 91 | + |
| 92 | + - name: Verify package tarball is present |
| 93 | + run: | |
| 94 | + tarball="./artifacts/${{ needs.check-publish.outputs.tarball_name }}" |
| 95 | + if [ ! -f "${tarball}" ]; then |
| 96 | + echo "::error::Expected package tarball ${tarball} is missing." |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Create release if needed |
| 101 | + env: |
| 102 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + run: | |
| 104 | + release_notes_file="./artifacts/release-notes.md" |
| 105 | + gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}" --jq '.commit.message' > "${release_notes_file}" |
| 106 | + if [ ! -s "${release_notes_file}" ]; then |
| 107 | + printf '## Release %s\n' "${{ needs.check-publish.outputs.tag }}" > "${release_notes_file}" |
| 108 | + fi |
| 109 | +
|
| 110 | + if gh release view "${{ needs.check-publish.outputs.tag }}" > /dev/null 2>&1; then |
| 111 | + echo "GitHub release ${{ needs.check-publish.outputs.tag }} already exists." |
| 112 | + else |
| 113 | + gh release create "${{ needs.check-publish.outputs.tag }}" \ |
| 114 | + --target "${GITHUB_SHA}" \ |
| 115 | + --title "${{ needs.check-publish.outputs.tag }}" \ |
| 116 | + --notes-file "${release_notes_file}" |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Dry-run npm publish |
| 120 | + run: npm publish --provenance --dry-run "./artifacts/${{ needs.check-publish.outputs.tarball_name }}" |
0 commit comments