🐛 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
+101
-33
No files matched your search
@@ -1,12 +1,19 @@
|
|||||||
name: VSIX Release
|
name: VSIX Release
|
||||||
|
|
||||||
# Compila il pacchetto .vsix di un'estensione VS Code e lo allega alla release Gitea del tag.
|
# Rilascio di un'estensione VS Code, in un unico flusso:
|
||||||
# Va eseguito dopo auto-release.yml (needs), che crea la release.
|
# 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:
|
# Prerequisiti nel repository chiamante:
|
||||||
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
||||||
# - lo script package produce <name>-<version>.vsix nella working-directory
|
# - lo script package produce <name>-<version>.vsix nella working-directory
|
||||||
# - il tag deve essere 'v' + version
|
# - il tag deve essere 'v' + version
|
||||||
|
# - Secrets: G_USER (utente proprietario del token) e NPM_TOKEN (token con scope package)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
@@ -33,11 +40,17 @@ jobs:
|
|||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
uses: https://gitea.pzetatouch.it/actions/checkout@v7
|
uses: https://gitea.pzetatouch.it/actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
|
# Storia e tag servono al changelog.
|
||||||
|
fetch-depth: 0
|
||||||
token: ${{ gitea.token }}
|
token: ${{ gitea.token }}
|
||||||
|
|
||||||
# Prima di installare: un tag disallineato produrrebbe un .vsix con un'altra versione.
|
# Controlli immediati: un tag disallineato produrrebbe un .vsix con un'altra versione,
|
||||||
- name: Check tag version
|
# e senza secrets il flusso si fermerebbe a rilascio già pubblicato.
|
||||||
|
- name: Check tag version and secrets
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
G_USER: ${{ secrets.G_USER }}
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG=${GITHUB_REF#refs/tags/}
|
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)."
|
echo "::error::Il tag $TAG non corrisponde alla versione $VERSION di package.json (atteso v$VERSION)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
- name: Setup Node.js
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
@@ -93,9 +110,17 @@ jobs:
|
|||||||
|
|
||||||
- name: Package VSIX
|
- name: Package VSIX
|
||||||
timeout-minutes: 10
|
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
|
timeout-minutes: 10
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
@@ -105,29 +130,76 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG=${GITHUB_REF#refs/tags/}
|
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"
|
API="$SERVER_URL/api/v1/repos/$REPOSITORY"
|
||||||
|
|
||||||
if [ ! -f "$VSIX" ]; then
|
api() {
|
||||||
echo "::error::Lo script package non ha prodotto $VSIX."
|
curl -sS --fail-with-body --max-time 300 -H "Authorization: token $GITEA_TOKEN" "$@"
|
||||||
exit 1
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
if ! RELEASE=$(curl -sS --fail-with-body --max-time 60 \
|
if [ "$(jq -r '.draft' /tmp/release.json)" = "true" ]; then
|
||||||
-H "Authorization: token $GITEA_TOKEN" "$API/releases/tags/$TAG"); then
|
api -X PATCH -H 'Content-Type: application/json' -d '{"draft": false}' "$API/releases/$ID" > /dev/null
|
||||||
echo "::error::Release del tag $TAG non trovata: $RELEASE"
|
echo "Release $TAG pubblicata."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Rieseguendo il job, o se l'allegato e' stato caricato a mano, non si sovrascrive.
|
- name: Publish to package registry
|
||||||
if echo "$RELEASE" | jq -e --arg name "$VSIX" 'any(.assets[]?; .name == $name)' > /dev/null; then
|
timeout-minutes: 10
|
||||||
echo "::notice::$VSIX e' gia' allegato alla release $TAG: nessun caricamento."
|
shell: bash
|
||||||
exit 0
|
env:
|
||||||
fi
|
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"
|
||||||
|
|
||||||
ID=$(echo "$RELEASE" | jq -r '.id')
|
STATUS=$(curl -sS --max-time 300 -o /tmp/package.txt -w '%{http_code}' -u "$G_USER:$NPM_TOKEN" \
|
||||||
curl -sS --fail-with-body --max-time 300 -X POST \
|
--upload-file "$VSIX" "$SERVER_URL/api/packages/$OWNER/generic/$NAME/$VERSION/$VSIX")
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
case "$STATUS" in
|
||||||
-F "attachment=@$VSIX" \
|
201) echo "$VSIX pubblicato nel registro pacchetti di $OWNER." ;;
|
||||||
"$API/releases/$ID/assets?name=$VSIX" > /dev/null
|
409) echo "::notice::$VSIX è già nel registro pacchetti: nessun caricamento." ;;
|
||||||
echo "$VSIX allegato alla release $TAG."
|
*)
|
||||||
|
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
|
# 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.
|
# NOTA: un solo job. Non aggiungere auto-release: creerebbe la release prima del .vsix.
|
||||||
# Workaround Gitea bug #31900: token esplicito nel checkout dei workflow condivisi.
|
# Workaround Gitea bug #31900: token esplicito nel checkout del workflow condiviso.
|
||||||
#
|
#
|
||||||
# Prerequisiti:
|
# Prerequisiti:
|
||||||
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
# - package.json con script: lint:check, typecheck, format:check, build, test, package
|
||||||
# - il tag deve essere 'v' + version di package.json
|
# - il tag deve essere 'v' + version di package.json
|
||||||
|
# - Secrets di organizzazione: G_USER + NPM_TOKEN (token Gitea con scope package)
|
||||||
|
|
||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
@@ -16,11 +17,6 @@ on:
|
|||||||
- 'v*'
|
- 'v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
auto-release:
|
|
||||||
uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/auto-release.yml@v1
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
vsix-release:
|
vsix-release:
|
||||||
needs: [auto-release]
|
|
||||||
uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/vsix-release.yml@v1
|
uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/vsix-release.yml@v1
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
Reference in new issue
Block a user