Skip to content

Commit 90f16f3

Browse files
committed
build(release): keep the token out of the verify step and tag the published commit
Checkout no longer leaves the token in .git/config while verify:publish installs packages; the tag step sets it itself. The tag now marks the commit that was packed and published, before any rebase onto main, and an existing tag is never moved.
1 parent 33d5ee0 commit 90f16f3

2 files changed

Lines changed: 46 additions & 21 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- uses: actions/checkout@v7
4040
with:
4141
fetch-depth: 0
42+
# The verify step installs packages whose scripts run here, so no token is left in
43+
# .git/config. The push step authenticates on its own.
44+
persist-credentials: false
4245

4346
- uses: ./.github/actions/setup
4447
with:
@@ -113,26 +116,48 @@ jobs:
113116
npm publish .release/*.tgz --provenance --access public
114117
fi
115118
116-
- name: Push the version commit and tag
119+
- name: Tag the release and push the version commit
117120
env:
121+
GH_TOKEN: ${{ github.token }}
118122
VERSION: ${{ steps.version.outputs.version }}
119123
run: |
120124
git config user.name 'github-actions[bot]'
121125
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
126+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
122127
tag="devtools@$VERSION"
123128
if ! git diff --quiet -- packages/devtools/package.json; then
124129
git commit -m "chore(release): $VERSION" -- packages/devtools/package.json
125130
fi
126-
# Pull requests can merge while a release runs. Replay the version commit on top of them
127-
# and tag where it lands. A rebase conflict fails the step rather than guessing.
128-
for attempt in 1 2 3; do
129-
git fetch origin main
130-
git rebase origin/main
131-
git tag -f -a "$tag" -m "$tag"
132-
if git push origin HEAD:main; then break; fi
133-
if [ "$attempt" = 3 ]; then exit 1; fi
134-
done
135-
git push -f origin "refs/tags/$tag"
131+
# The tag marks the exact source that was packed and published: this commit, before any
132+
# rebase onto pull requests that merged while the release ran.
133+
released=$(git rev-parse HEAD)
134+
existing=$(git ls-remote origin "refs/tags/$tag^{}" | cut -f1)
135+
if [ -z "$existing" ]; then
136+
existing=$(git ls-remote origin "refs/tags/$tag" | cut -f1)
137+
fi
138+
if [ -z "$existing" ]; then
139+
git tag -a "$tag" -m "$tag" "$released"
140+
git push origin "refs/tags/$tag"
141+
elif [ "$existing" = "$released" ]; then
142+
echo "$tag already points at $released"
143+
else
144+
# A tag is never moved: a rerun after a partial release leaves the first one alone.
145+
echo "::warning::$tag already exists at $existing, not at $released. It is left as it is."
146+
fi
147+
# Main gets the version commit, replayed on top of anything that merged meanwhile. When
148+
# the version was already set on main, there is nothing to push. A rebase conflict fails
149+
# the step rather than guessing.
150+
if [ "$released" != "$GITHUB_SHA" ]; then
151+
for attempt in 1 2 3; do
152+
git fetch origin main
153+
if ! git rebase origin/main; then
154+
git rebase --abort
155+
exit 1
156+
fi
157+
if git push origin HEAD:main; then break; fi
158+
if [ "$attempt" = 3 ]; then exit 1; fi
159+
done
160+
fi
136161
137162
- name: GitHub release
138163
env:

‎apps/docs/src/content/contributing/publishing.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ The **Release** workflow (`.github/workflows/release.yml`) publishes the package
7676
2. If `app/` changed since the last release, check that `extension/ui` is current. CI fails when it is stale.
7777
3. Once the pull request is merged and CI is green on `main`, run **Release** from the Actions tab on `main`. Its input is an exact version (`1.0.1`), or `patch`, or `minor`.
7878

79-
| Step | What happens |
80-
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
81-
| CI | Runs `ci.yml` on the commit being released, every job included. |
82-
| Version | Sets `version` in `packages/devtools/package.json`. |
83-
| Check the changelog | Fails unless `CHANGELOG.md` has a `## <version>` section. That section becomes the release notes. |
84-
| Build | `pnpm pack` builds the library and the UI into one tarball, with `publishConfig.exports` applied. |
85-
| Verify the tarball | `pnpm verify:publish` installs that tarball into a fresh Angular CLI app from a throwaway local registry, builds it, and checks that the hub answers. |
86-
| Publish | `npm publish --provenance` publishes the tarball on the `latest` tag. |
87-
| Push and tag | Commits `chore(release): <version>` to `main` when the version changed, and tags it `devtools@<version>`. |
88-
| GitHub release | Creates a release for the tag, with the changelog section as its notes. |
79+
| Step | What happens |
80+
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
81+
| CI | Runs `ci.yml` on the commit being released, every job included. |
82+
| Version | Sets `version` in `packages/devtools/package.json`. |
83+
| Check the changelog | Fails unless `CHANGELOG.md` has a `## <version>` section. That section becomes the release notes. |
84+
| Build | `pnpm pack` builds the library and the UI into one tarball, with `publishConfig.exports` applied. |
85+
| Verify the tarball | `pnpm verify:publish` installs that tarball into a fresh Angular CLI app from a throwaway local registry, builds it, and checks that the hub answers. |
86+
| Publish | `npm publish --provenance` publishes the tarball on the `latest` tag. |
87+
| Tag and push | Tags the commit that was published `devtools@<version>`, and never moves an existing tag. When the version changed, commits `chore(release): <version>` and pushes it to `main`. |
88+
| GitHub release | Creates a release for the tag, with the changelog section as its notes. |
8989

9090
If the workflow fails before it publishes, nothing has left the runner. Fix the cause and run it again. If it fails after it publishes, run it again with the same exact version, not a bump: it skips the publish when that version is already on npm and finishes the rest.
9191

0 commit comments

Comments
 (0)