Repository navigation
ci: publish after CI passes instead of running release-please - #266
sydneycollins-cio wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
youngnicks-cio
left a comment
There was a problem hiding this comment.
Requesting a few CI hardening edits before this merges. The job now holds a contents: write token and id-token: write while it runs dependency install scripts, and a manual dispatch can publish an unreviewed ref. Details inline.
| - uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ needs.release-please.outputs.sha || github.sha }} | ||
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | ||
| fetch-depth: 0 |
There was a problem hiding this comment.
Please add persist-credentials: false here. With contents: write, checkout leaves a write token in .git/config, and the npm ci / build / test steps below run in this checkout, so any dependency install script could read it and push commits or tags. Nothing later needs it: the version checks only read local refs, and the release step uses GH_TOKEN.
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ needs.release-please.outputs.sha || github.sha }} | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| fetch-depth: 0 | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| fetch-depth: 0 | |
| persist-credentials: false |
| if: >- | ||
| github.event_name == 'workflow_dispatch' || | ||
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') |
There was a problem hiding this comment.
workflow_dispatch runs on whatever ref is picked in the dispatch form, so a manual run can publish and tag a branch that never went through review or CI. Please limit dispatch to main:
| if: >- | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') | |
| if: >- | |
| (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') || | |
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') |
| env: | ||
| CI_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| run: | | ||
| if [[ -n "$CI_SHA" && "$(git rev-parse origin/main)" != "$CI_SHA" ]]; then |
There was a problem hiding this comment.
On dispatch CI_SHA is empty, so this check is skipped. Could it fall back to the checked-out commit so dispatch also has to match origin/main? For example want="${CI_SHA:-$(git rev-parse HEAD)}" and compare origin/main against $want.
| echo "customerio-node@$VERSION is already on npm." | ||
| exit 0 | ||
| fi | ||
| npm ci |
There was a problem hiding this comment.
This job also has id-token: write, so any install script that runs here can request an OIDC token and publish to npm through trusted publishing. Please either use npm ci --ignore-scripts here, or split it into a build/test job (read-only, no id-token) that uploads the npm pack tarball and a publish job that only downloads and publishes it. The split is the stronger option, and since this PR already rewrites the job it's a good place for it.
| if [[ -n "$(npm view "customerio-node@$VERSION" version 2>/dev/null)" ]]; then | ||
| echo "customerio-node@$VERSION is already on npm." | ||
| exit 0 |
There was a problem hiding this comment.
Agree with Nick's feedback. Could we also verify that an existing npm version was published from this commit before creating the tag? If npm publishes commit A but release creation fails, the next successful main run at commit B with the same version skips publishing here and then tags B. That leaves the GitHub release pointing at different code from the npm package. Failing on a commit mismatch would prevent the retry from silently creating the wrong tag.
Release PRs now happen in the private repo. Once CI passes on main, this publishes the package.json version to npm if it's new, then tags it and creates the GitHub release.
🤖 Generated with Claude Code