Skip to content

ci: publish after CI passes instead of running release-please - #266

Open
sydneycollins-cio wants to merge 1 commit into
mainfrom
ci/publish-after-ci
Open

sydneycollins-cio wants to merge 1 commit into
mainfrom
ci/publish-after-ci

Conversation

@sydneycollins-cio

Copy link
Copy Markdown
Contributor

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

@youngnicks-cio youngnicks-cio left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 28 to +31
- 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- 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

Comment on lines +20 to +22
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +73 to +75
if [[ -n "$(npm view "customerio-node@$VERSION" version 2>/dev/null)" ]]; then
echo "customerio-node@$VERSION is already on npm."
exit 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants