|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 16.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 == '16.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 | + dist_tag: ${{ steps.release_metadata.outputs.dist_tag }} |
| 17 | + prerelease: ${{ steps.release_metadata.outputs.prerelease }} |
| 18 | + tarball_name: ${{ steps.release_metadata.outputs.tarball_name }} |
| 19 | + concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref_name }} |
| 21 | + cancel-in-progress: true |
| 22 | + permissions: |
| 23 | + contents: read # for actions/checkout |
| 24 | + steps: |
| 25 | + - name: Checkout repo |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + # Keep checkout fast: we should only need to scroll back a few |
| 29 | + # commits for release notes. If the release commit is older than |
| 30 | + # this depth, release:metadata will emit empty release notes. |
| 31 | + fetch-depth: 10 |
| 32 | + persist-credentials: false |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + cache: npm |
| 38 | + node-version-file: '.node-version' |
| 39 | + |
| 40 | + - name: Install Dependencies |
| 41 | + run: npm ci --ignore-scripts |
| 42 | + |
| 43 | + - name: Read release metadata |
| 44 | + id: release_metadata |
| 45 | + run: | |
| 46 | + release_metadata_json="$(npm run --silent release:metadata)" |
| 47 | + jq -r ' |
| 48 | + "version=\(.version)", |
| 49 | + "tag=\(.tag)", |
| 50 | + "dist_tag=\(.distTag)", |
| 51 | + "prerelease=\(.prerelease)", |
| 52 | + "package_spec=\(.packageSpec)", |
| 53 | + "tarball_name=\(.tarballName)", |
| 54 | + "should_publish=\(.shouldPublish)" |
| 55 | + ' <<< "${release_metadata_json}" >> "${GITHUB_OUTPUT}" |
| 56 | + jq -r '.releaseNotes' <<< "${release_metadata_json}" > ./release-notes.md |
| 57 | +
|
| 58 | + - name: Log publish decision |
| 59 | + run: | |
| 60 | + if [ "${{ steps.release_metadata.outputs.should_publish }}" = "true" ]; then |
| 61 | + echo "${{ steps.release_metadata.outputs.package_spec }} is not published yet." |
| 62 | + else |
| 63 | + echo "${{ steps.release_metadata.outputs.package_spec }} is already published." |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Build NPM package |
| 67 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 68 | + run: npm run build:npm |
| 69 | + |
| 70 | + - name: Pack npmDist package |
| 71 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 72 | + run: npm pack ./npmDist --pack-destination . > /dev/null |
| 73 | + |
| 74 | + - name: Upload npm package tarball |
| 75 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: npmDist-tarball |
| 79 | + path: ./${{ steps.release_metadata.outputs.tarball_name }} |
| 80 | + |
| 81 | + - name: Upload release notes |
| 82 | + if: steps.release_metadata.outputs.should_publish == 'true' |
| 83 | + uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: release-notes |
| 86 | + path: ./release-notes.md |
| 87 | + |
| 88 | + publish-npm: |
| 89 | + name: Publish npm package |
| 90 | + needs: check-publish |
| 91 | + # Keep this guard on every job for defense-in-depth in case job dependencies are refactored. |
| 92 | + if: ${{ !github.event.repository.fork && github.repository == 'graphql/graphql-js' && github.ref_name == '16.x.x' && needs.check-publish.outputs.should_publish == 'true' && needs.check-publish.result == 'success' }} |
| 93 | + runs-on: ubuntu-latest |
| 94 | + environment: release |
| 95 | + permissions: |
| 96 | + contents: read # for actions/checkout |
| 97 | + id-token: write # for npm trusted publishing via OIDC |
| 98 | + steps: |
| 99 | + - name: Checkout repo |
| 100 | + uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + persist-credentials: false |
| 103 | + |
| 104 | + - name: Setup Node.js |
| 105 | + uses: actions/setup-node@v4 |
| 106 | + with: |
| 107 | + node-version-file: '.node-version' |
| 108 | + |
| 109 | + - name: Download npmDist package |
| 110 | + uses: actions/download-artifact@v4 |
| 111 | + with: |
| 112 | + name: npmDist-tarball |
| 113 | + path: ./artifacts |
| 114 | + |
| 115 | + - name: Publish npm package |
| 116 | + run: | |
| 117 | + if [ -n "${{ needs.check-publish.outputs.dist_tag }}" ]; then |
| 118 | + npm publish --provenance --tag "${{ needs.check-publish.outputs.dist_tag }}" "./artifacts/${{ needs.check-publish.outputs.tarball_name }}" |
| 119 | + else |
| 120 | + npm publish --provenance "./artifacts/${{ needs.check-publish.outputs.tarball_name }}" |
| 121 | + fi |
| 122 | +
|
| 123 | + create-release: |
| 124 | + name: Create release |
| 125 | + needs: check-publish |
| 126 | + # Keep this guard on every job for defense-in-depth in case job dependencies are refactored. |
| 127 | + if: ${{ !github.event.repository.fork && github.repository == 'graphql/graphql-js' && github.ref_name == '16.x.x' && needs.check-publish.outputs.should_publish == 'true' && needs.check-publish.result == 'success' }} |
| 128 | + runs-on: ubuntu-latest |
| 129 | + environment: release |
| 130 | + permissions: |
| 131 | + contents: write # for creating GitHub release |
| 132 | + steps: |
| 133 | + - name: Checkout repo |
| 134 | + uses: actions/checkout@v4 |
| 135 | + with: |
| 136 | + persist-credentials: false |
| 137 | + |
| 138 | + - name: Download release notes |
| 139 | + uses: actions/download-artifact@v4 |
| 140 | + with: |
| 141 | + name: release-notes |
| 142 | + path: ./artifacts |
| 143 | + |
| 144 | + - name: Create release |
| 145 | + env: |
| 146 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + run: | |
| 148 | + if gh release view "${{ needs.check-publish.outputs.tag }}" > /dev/null 2>&1; then |
| 149 | + echo "GitHub release ${{ needs.check-publish.outputs.tag }} already exists. Skipping release creation." |
| 150 | + exit 0 |
| 151 | + fi |
| 152 | +
|
| 153 | + release_notes_file="./artifacts/release-notes.md" |
| 154 | +
|
| 155 | + if [ "${{ needs.check-publish.outputs.prerelease }}" = "true" ]; then |
| 156 | + gh release create "${{ needs.check-publish.outputs.tag }}" \ |
| 157 | + --target "${GITHUB_SHA}" \ |
| 158 | + --title "${{ needs.check-publish.outputs.tag }}" \ |
| 159 | + --notes-file "${release_notes_file}" \ |
| 160 | + --prerelease |
| 161 | + else |
| 162 | + gh release create "${{ needs.check-publish.outputs.tag }}" \ |
| 163 | + --target "${GITHUB_SHA}" \ |
| 164 | + --title "${{ needs.check-publish.outputs.tag }}" \ |
| 165 | + --notes-file "${release_notes_file}" |
| 166 | + fi |
0 commit comments