|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + type: |
| 5 | + description: 'The type of release to publish' |
| 6 | + required: true |
| 7 | + type: string |
| 8 | + npmTag: |
| 9 | + description: 'The npm distribution tag for snapshot releases' |
| 10 | + default: alpha |
| 11 | + type: string |
| 12 | + restoreDeletedChangesets: |
| 13 | + description: 'Whether deleted changesets should be restored before publishing a snapshot' |
| 14 | + default: false |
| 15 | + type: boolean |
| 16 | + outputs: |
| 17 | + published: |
| 18 | + description: 'Whether any packages were published' |
| 19 | + value: ${{ jobs.snapshot.outputs.published || jobs.stable.outputs.published }} |
| 20 | + publishedPackages: |
| 21 | + description: 'The published packages as JSON' |
| 22 | + value: |
| 23 | + ${{ jobs.snapshot.outputs.publishedPackages || jobs.stable.outputs.publishedPackages }} |
| 24 | + hivePublish: |
| 25 | + description: 'Whether the Hive package was published' |
| 26 | + value: ${{ jobs.stable.outputs.hivePublish }} |
| 27 | + hiveVersion: |
| 28 | + description: 'The published Hive package version' |
| 29 | + value: ${{ jobs.stable.outputs.hiveVersion }} |
| 30 | + cliPublish: |
| 31 | + description: 'Whether the CLI package was published' |
| 32 | + value: ${{ jobs.stable.outputs.cliPublish }} |
| 33 | + cliVersion: |
| 34 | + description: 'The published CLI package version' |
| 35 | + value: ${{ jobs.stable.outputs.cliVersion }} |
| 36 | + secrets: |
| 37 | + githubToken: |
| 38 | + required: true |
| 39 | + npmToken: |
| 40 | + required: true |
| 41 | + hiveToken: |
| 42 | + required: false |
| 43 | + r2AccessKeyId: |
| 44 | + required: false |
| 45 | + r2SecretAccessKey: |
| 46 | + required: false |
| 47 | + |
| 48 | +permissions: |
| 49 | + id-token: write |
| 50 | + pull-requests: write |
| 51 | + contents: write |
| 52 | + |
| 53 | +jobs: |
| 54 | + snapshot: |
| 55 | + if: |
| 56 | + inputs.type == 'snapshot' && github.event.pull_request.head.repo.full_name == |
| 57 | + github.repository |
| 58 | + runs-on: ubuntu-latest |
| 59 | + outputs: |
| 60 | + published: ${{ steps.changesets.outputs.published }} |
| 61 | + publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} |
| 62 | + steps: |
| 63 | + - name: checkout |
| 64 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 65 | + with: |
| 66 | + fetch-depth: 0 |
| 67 | + ref: ${{ github.event.pull_request.head.sha }} |
| 68 | + |
| 69 | + - name: setup environment |
| 70 | + id: env |
| 71 | + uses: the-guild-org/shared-config/setup@v1 |
| 72 | + with: |
| 73 | + node-version-file: '.node-version' |
| 74 | + |
| 75 | + - name: restore deleted changesets |
| 76 | + if: inputs.restoreDeletedChangesets |
| 77 | + run: git checkout HEAD~1 -- . |
| 78 | + |
| 79 | + - name: ${{ inputs.npmTag }} release |
| 80 | + id: changesets |
| 81 | + uses: the-guild-org/changesets-snapshot-action@232ff9af22cfd043528fe2e4c403afd090ba3ed3 # v0.0.4 |
| 82 | + with: |
| 83 | + tag: ${{ inputs.npmTag }} |
| 84 | + prepareScript: ${{ format('{0} run build:libraries', steps.env.outputs.package-manager) }} |
| 85 | + env: |
| 86 | + NPM_TOKEN: ${{ secrets.npmToken }} |
| 87 | + GITHUB_TOKEN: ${{ secrets.githubToken }} |
| 88 | + NPM_CONFIG_PROVENANCE: true |
| 89 | + PNPM_CONFIG_PROVENANCE: true |
| 90 | + |
| 91 | + stable: |
| 92 | + if: inputs.type == 'stable' |
| 93 | + runs-on: ubuntu-22.04 |
| 94 | + env: |
| 95 | + HIVE_TOKEN: ${{ secrets.hiveToken }} |
| 96 | + # AWS_* are used by Oclif CLI |
| 97 | + AWS_ACCESS_KEY_ID: ${{ secrets.r2AccessKeyId }} |
| 98 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.r2SecretAccessKey }} |
| 99 | + AWS_S3_ENDPOINT: https://6d5bc18cd8d13babe7ed321adba3d8ae.r2.cloudflarestorage.com |
| 100 | + |
| 101 | + outputs: |
| 102 | + published: ${{ steps.changesets.outputs.published }} |
| 103 | + publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} |
| 104 | + cliPublish: ${{ steps.cli.outputs.publish }} |
| 105 | + cliVersion: ${{ steps.cli.outputs.version }} |
| 106 | + hivePublish: ${{ steps.hive.outputs.publish }} |
| 107 | + hiveVersion: ${{ steps.hive.outputs.version }} |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: checkout |
| 111 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 112 | + with: |
| 113 | + fetch-depth: 2 |
| 114 | + token: ${{ secrets.githubToken }} |
| 115 | + |
| 116 | + - name: setup environment |
| 117 | + uses: ./.github/actions/setup |
| 118 | + with: |
| 119 | + codegen: false # no need to run because release script will run it anyway |
| 120 | + actor: release-stable |
| 121 | + |
| 122 | + - name: prepare npm credentials |
| 123 | + run: | |
| 124 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> $HOME/.npmrc |
| 125 | + env: |
| 126 | + NPM_TOKEN: ${{ secrets.npmToken }} |
| 127 | + |
| 128 | + - uses: dtolnay/rust-toolchain@stable |
| 129 | + with: |
| 130 | + toolchain: stable |
| 131 | + |
| 132 | + # see https://github.com/changesets/action/issues/523 |
| 133 | + - name: fix gh-api issues with changesets |
| 134 | + run: | |
| 135 | + git ls-files | while read -r file; do [ -x "$file" ] && chmod -x "$file" || true; done |
| 136 | +
|
| 137 | + - name: publish stable |
| 138 | + id: changesets |
| 139 | + uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3 |
| 140 | + with: |
| 141 | + publish: pnpm release |
| 142 | + version: pnpm release:version |
| 143 | + commit: 'chore(release): update monorepo packages versions' |
| 144 | + title: 'Upcoming Release Changes' |
| 145 | + commitMode: github-api |
| 146 | + env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.githubToken }} |
| 148 | + NPM_CONFIG_PROVENANCE: true |
| 149 | + PNPM_CONFIG_PROVENANCE: true |
| 150 | + |
| 151 | + - name: extract published cli version |
| 152 | + if: |
| 153 | + steps.changesets.outputs.published && contains(steps.changesets.outputs.publishedPackages, |
| 154 | + '"@graphql-hive/cli"') |
| 155 | + id: cli |
| 156 | + run: | |
| 157 | + echo '${{steps.changesets.outputs.publishedPackages}}' > cli-ver.json |
| 158 | + VERSION=`echo $(jq -r '.[] | select(.name | endswith("@graphql-hive/cli")).version' cli-ver.json)` |
| 159 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 160 | + echo "publish=true" >> $GITHUB_OUTPUT |
| 161 | +
|
| 162 | + - name: extract published hive version |
| 163 | + if: |
| 164 | + steps.changesets.outputs.published && contains(steps.changesets.outputs.publishedPackages, |
| 165 | + '"hive"') |
| 166 | + id: hive |
| 167 | + run: | |
| 168 | + echo '${{steps.changesets.outputs.publishedPackages}}' > hive-ver.json |
| 169 | + VERSION=`echo $(jq -r '.[] | select(.name | endswith("hive")).version' hive-ver.json)` |
| 170 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 171 | + echo "publish=true" >> $GITHUB_OUTPUT |
| 172 | +
|
| 173 | + # Needed for `oclif pack win` |
| 174 | + - name: Install NSIS |
| 175 | + run: | |
| 176 | + sudo apt-get -y install nsis |
| 177 | +
|
| 178 | + - name: pack tarballs |
| 179 | + if: steps.cli.outputs.publish == 'true' |
| 180 | + working-directory: packages/libraries/cli |
| 181 | + run: pnpm oclif:pack |
| 182 | + |
| 183 | + - name: upload tarballs |
| 184 | + if: steps.cli.outputs.publish == 'true' |
| 185 | + working-directory: packages/libraries/cli |
| 186 | + run: pnpm oclif:upload |
| 187 | + |
| 188 | + - name: promote tarballs |
| 189 | + if: steps.cli.outputs.publish == 'true' |
| 190 | + working-directory: packages/libraries/cli |
| 191 | + env: |
| 192 | + VERSION: ${{ steps.cli.outputs.version }} |
| 193 | + run: pnpm oclif promote --no-xz --sha ${GITHUB_SHA:0:7} --version $VERSION |
0 commit comments