|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Two gates, both checked through the GitHub API by scripts/release-gate.js, which fails closed (red, pending, missing |
| 4 | +# or an API error all stop the job): |
| 5 | +# - publish-next: after CI completes on a `main` push, and only if that commit's CI is green. Changesets opens the |
| 6 | +# "version packages" PR while changesets are pending; once it is merged (and CI is green on the merge), it runs |
| 7 | +# `changeset publish --tag next` (npm publish --tag next). Nothing ever publishes to `latest` directly. |
| 8 | +# - promote (manual, from `main`): moves a published version from `next` to `latest`, only if its release commit |
| 9 | +# (tag v<version>) has a green `nightly` status from a successful scheduled.yml run (mark-nightly), and the version |
| 10 | +# is not lower than the current `latest`. Run the nightly on that commit first if needed: |
| 11 | +# Actions -> Nightly -> Run workflow -> "Use workflow from" tag v<version>. |
| 12 | +# Both publishing jobs run in the `npm` environment, which holds NPM_TOKEN (a granular, publish-only token). Setup and |
| 13 | +# caveats (the version PR gets no CI): CONTRIBUTING.md "Publishing to npm". |
| 14 | +# Real publishing is first verified after merge to `main` (R28); until then only the dry run below has run (from the |
| 15 | +# PR, Release run 45353782465). |
| 16 | +on: |
| 17 | + workflow_run: |
| 18 | + workflows: [CI] |
| 19 | + types: [completed] |
| 20 | + branches: [main] |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + promote: |
| 24 | + description: 'Version to move from `next` to `latest` (e.g. 0.3.0). Empty: nothing to promote.' |
| 25 | + type: string |
| 26 | + default: '' |
| 27 | + dry_run: |
| 28 | + description: 'Dry run: evaluate the gates, version and pack; publish and promote nothing' |
| 29 | + type: boolean |
| 30 | + default: false |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +# per event: a dry run or a promote never queues behind or replaces a pending publish-next |
| 36 | +concurrency: |
| 37 | + group: release-${{ github.event_name }} |
| 38 | + cancel-in-progress: false |
| 39 | + |
| 40 | +env: |
| 41 | + PACKAGE: react-native-open-telemetry |
| 42 | + # A commit whose CI is red (a v0-impl PR run): the dry run proves the CI gate refuses it, live against the API. |
| 43 | + KNOWN_RED_SHA: 78482b19a4537be8f05306744729b5a6db8b0d10 |
| 44 | + # A commit whose CI is green: the positive control, so the refusal above is not a gate that always fails. |
| 45 | + KNOWN_GREEN_SHA: d6d1af161ea6a6a1ee587aa858304f3aa6f2e5b3 |
| 46 | + |
| 47 | +jobs: |
| 48 | + dry-run: |
| 49 | + if: github.event_name == 'workflow_dispatch' && inputs.dry_run |
| 50 | + runs-on: ubuntu-latest |
| 51 | + timeout-minutes: 20 |
| 52 | + permissions: |
| 53 | + contents: read |
| 54 | + actions: read |
| 55 | + statuses: read |
| 56 | + env: |
| 57 | + GH_TOKEN: ${{ github.token }} |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v4 |
| 60 | + with: |
| 61 | + fetch-depth: 0 # all branches: changeset status compares against origin/main |
| 62 | + - uses: actions/setup-node@v4 |
| 63 | + with: |
| 64 | + node-version: '24' |
| 65 | + - uses: oven-sh/setup-bun@v2 |
| 66 | + with: |
| 67 | + bun-version: 1.2.19 |
| 68 | + - run: node scripts/release-gate.js --self-test |
| 69 | + - name: The CI gate refuses a red commit and passes a green one |
| 70 | + run: | |
| 71 | + if node scripts/release-gate.js ci "$KNOWN_RED_SHA"; then echo "::error::CI gate passed a red commit"; exit 1; fi |
| 72 | + node scripts/release-gate.js ci "$KNOWN_GREEN_SHA" |
| 73 | + - name: The promote gate refuses a commit without a green nightly |
| 74 | + run: | |
| 75 | + if node scripts/release-gate.js nightly "$KNOWN_RED_SHA"; then echo "::error::nightly gate passed"; exit 1; fi |
| 76 | + - run: bun install --frozen-lockfile |
| 77 | + - run: bun run prepare |
| 78 | + - run: bunx changeset status --verbose --since=origin/main |
| 79 | + - name: Version (what the version PR would contain) |
| 80 | + run: bun run version && git status --short && git diff -- package.json src/sdk/config.ts ios/RNOtel/RNOtel.swift |
| 81 | + # `changeset publish` has no dry-run flag, so the dry run packs exactly what it would publish, with its dist-tag |
| 82 | + - run: npm publish --dry-run --tag next --ignore-scripts |
| 83 | + |
| 84 | + publish-next: |
| 85 | + if: >- |
| 86 | + github.event_name == 'workflow_run' && github.event.workflow_run.event == 'push' && |
| 87 | + github.event.workflow_run.conclusion == 'success' |
| 88 | + runs-on: ubuntu-latest |
| 89 | + timeout-minutes: 30 |
| 90 | + environment: npm |
| 91 | + permissions: |
| 92 | + contents: write # the version PR branch and the v<version> tag |
| 93 | + pull-requests: write # the version PR |
| 94 | + actions: read # the CI gate |
| 95 | + id-token: write # npm provenance |
| 96 | + env: |
| 97 | + SHA: ${{ github.event.workflow_run.head_sha }} |
| 98 | + GH_TOKEN: ${{ github.token }} |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 103 | + fetch-depth: 0 |
| 104 | + - uses: actions/setup-node@v4 |
| 105 | + with: |
| 106 | + node-version: '24' |
| 107 | + # the event says success; re-check through the API so a re-run or a stale event cannot publish a red commit |
| 108 | + - run: node scripts/release-gate.js ci "$SHA" |
| 109 | + - uses: oven-sh/setup-bun@v2 |
| 110 | + with: |
| 111 | + bun-version: 1.2.19 |
| 112 | + - run: bun install --frozen-lockfile |
| 113 | + - uses: changesets/action@v1 |
| 114 | + with: |
| 115 | + version: bun run version |
| 116 | + publish: bun run release |
| 117 | + title: 'chore: version packages' |
| 118 | + commit: 'chore: version packages' |
| 119 | + createGithubReleases: false # `latest` is promote's call, not the publish's |
| 120 | + env: |
| 121 | + GITHUB_TOKEN: ${{ github.token }} |
| 122 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 123 | + NPM_CONFIG_PROVENANCE: 'true' |
| 124 | + |
| 125 | + promote: |
| 126 | + if: >- |
| 127 | + github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && |
| 128 | + inputs.promote != '' && !inputs.dry_run |
| 129 | + runs-on: ubuntu-latest |
| 130 | + timeout-minutes: 10 |
| 131 | + environment: npm |
| 132 | + permissions: |
| 133 | + contents: read |
| 134 | + statuses: read # the nightly gate: the status |
| 135 | + actions: read # the nightly gate: the scheduled.yml run it links |
| 136 | + env: |
| 137 | + VERSION: ${{ inputs.promote }} |
| 138 | + GH_TOKEN: ${{ github.token }} |
| 139 | + steps: |
| 140 | + - uses: actions/checkout@v4 |
| 141 | + with: |
| 142 | + fetch-depth: 0 |
| 143 | + - uses: actions/setup-node@v4 |
| 144 | + with: |
| 145 | + node-version: '24' |
| 146 | + registry-url: https://registry.npmjs.org |
| 147 | + - name: Resolve the release commit |
| 148 | + run: | |
| 149 | + # x.y.z only: a prerelease never becomes `latest`, and sort -V orders plain versions correctly |
| 150 | + [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::not a release version: $VERSION"; exit 1; } |
| 151 | + sha=$(git rev-list -n 1 "v$VERSION") # fails the step when the tag is missing |
| 152 | + echo "SHA=$sha" >> "$GITHUB_ENV" |
| 153 | + test "$(npm view "$PACKAGE@$VERSION" version)" = "$VERSION" |
| 154 | + latest=$(npm view "$PACKAGE" dist-tags.latest) |
| 155 | + if [ "$(printf '%s\n' "$latest" "$VERSION" | sort -V | tail -n 1)" != "$VERSION" ]; then |
| 156 | + echo "::error::$VERSION is lower than latest $latest"; exit 1 |
| 157 | + fi |
| 158 | + - run: node scripts/release-gate.js nightly "$SHA" |
| 159 | + - run: npm dist-tag add "$PACKAGE@$VERSION" latest |
| 160 | + env: |
| 161 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments