|
39 | 39 | - uses: actions/checkout@v7 |
40 | 40 | with: |
41 | 41 | 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 |
42 | 45 |
|
43 | 46 | - uses: ./.github/actions/setup |
44 | 47 | with: |
@@ -113,26 +116,48 @@ jobs: |
113 | 116 | npm publish .release/*.tgz --provenance --access public |
114 | 117 | fi |
115 | 118 |
|
116 | | - - name: Push the version commit and tag |
| 119 | + - name: Tag the release and push the version commit |
117 | 120 | env: |
| 121 | + GH_TOKEN: ${{ github.token }} |
118 | 122 | VERSION: ${{ steps.version.outputs.version }} |
119 | 123 | run: | |
120 | 124 | git config user.name 'github-actions[bot]' |
121 | 125 | 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" |
122 | 127 | tag="devtools@$VERSION" |
123 | 128 | if ! git diff --quiet -- packages/devtools/package.json; then |
124 | 129 | git commit -m "chore(release): $VERSION" -- packages/devtools/package.json |
125 | 130 | 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 |
136 | 161 |
|
137 | 162 | - name: GitHub release |
138 | 163 | env: |
|
0 commit comments