|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + commit: |
| 9 | + description: |
| 10 | + "Optional 40-character version-bump commit SHA reachable from the |
| 11 | + selected ref" |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }} |
| 17 | + queue: max |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +permissions: {} |
| 21 | + |
| 22 | +env: |
| 23 | + NODE_VERSION: "24.22.1" |
| 24 | + |
| 25 | +jobs: |
| 26 | + plan: |
| 27 | + if: github.repository_owner == 'convex' |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 5 |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + outputs: |
| 33 | + sha: ${{ steps.select.outputs.sha }} |
| 34 | + name: ${{ steps.select.outputs.name }} |
| 35 | + version: ${{ steps.select.outputs.version }} |
| 36 | + channel: ${{ steps.select.outputs.channel }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + persist-credentials: false |
| 42 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 43 | + with: |
| 44 | + node-version: ${{ env.NODE_VERSION }} |
| 45 | + package-manager-cache: false |
| 46 | + - id: select |
| 47 | + name: Select the latest version-bump commit |
| 48 | + env: |
| 49 | + RELEASE_COMMIT: ${{ inputs.commit }} |
| 50 | + run: | |
| 51 | + if [[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]; then |
| 52 | + source="${RELEASE_COMMIT:-$GITHUB_SHA}" |
| 53 | + [[ "$source" =~ ^[0-9a-f]{40}$ ]] || { echo 'Expected a 40-character commit SHA' >&2; exit 1; } |
| 54 | + git merge-base --is-ancestor "$source" "$GITHUB_SHA" |
| 55 | + else |
| 56 | + before=$(jq -r .before "$GITHUB_EVENT_PATH") |
| 57 | + source='' |
| 58 | + candidates=$(git rev-list --first-parent "$before..$GITHUB_SHA" -- package.json) |
| 59 | + while read -r candidate && [[ -n "$candidate" ]]; do |
| 60 | + current=$(git show "$candidate:package.json" | jq -r .version) |
| 61 | + previous=$(git show "$candidate^1:package.json" | jq -r .version) |
| 62 | + if [[ "$current" != "$previous" ]]; then source="$candidate"; break; fi |
| 63 | + done <<< "$candidates" |
| 64 | + if [[ -z "$source" ]]; then echo 'No version bump'; exit 0; fi |
| 65 | + fi |
| 66 | + name=$(git show "$source:package.json" | jq -r .name) |
| 67 | + VERSION=$(git show "$source:package.json" | jq -r .version) |
| 68 | + PREVIOUS_VERSION=$(git show "$source^1:package.json" | jq -r .version) |
| 69 | + export VERSION PREVIOUS_VERSION |
| 70 | + node --input-type=module <<'NODE' |
| 71 | + import { execFileSync } from 'node:child_process'; |
| 72 | + import { appendFileSync } from 'node:fs'; |
| 73 | + import { createRequire } from 'node:module'; |
| 74 | + // Use the standard SemVer library bundled with the pinned npm. |
| 75 | + const npmRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim(); |
| 76 | + const semver = createRequire(`${npmRoot}/npm/package.json`)('semver'); |
| 77 | + const { VERSION: version, PREVIOUS_VERSION: previous, GITHUB_REF: ref } = process.env; |
| 78 | + if (semver.valid(version) !== version || !semver.gt(version, previous)) throw new Error('Selected commit must increase the package version'); |
| 79 | + const pre = semver.prerelease(version); |
| 80 | + const channel = pre ? String(pre[0]) : 'latest'; |
| 81 | + if (pre && (!/^[a-z][a-z0-9-]*$/.test(channel) || channel === 'latest' || semver.validRange(channel))) throw new Error('Invalid prerelease channel'); |
| 82 | + if (!pre && ref !== 'refs/heads/main') throw new Error('Stable releases require main'); |
| 83 | + appendFileSync(process.env.GITHUB_OUTPUT, `channel=${channel}\n`); |
| 84 | + NODE |
| 85 | + tag="v$VERSION" |
| 86 | + if git show-ref --verify --quiet "refs/tags/$tag"; then |
| 87 | + if [[ "$GITHUB_EVENT_NAME" != workflow_dispatch ]]; then |
| 88 | + echo "$tag was already staged; skipping automatic release" |
| 89 | + exit 0 |
| 90 | + fi |
| 91 | + [[ "$(git rev-parse "$tag^{commit}")" == "$source" ]] || { echo "$tag points elsewhere" >&2; exit 1; } |
| 92 | + fi |
| 93 | + { |
| 94 | + echo "sha=$source" |
| 95 | + echo "name=$name" |
| 96 | + echo "version=$VERSION" |
| 97 | + } >> "$GITHUB_OUTPUT" |
| 98 | +
|
| 99 | + build: |
| 100 | + needs: plan |
| 101 | + if: needs.plan.outputs.sha != '' |
| 102 | + runs-on: ubuntu-latest |
| 103 | + timeout-minutes: 30 |
| 104 | + permissions: |
| 105 | + contents: read |
| 106 | + outputs: |
| 107 | + artifact_id: ${{ steps.upload.outputs.artifact-id }} |
| 108 | + sha256: ${{ steps.digest.outputs.sha256 }} |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 111 | + with: |
| 112 | + ref: ${{ needs.plan.outputs.sha }} |
| 113 | + persist-credentials: false |
| 114 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 115 | + with: |
| 116 | + node-version: ${{ env.NODE_VERSION }} |
| 117 | + package-manager-cache: false |
| 118 | + - run: npm ci |
| 119 | + - name: Validate release notes |
| 120 | + run: | |
| 121 | + # Compare against this checkout while reading all notes, including prerelease state. |
| 122 | + git update-ref refs/heads/main HEAD |
| 123 | + npx changeset status --output "$RUNNER_TEMP/changesets.json" |
| 124 | + jq -e '.changesets | length == 0' "$RUNNER_TEMP/changesets.json" |
| 125 | + version=$(jq -r .version package.json) |
| 126 | + awk -v version="$version" '/^## / { active=($0 == "## " version); next } active && !/^#/ && /[[:alnum:]]/ { found=1 } END { exit !found }' CHANGELOG.md |
| 127 | + - run: npm run build |
| 128 | + - run: npm run check |
| 129 | + - name: Run E2E tests and verify generated code |
| 130 | + env: |
| 131 | + CONVEX_AGENT_MODE: anonymous |
| 132 | + CONVEX_DISABLE_TELEMETRY: "1" |
| 133 | + run: | |
| 134 | + npm run test:e2e |
| 135 | + git diff --exit-code -- src/component/_generated |
| 136 | + test -z "$(git ls-files --others --exclude-standard src/component/_generated)" |
| 137 | + - name: Pack the tested package |
| 138 | + run: | |
| 139 | + mkdir -p "$RUNNER_TEMP/npm-release" |
| 140 | + npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/npm-release" |
| 141 | + - id: digest |
| 142 | + run: |
| 143 | + echo "sha256=$(sha256sum "$RUNNER_TEMP"/npm-release/*.tgz | cut -d ' ' |
| 144 | + -f 1)" >> "$GITHUB_OUTPUT" |
| 145 | + - id: upload |
| 146 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 |
| 147 | + with: |
| 148 | + name: npm-release-${{ needs.plan.outputs.sha }} |
| 149 | + path: ${{ runner.temp }}/npm-release/*.tgz |
| 150 | + if-no-files-found: error |
| 151 | + |
| 152 | + stage: |
| 153 | + needs: [plan, build] |
| 154 | + runs-on: ubuntu-latest |
| 155 | + timeout-minutes: 10 |
| 156 | + permissions: |
| 157 | + contents: read |
| 158 | + id-token: write |
| 159 | + steps: |
| 160 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 161 | + with: |
| 162 | + node-version: ${{ env.NODE_VERSION }} |
| 163 | + package-manager-cache: false |
| 164 | + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 165 | + with: |
| 166 | + artifact-ids: ${{ needs.build.outputs.artifact_id }} |
| 167 | + path: ${{ runner.temp }}/npm-release |
| 168 | + merge-multiple: true |
| 169 | + - name: Stage the tested artifact |
| 170 | + env: |
| 171 | + SOURCE_SHA: ${{ needs.plan.outputs.sha }} |
| 172 | + PACKAGE_NAME: ${{ needs.plan.outputs.name }} |
| 173 | + VERSION: ${{ needs.plan.outputs.version }} |
| 174 | + CHANNEL: ${{ needs.plan.outputs.channel }} |
| 175 | + EXPECTED_SHA256: ${{ needs.build.outputs.sha256 }} |
| 176 | + run: | |
| 177 | + set -o pipefail |
| 178 | + set -- "$RUNNER_TEMP"/npm-release/*.tgz |
| 179 | + test "$#" -eq 1 |
| 180 | + TARBALL="$1" |
| 181 | + echo "$EXPECTED_SHA256 $TARBALL" | sha256sum -c - |
| 182 | + { |
| 183 | + echo "$PACKAGE_NAME@$VERSION — source $SOURCE_SHA — npm channel $CHANNEL" |
| 184 | + echo "Review on npm's Staged Packages page, then approve with 2FA or npm stage approve <stage-id>." |
| 185 | + } >> "$GITHUB_STEP_SUMMARY" |
| 186 | + # npm reads GITHUB_SHA for provenance; checkout alone does not change it. |
| 187 | + GITHUB_SHA="$SOURCE_SHA" npm stage publish "$TARBALL" \ |
| 188 | + --ignore-scripts --provenance --access public --tag "$CHANNEL" \ |
| 189 | + 2>&1 | tee "$RUNNER_TEMP/npm-stage.log" |
| 190 | + - name: Preserve staging output and stage ID |
| 191 | + if: always() |
| 192 | + run: | |
| 193 | + if test -f "$RUNNER_TEMP/npm-stage.log"; then |
| 194 | + cat "$RUNNER_TEMP/npm-stage.log" >> "$GITHUB_STEP_SUMMARY" |
| 195 | + fi |
| 196 | +
|
| 197 | + tag: |
| 198 | + needs: [plan, stage] |
| 199 | + runs-on: ubuntu-latest |
| 200 | + timeout-minutes: 5 |
| 201 | + permissions: |
| 202 | + contents: write |
| 203 | + steps: |
| 204 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 205 | + with: |
| 206 | + ref: ${{ needs.plan.outputs.sha }} |
| 207 | + fetch-depth: 0 |
| 208 | + persist-credentials: false |
| 209 | + - name: Tag the staged source |
| 210 | + env: |
| 211 | + GH_TOKEN: ${{ github.token }} |
| 212 | + SOURCE_SHA: ${{ needs.plan.outputs.sha }} |
| 213 | + VERSION: ${{ needs.plan.outputs.version }} |
| 214 | + run: | |
| 215 | + tag="v$VERSION" |
| 216 | + if git show-ref --verify --quiet "refs/tags/$tag"; then |
| 217 | + test "$(git rev-parse "$tag^{commit}")" = "$SOURCE_SHA" |
| 218 | + else |
| 219 | + git tag "$tag" "$SOURCE_SHA" |
| 220 | + gh auth setup-git |
| 221 | + git push origin "refs/tags/$tag" |
| 222 | + fi |
0 commit comments