@@ -33,16 +33,39 @@ jobs:
3333 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3434 with :
3535 ref : ${{ github.sha }}
36+ # The parent commit too, to read the version this push replaced.
37+ fetch-depth : 2
3638
3739 - id : v
3840 env :
3941 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42+ EVENT_NAME : ${{ github.event_name }}
4043 run : |
44+ set -euo pipefail
4145 VERSION=$(node -p "require('./vscode-extension/package.json').version")
4246 if [[ "$VERSION" == *-* || "$VERSION" == *+* ]]; then
4347 echo "::error::vscode-extension version $VERSION is not strict SemVer MAJOR.MINOR.PATCH."
4448 exit 1
4549 fi
50+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
51+
52+ # A release is a version change, and nothing else. This workflow wakes
53+ # on any edit to the manifest, which also carries the icon, the
54+ # commands and the settings schema — so an unrelated edit would
55+ # otherwise ship whatever version happened to be sitting there.
56+ # Publishing a version the manifest already held is `workflow_dispatch`,
57+ # chosen deliberately.
58+ if [ "$EVENT_NAME" = "push" ]; then
59+ BEFORE=$(git show "${GITHUB_SHA}^:vscode-extension/package.json" 2>/dev/null \
60+ | node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).version" 2>/dev/null || echo "")
61+ if [ "$BEFORE" = "$VERSION" ]; then
62+ echo "::notice::vscode-extension stays at $VERSION — the manifest changed, the version did not. Nothing to release."
63+ echo "publish=false" >> "$GITHUB_OUTPUT"
64+ echo "release=false" >> "$GITHUB_OUTPUT"
65+ exit 0
66+ fi
67+ fi
68+
4669 MKT=$(curl -s -X POST https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery \
4770 -H "Content-Type: application/json" -H "Accept: application/json;api-version=7.2-preview.1" \
4871 -d '{"filters":[{"criteria":[{"filterType":7,"value":"tumaet.apollon-vscode"}]}],"flags":914}' \
5881 else
5982 echo "release=true" >> "$GITHUB_OUTPUT"
6083 fi
61- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
6284
6385 build :
6486 name : Build VSIX
@@ -135,6 +157,15 @@ jobs:
135157 permissions :
136158 contents : read
137159 steps :
160+ # `.nvmrc` is the one source for the Node version, and this job has no
161+ # working tree to read it from. `checkout` cleans the directory, so it has
162+ # to precede the artifact download rather than follow it.
163+ - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
164+ with :
165+ ref : ${{ github.sha }}
166+ sparse-checkout : .nvmrc
167+ sparse-checkout-cone-mode : false
168+
138169 - uses : actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
139170 with :
140171 name : vsix
@@ -204,7 +235,13 @@ jobs:
204235 git tag "$TAG" "$GITHUB_SHA"
205236 git push origin "refs/tags/$TAG"
206237 fi
207- VSIX=$(ls *.vsix | head -n1)
238+ shopt -s nullglob
239+ files=( ./*.vsix )
240+ if [[ ${#files[@]} -ne 1 ]]; then
241+ echo "::error::Expected exactly 1 VSIX to attach, found ${#files[@]}: ${files[*]}"
242+ exit 1
243+ fi
244+ VSIX="${files[0]}"
208245 gh release create "$TAG" \
209246 --title "$TAG" \
210247 --target "$GITHUB_SHA" \
0 commit comments