11name : Release
22run-name : ${{ inputs.prerelease && 'Pre-Release' || 'Release' }} ${{ inputs.version }}
33
4- # A release is dispatched on main with a version and a commit on main. Nobody pushes the tag:
5- # once a member of clients other than the dispatcher approves the "release-approval"
6- # environment, the approve job creates it as the coder-release-publisher App, which is the only
7- # actor the tag ruleset lets create v* tags. Its key is in Cloud KMS, and only the approve job of
8- # main's copy of this file, in release-approval, may sign with it. See CONTRIBUTING.md.
4+ # Only the release App can create v* tags. Cloud KMS restricts its signing key to
5+ # this workflow on main in release-approval, which requires a second person's approval.
96
107on :
118 workflow_dispatch :
1512 required : true
1613 type : string
1714 commit :
18- description : " Full SHA of the commit on main to release"
15+ description : " Full SHA of the commit to release: on main, or on a release/* branch for a pre- release"
1916 required : true
2017 type : string
2118 prerelease :
2623
2724permissions : {}
2825
29- # Build releases from a clean install.
26+ # Build releases from a clean install. This also keeps the package job, which runs the released
27+ # commit's scripts in main's context, from reading or writing main's caches.
3028cache-mode : none
3129
30+ # One release at a time, from dispatch to publication, so versions are tagged and published in
31+ # order. A run waiting for approval holds the queue.
3232concurrency :
33- group : ${{ github.workflow }}-${{ inputs.version }}
34- cancel-in-progress : false
33+ group : ${{ github.workflow }}
34+ queue : max
3535
3636env :
3737 PRE_RELEASE_FLAG : ${{ inputs.prerelease && '--pre-release' || '' }}
3838
3939jobs :
40- # The jobs below run the scripts of the commit they build , so only a commit that went through
41- # review on main may be released .
40+ # The package job runs the approved commit's scripts and local actions , so the approver reviews
41+ # that exact commit, linked from this job's summary, not a branch tip .
4242 validate :
4343 name : Check the request
4444 runs-on : ubuntu-24.04
@@ -56,19 +56,23 @@ jobs:
5656 env :
5757 VERSION : ${{ inputs.version }}
5858 COMMIT : ${{ inputs.commit }}
59+ PRERELEASE : ${{ inputs.prerelease }}
5960 run : |
6061 set -euo pipefail
6162 fail() { echo "::error::$*"; exit 1; }
6263
6364 # Also stops a run started from a tag or from another branch.
6465 [[ "$GITHUB_REF" == "refs/heads/main" ]] || fail "This workflow only runs on main, not on $GITHUB_REF."
65- [[ "$VERSION" =~ ^v[ 0-9]+\.[ 0-9]+\.[ 0-9]+ $ ]] || fail "version must look like v1.2.3, got '$VERSION'."
66+ [[ "$VERSION" =~ ^v(0|[1-9][ 0-9]*)\.(0|[1-9][ 0-9]*)\.(0|[1-9][ 0-9]*) $ ]] || fail "version must look like v1.2.3, got '$VERSION'."
6667 [[ "$COMMIT" =~ ^[0-9a-f]{40}$ ]] || fail "commit must be a full 40-character SHA, got '$COMMIT'."
67- git merge-base --is-ancestor "$COMMIT" "$GITHUB_SHA" || fail "$COMMIT is not on main ."
68+ [[ "$( git cat-file -t "$COMMIT" 2>/dev/null)" == "commit" ]] || fail "$COMMIT is not a commit in $GITHUB_REPOSITORY ."
6869
6970 PACKAGE_VERSION="$(git show "$COMMIT:package.json" | jq -r .version)"
7071 [[ "${VERSION#v}" == "$PACKAGE_VERSION" ]] || fail "version $VERSION does not match package.json ($PACKAGE_VERSION) at $COMMIT."
7172
73+ url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
74+ echo "Approving releases [$COMMIT]($url/commit/$COMMIT) as $VERSION (prerelease=$PRERELEASE) ([changes from main]($url/compare/main...$COMMIT))." >> "$GITHUB_STEP_SUMMARY"
75+
7276 # A release is tagged only after a reviewer of the "release-approval" environment approves
7377 # this job, and it is built and published only once it is tagged.
7478 approve :
@@ -81,56 +85,64 @@ jobs:
8185 contents : read
8286 id-token : write # Cloud KMS signs the App's JWT
8387 steps :
84- # For the tags and the history of main. Nothing from the tree runs in this job.
88+ # For the branches, tags and history. Nothing from the tree runs in this job. Without tags,
89+ # the checks below would pass vacuously.
8590 - name : Checkout
8691 uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
8792 with :
8893 fetch-depth : 0
8994 fetch-tags : true
9095 persist-credentials : false
9196
92- # Here and not in the validate job, because the tags can change while the run waits for
93- # approval.
97+ # Here and not in the validate job, because branches and tags can change while the run
98+ # waits for approval.
9499 - name : Check the tag
95100 id : check
96101 env :
97102 VERSION : ${{ inputs.version }}
98103 COMMIT : ${{ inputs.commit }}
104+ PRERELEASE : ${{ inputs.prerelease }}
99105 run : |
100106 set -euo pipefail
101107 fail() { echo "::error::$*"; exit 1; }
102108
103- # Checked by the validate job too, and again in the job that may tag.
104- [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "version must look like v1.2.3, got '$VERSION'."
105- [[ "$COMMIT" =~ ^[0-9a-f]{40}$ ]] || fail "commit must be a full 40-character SHA, got '$COMMIT'."
106- git merge-base --is-ancestor "$COMMIT" "$GITHUB_SHA" || fail "$COMMIT is not on main."
107-
108- # A re-run finds the tag that the first attempt created.
109- if existing="$(git rev-parse --verify --quiet "refs/tags/$VERSION^{commit}")"; then
109+ message="Release $VERSION (prerelease=$PRERELEASE)"
110+ annotation="$(git tag --list "$VERSION" --format='%(objecttype) %(contents)')"
111+ if [[ -n "$annotation" ]]; then
112+ existing="$(git rev-parse "refs/tags/$VERSION^{commit}")"
110113 [[ "$existing" == "$COMMIT" ]] || fail "Tag $VERSION already exists at $existing, not at $COMMIT."
111- echo "Tag $VERSION already exists at $COMMIT."
112- echo "create=false" >> "$GITHUB_OUTPUT"
114+ [[ "$annotation" == "tag $message" ]] || fail "Tag $VERSION does not record the requested release channel (prerelease=$PRERELEASE)."
113115 exit 0
114116 fi
115117
118+ if [[ "$PRERELEASE" == "true" ]]; then
119+ # Rulesets let only maintainers and admins create release branches, and changing one takes
120+ # a reviewed pull request, as on main. Their * does not match /, so release/a/b is not a release branch.
121+ [[ -n "$(git branch --remotes --contains "$COMMIT" --format='%(refname:lstrip=3)' 2>/dev/null | grep -E -x 'main|release/[^/]+')" ]] || fail "$COMMIT is not on main or a release/* branch."
122+ else
123+ git merge-base --is-ancestor "$COMMIT" "$GITHUB_SHA" || fail "$COMMIT is not on main. Only a pre-release can come from a release/* branch."
124+ # Pre-releases from branches are squash-merged, so only the latest release on main must
125+ # be an ancestor.
126+ previous="$(git tag --merged "$GITHUB_SHA" --list 'v*' --sort=-version:refname | grep -E -m 1 '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)"
127+ [[ -z "$previous" ]] || git merge-base --is-ancestor "$previous" "$COMMIT" || fail "$COMMIT is older than $previous, the latest release on main."
128+ fi
129+
116130 # Each release needs a commit of its own.
117131 released="$(git tag --points-at "$COMMIT" --list 'v*' | paste -sd ' ' -)"
118132 [[ -z "$released" ]] || fail "$COMMIT was already released as $released. Release a newer commit."
119133
120- # Versions only go up, and a release never comes from before the last one.
121- tags="$(git tag --list 'v*' --sort=-version:refname)"
122- latest="$(grep -E -m 1 '^v[0-9]+\.[0-9]+\.[0-9]+$' <<<"$tags" || true)"
134+ # Checked before tagging, because the Marketplace only rejects an older version at publish.
135+ latest="$(git tag --list 'v*' --sort=-version:refname | grep -E -m 1 '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)"
123136 if [[ -n "$latest" ]]; then
124137 printf '%s\n' "$latest" "$VERSION" | sort -V -C || fail "$VERSION is not newer than $latest, the latest release."
125- git merge-base --is-ancestor "$latest" "$COMMIT" || fail "$COMMIT is older than the commit released as $latest."
126138 fi
127139
128- echo "create=true " >> "$GITHUB_OUTPUT"
140+ echo "message=$message " >> "$GITHUB_OUTPUT"
129141
130142 # The App can also write to other repositories, so the token is asked for this one only.
131143 - name : Generate release App token
132144 id : app_token
133- if : steps.check.outputs.create == 'true '
145+ if : steps.check.outputs.message != ' '
134146 uses : coder/github-app-token-action@00eaec58ee1bfea9c8b48655b7ab7470b07739e5 # main 2026-11-17
135147 with :
136148 client-id : ${{ secrets.CODER_RELEASE_PUBLISHER_APP_ID }}
@@ -144,15 +156,16 @@ jobs:
144156
145157 # An annotated tag, through the API: nothing is pushed from this job's checkout.
146158 - name : Create the tag
147- if : steps.check.outputs.create == 'true '
159+ if : steps.check.outputs.message != ' '
148160 env :
149161 GH_TOKEN : ${{ steps.app_token.outputs.token }}
162+ MESSAGE : ${{ steps.check.outputs.message }}
150163 VERSION : ${{ inputs.version }}
151164 COMMIT : ${{ inputs.commit }}
152165 run : |
153166 set -euo pipefail
154167 tag_object="$(gh api "repos/$GITHUB_REPOSITORY/git/tags" \
155- -f tag="$VERSION" -f message="Release $VERSION " -f object="$COMMIT" -f type=commit \
168+ -f tag="$VERSION" -f message="$MESSAGE " -f object="$COMMIT" -f type=commit \
156169 --jq .sha)"
157170 gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$VERSION" -f sha="$tag_object" >/dev/null
158171 echo "Created tag $VERSION at $COMMIT."
@@ -164,27 +177,21 @@ jobs:
164177 timeout-minutes : 15
165178 permissions :
166179 contents : read
167- outputs :
168- vsix : ${{ steps.package.outputs.vsix }}
169- vsce-version : ${{ steps.package.outputs.vsce-version }}
170180 steps :
171181 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
172182 with :
173- ref : ${{ inputs.commit }}
183+ ref : refs/tags/ ${{ inputs.version }}
174184 persist-credentials : false
175185
176- - name : Setup pnpm, Node.js, and dependencies
177- uses : ./.github/actions/pnpm-setup
178-
179- - name : Validate version matches package.json
186+ # The validate job checked package.json at this commit.
187+ - name : Check the tag is at the approved commit
180188 env :
181- VERSION : ${{ inputs.version }}
189+ COMMIT : ${{ inputs.commit }}
182190 run : |
183- PACKAGE_VERSION=$(node -p "require('./package.json').version")
184- if [ "${VERSION#v}" != "$PACKAGE_VERSION" ]; then
185- echo "Error: Version ($VERSION) does not match package.json version ($PACKAGE_VERSION)"
186- exit 1
187- fi
191+ [[ "$(git rev-parse HEAD)" == "$COMMIT" ]] || { echo "::error::The tag is not at $COMMIT."; exit 1; }
192+
193+ - name : Setup pnpm, Node.js, and dependencies
194+ uses : ./.github/actions/pnpm-setup
188195
189196 - name : Build extension
190197 run : pnpm build:production
@@ -197,18 +204,80 @@ jobs:
197204 VSIX="$(node -p "require('./package.json').name")-${VERSION#v}.vsix"
198205 pnpm vsce package --no-dependencies $PRE_RELEASE_FLAG --out "$VSIX"
199206 echo "vsix=$VSIX" >> "$GITHUB_OUTPUT"
200- echo "vsce-version=$(pnpm exec vsce --version)" >> "$GITHUB_OUTPUT"
201207
202208 - name : Upload VSIX
203209 uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
204210 with :
205- name : ${{ steps.package.outputs. vsix }}
211+ name : vsix
206212 path : ${{ steps.package.outputs.vsix }}
207213 if-no-files-found : error
208214
215+ # The package job ran the released commit's scripts, which can rewrite the manifest. This job
216+ # runs none of them, so the publish jobs take their file name and vsce version from it.
217+ verify :
218+ name : Verify the package
219+ needs : package
220+ runs-on : ubuntu-24.04
221+ timeout-minutes : 5
222+ permissions :
223+ contents : read
224+ outputs :
225+ vsix : ${{ steps.verify.outputs.vsix }}
226+ vsce-version : ${{ steps.verify.outputs.vsce-version }}
227+ steps :
228+ # main's manifest and lockfile.
229+ - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
230+ with :
231+ sparse-checkout : |
232+ package.json
233+ pnpm-lock.yaml
234+ sparse-checkout-cone-mode : false
235+ persist-credentials : false
236+
237+ - name : Download VSIX
238+ uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
239+ with :
240+ name : vsix
241+ path : ${{ runner.temp }}/vsix
242+
243+ - name : Check the VSIX manifest
244+ id : verify
245+ env :
246+ VERSION : ${{ inputs.version }}
247+ PRERELEASE : ${{ inputs.prerelease }}
248+ run : |
249+ set -euo pipefail
250+ fail() { echo "::error::$*"; exit 1; }
251+
252+ vsix="$(jq -r .name package.json)-${VERSION#v}.vsix"
253+ file="$RUNNER_TEMP/vsix/$vsix"
254+ # Otherwise unzip and a registry could read different copies of an entry.
255+ [[ -z "$(unzip -Z1 "$file" | sort -f | uniq -di)" ]] || fail "$vsix has duplicate entries."
256+
257+ expected="$(jq -c --arg version "${VERSION#v}" '{publisher, name, version: $version}' package.json)"
258+ actual="$(unzip -p "$file" extension/package.json | jq -c '{publisher, name, version}')"
259+ [[ "$actual" == "$expected" ]] || fail "$vsix declares $actual, not $expected."
260+
261+ # The registries take the identity and channel from extension.vsixmanifest, and
262+ # vsce publish --pre-release only checks that the PreRelease property exists.
263+ expected="$(jq -c --arg prerelease "$PRERELEASE" '. + {target: null, prerelease: ($prerelease == "true")}' <<<"$expected")"
264+ actual="$(unzip -p "$file" extension.vsixmanifest | yq -p xml -o json '.PackageManifest.Metadata' | jq -c '{
265+ publisher: .Identity."+@Publisher", name: .Identity."+@Id", version: .Identity."+@Version", target: .Identity."+@TargetPlatform",
266+ prerelease: ([[.Properties.Property] | flatten[] | select(."+@Id" == "Microsoft.VisualStudio.Code.PreRelease") | ."+@Value"] == ["true"])
267+ }')"
268+ [[ "$actual" == "$expected" ]] || fail "The vsixmanifest of $vsix declares $actual, not $expected."
269+
270+ # pnpm-lock.yaml starts with a document that locks pnpm itself.
271+ vsce="$(yq -r '.importers["."].devDependencies["@vscode/vsce"].version | select(. != null)' pnpm-lock.yaml)"
272+ vsce="${vsce%%(*}"
273+ [[ "$vsce" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "Unexpected vsce version '$vsce' in pnpm-lock.yaml."
274+
275+ echo "vsix=$vsix" >> "$GITHUB_OUTPUT"
276+ echo "vsce-version=$vsce" >> "$GITHUB_OUTPUT"
277+
209278 publish-vscode :
210279 name : Publish to VS Marketplace
211- needs : package
280+ needs : verify
212281 runs-on : ubuntu-24.04
213282 timeout-minutes : 10
214283 environment : publish
@@ -220,30 +289,24 @@ jobs:
220289 with :
221290 node-version : " 22"
222291
223- # Only accept a plain version: this value comes from a job that ran dependency code.
224292 - name : Install vsce
225293 env :
226- VSCE_VERSION : ${{ needs.package.outputs.vsce-version }}
227- run : |
228- if [[ ! "$VSCE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
229- echo "Error: unexpected vsce version '$VSCE_VERSION'"
230- exit 1
231- fi
232- npm install -g "@vscode/vsce@${VSCE_VERSION}"
294+ VSCE_VERSION : ${{ needs.verify.outputs.vsce-version }}
295+ run : npm install -g "@vscode/vsce@${VSCE_VERSION}"
233296
234297 - name : Download VSIX
235298 uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
236299 with :
237- name : ${{ needs.package.outputs. vsix }}
300+ name : vsix
238301
239302 - name : Publish to VS Marketplace
240303 env :
241- VSIX : ${{ needs.package .outputs.vsix }}
304+ VSIX : ${{ needs.verify .outputs.vsix }}
242305 run : vsce publish $PRE_RELEASE_FLAG --packagePath "$VSIX" --oidc
243306
244307 publish-ovsx :
245308 name : Publish to Open VSX
246- needs : package
309+ needs : verify
247310 runs-on : ubuntu-24.04
248311 timeout-minutes : 10
249312 environment : publish
@@ -261,16 +324,16 @@ jobs:
261324 - name : Download VSIX
262325 uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
263326 with :
264- name : ${{ needs.package.outputs. vsix }}
327+ name : vsix
265328
266329 - name : Publish to Open VSX
267330 env :
268- VSIX : ${{ needs.package .outputs.vsix }}
331+ VSIX : ${{ needs.verify .outputs.vsix }}
269332 run : ovsx publish "$VSIX" $PRE_RELEASE_FLAG --trusted-publishing
270333
271334 publish-github :
272335 name : Create GitHub ${{ inputs.prerelease && 'Pre-Release' || 'Release' }}
273- needs : package
336+ needs : verify
274337 runs-on : ubuntu-24.04
275338 timeout-minutes : 5
276339 permissions :
@@ -281,7 +344,7 @@ jobs:
281344 - name : Download VSIX
282345 uses : actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
283346 with :
284- name : ${{ needs.package.outputs. vsix }}
347+ name : vsix
285348
286349 # The tag already exists (the approve job created it), so this only creates the release.
287350 - name : Create draft release
@@ -290,6 +353,6 @@ jobs:
290353 tag_name : ${{ inputs.version }}
291354 prerelease : ${{ inputs.prerelease }}
292355 draft : true
293- files : ${{ needs.package .outputs.vsix }}
356+ files : ${{ needs.verify .outputs.vsix }}
294357 generate_release_notes : true
295358 fail_on_unmatched_files : true
0 commit comments