🐛 fix(ci): vsix-release pubblica la release solo a pacchetto pronto
- Flusso unico: gate e build, release in bozza, allegato, pubblicazione e registro pacchetti generic - Job rieseguibile, con errori espliciti su ogni chiamata e secrets controllati all'inizio - Esempio estensione-vscode/release.yml senza auto-release Fixes #30 @1h30m
This commit is contained in:
1 parent
b4ec52a4fe
commit
7e13a831e7
2 files changed
+103
-35
No files matched your search
@@ -1,12 +1,19 @@
|
||||
name: VSIX Release
|
||||
|
||||
# Compila il pacchetto .vsix di un'estensione VS Code e lo allega alla release Gitea del tag.
|
||||
# Va eseguito dopo auto-release.yml (needs), che crea la release.
|
||||
# Rilascio di un'estensione VS Code, in un unico flusso:
|
||||
# quality gate e build → .vsix → release in bozza → allegato → pubblicazione → registro pacchetti
|
||||
#
|
||||
# La release diventa pubblica solo quando il .vsix è già allegato. Il pacchetto (tipo generic)
|
||||
# viene pubblicato per ultimo: è il segnale che le estensioni installate usano per avvisare
|
||||
# di un aggiornamento. Non va combinato con auto-release.yml, che creerebbe la release prima.
|
||||
#
|
||||
# Il job è rieseguibile: ciò che esiste già non viene sovrascritto.
|
||||
#
|
||||
# Prerequisiti nel repository chiamante:
|
||||
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
||||
# - lo script package produce <name>-<version>.vsix nella working-directory
|
||||
# - il tag deve essere 'v' + version
|
||||
# - Secrets: G_USER (utente proprietario del token) e NPM_TOKEN (token con scope package)
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
@@ -33,11 +40,17 @@ jobs:
|
||||
timeout-minutes: 10
|
||||
uses: https://gitea.pzetatouch.it/actions/checkout@v7
|
||||
with:
|
||||
# Storia e tag servono al changelog.
|
||||
fetch-depth: 0
|
||||
token: ${{ gitea.token }}
|
||||
|
||||
# Prima di installare: un tag disallineato produrrebbe un .vsix con un'altra versione.
|
||||
- name: Check tag version
|
||||
# Controlli immediati: un tag disallineato produrrebbe un .vsix con un'altra versione,
|
||||
# e senza secrets il flusso si fermerebbe a rilascio già pubblicato.
|
||||
- name: Check tag version and secrets
|
||||
shell: bash
|
||||
env:
|
||||
G_USER: ${{ secrets.G_USER }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
@@ -46,6 +59,10 @@ jobs:
|
||||
echo "::error::Il tag $TAG non corrisponde alla versione $VERSION di package.json (atteso v$VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$G_USER" ] || [ -z "$NPM_TOKEN" ]; then
|
||||
echo "::error::Secrets G_USER e/o NPM_TOKEN non disponibili: serve 'secrets: inherit' nel workflow chiamante."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
timeout-minutes: 10
|
||||
@@ -93,9 +110,17 @@ jobs:
|
||||
|
||||
- name: Package VSIX
|
||||
timeout-minutes: 10
|
||||
run: npm run package
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
npm run package
|
||||
VSIX="$(jq -r '.name' package.json)-$(jq -r '.version' package.json).vsix"
|
||||
if [ ! -f "$VSIX" ]; then
|
||||
echo "::error::Lo script package non ha prodotto $VSIX."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Attach VSIX to release
|
||||
- name: Publish release with VSIX
|
||||
timeout-minutes: 10
|
||||
shell: bash
|
||||
env:
|
||||
@@ -105,29 +130,76 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
VSIX="$(jq -r '.name' package.json)-$(jq -r '.version' package.json).vsix"
|
||||
NAME=$(jq -r '.name' package.json)
|
||||
VSIX="$NAME-$(jq -r '.version' package.json).vsix"
|
||||
API="$SERVER_URL/api/v1/repos/$REPOSITORY"
|
||||
|
||||
if [ ! -f "$VSIX" ]; then
|
||||
echo "::error::Lo script package non ha prodotto $VSIX."
|
||||
api() {
|
||||
curl -sS --fail-with-body --max-time 300 -H "Authorization: token $GITEA_TOKEN" "$@"
|
||||
}
|
||||
|
||||
# 200: la release esiste (anche in bozza, il token ha permesso di scrittura). 404: va creata.
|
||||
STATUS=$(curl -sS --max-time 60 -o /tmp/release.json -w '%{http_code}' \
|
||||
-H "Authorization: token $GITEA_TOKEN" "$API/releases/tags/$TAG")
|
||||
case "$STATUS" in
|
||||
200) echo "Release $TAG già presente: note e titolo restano invariati." ;;
|
||||
404)
|
||||
PREVIOUS=$(git describe --tags --abbrev=0 --match 'v*' "$TAG^" 2>/dev/null || true)
|
||||
RANGE=${PREVIOUS:+$PREVIOUS..}$TAG
|
||||
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' "$RANGE")
|
||||
PRERELEASE=false
|
||||
case "$TAG" in *-*) PRERELEASE=true ;; esac
|
||||
jq -n --arg tag "$TAG" --arg name "$NAME $TAG" --arg body "$CHANGELOG" --argjson pre "$PRERELEASE" \
|
||||
'{tag_name: $tag, name: $name, body: $body, draft: true, prerelease: $pre}' \
|
||||
| api -X POST -H 'Content-Type: application/json' --data-binary @- "$API/releases" > /tmp/release.json
|
||||
;;
|
||||
*)
|
||||
echo "::error::Lettura della release $TAG fallita con stato $STATUS: $(cat /tmp/release.json)"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! RELEASE=$(curl -sS --fail-with-body --max-time 60 \
|
||||
-H "Authorization: token $GITEA_TOKEN" "$API/releases/tags/$TAG"); then
|
||||
echo "::error::Release del tag $TAG non trovata: $RELEASE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Rieseguendo il job, o se l'allegato e' stato caricato a mano, non si sovrascrive.
|
||||
if echo "$RELEASE" | jq -e --arg name "$VSIX" 'any(.assets[]?; .name == $name)' > /dev/null; then
|
||||
echo "::notice::$VSIX e' gia' allegato alla release $TAG: nessun caricamento."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ID=$(echo "$RELEASE" | jq -r '.id')
|
||||
curl -sS --fail-with-body --max-time 300 -X POST \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-F "attachment=@$VSIX" \
|
||||
"$API/releases/$ID/assets?name=$VSIX" > /dev/null
|
||||
ID=$(jq -r '.id' /tmp/release.json)
|
||||
if jq -e --arg name "$VSIX" 'any(.assets[]?; .name == $name)' /tmp/release.json > /dev/null; then
|
||||
echo "::notice::$VSIX è già allegato alla release $TAG: nessun caricamento."
|
||||
else
|
||||
api -X POST -F "attachment=@$VSIX" "$API/releases/$ID/assets?name=$VSIX" > /dev/null
|
||||
echo "$VSIX allegato alla release $TAG."
|
||||
fi
|
||||
|
||||
if [ "$(jq -r '.draft' /tmp/release.json)" = "true" ]; then
|
||||
api -X PATCH -H 'Content-Type: application/json' -d '{"draft": false}' "$API/releases/$ID" > /dev/null
|
||||
echo "Release $TAG pubblicata."
|
||||
fi
|
||||
|
||||
- name: Publish to package registry
|
||||
timeout-minutes: 10
|
||||
shell: bash
|
||||
env:
|
||||
G_USER: ${{ secrets.G_USER }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
SERVER_URL: ${{ gitea.server_url }}
|
||||
OWNER: ${{ gitea.repository_owner }}
|
||||
REPOSITORY: ${{ gitea.repository }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
NAME=$(jq -r '.name' package.json)
|
||||
VERSION=$(jq -r '.version' package.json)
|
||||
VSIX="$NAME-$VERSION.vsix"
|
||||
|
||||
STATUS=$(curl -sS --max-time 300 -o /tmp/package.txt -w '%{http_code}' -u "$G_USER:$NPM_TOKEN" \
|
||||
--upload-file "$VSIX" "$SERVER_URL/api/packages/$OWNER/generic/$NAME/$VERSION/$VSIX")
|
||||
case "$STATUS" in
|
||||
201) echo "$VSIX pubblicato nel registro pacchetti di $OWNER." ;;
|
||||
409) echo "::notice::$VSIX è già nel registro pacchetti: nessun caricamento." ;;
|
||||
*)
|
||||
echo "::error::Pubblicazione del pacchetto fallita con stato $STATUS: $(cat /tmp/package.txt)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Il collegamento mostra il pacchetto nella pagina del repository: se è già presente fallisce.
|
||||
if ! curl -sS --fail-with-body --max-time 60 -X POST -H "Authorization: token $NPM_TOKEN" \
|
||||
"$SERVER_URL/api/v1/packages/$OWNER/generic/$NAME/-/link/${REPOSITORY#*/}"; then
|
||||
echo "::warning::Pacchetto $NAME non collegato al repository (forse lo è già)."
|
||||
fi
|
||||
@@ -1,12 +1,13 @@
|
||||
# Copia in: .gitea/workflows/release.yml
|
||||
# Trigger: git tag v* → crea la release Gitea e le allega il pacchetto .vsix
|
||||
# Trigger: git tag v* → build del .vsix, release Gitea con allegato, registro pacchetti
|
||||
#
|
||||
# NOTA: vsix-release attende auto-release via needs, perché carica nella release già creata.
|
||||
# Workaround Gitea bug #31900: token esplicito nel checkout dei workflow condivisi.
|
||||
# NOTA: un solo job. Non aggiungere auto-release: creerebbe la release prima del .vsix.
|
||||
# Workaround Gitea bug #31900: token esplicito nel checkout del workflow condiviso.
|
||||
#
|
||||
# Prerequisiti:
|
||||
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
||||
# - il tag deve essere 'v' + version di package.json
|
||||
# - Secrets di organizzazione: G_USER + NPM_TOKEN (token Gitea con scope package)
|
||||
|
||||
name: Release
|
||||
|
||||
@@ -16,11 +17,6 @@ on:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
auto-release:
|
||||
uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/auto-release.yml@v1
|
||||
secrets: inherit
|
||||
|
||||
vsix-release:
|
||||
needs: [auto-release]
|
||||
uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/vsix-release.yml@v1
|
||||
secrets: inherit
|
||||
Reference in new issue
Block a user