Files
LucaZanni 7e13a831e7 🐛 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
2026-11-27 10:15:00 +01:00

206 lines
8.2 KiB
YAML

name: VSIX 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:
inputs:
working-directory:
description: 'Cartella che contiene package.json, relativa alla root del repo. Default: la root.'
type: string
default: '.'
node-version:
type: string
default: '24.16.0'
jobs:
vsix-release:
runs-on: ubuntu-latest
# Il chiamante non puo' dichiararlo: su un job che usa un workflow
# riusabile timeout-minutes non e' una chiave ammessa (devops/shared-actions#23).
timeout-minutes: 30
defaults:
run:
working-directory: ${{ inputs.working-directory || '.' }}
steps:
- name: Checkout
timeout-minutes: 10
uses: https://gitea.pzetatouch.it/actions/checkout@v7
with:
# Storia e tag servono al changelog.
fetch-depth: 0
token: ${{ gitea.token }}
# 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/}
VERSION=$(jq -r '.version' package.json)
if [ "$TAG" != "v$VERSION" ]; then
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
uses: https://gitea.pzetatouch.it/actions/setup-node@v7
with:
node-version: ${{ inputs.node-version || '24.16.0' }}
# La cache npm resta allo step actions/cache: dalla v5 setup-node la accende
# da solo se package.json ha packageManager, e la duplicherebbe.
package-manager-cache: false
- name: Cache npm
timeout-minutes: 10
uses: https://gitea.pzetatouch.it/actions/cache@v6
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Configure npm private registry
run: |
echo "@pzeta:registry=https://gitea.pzetatouch.it/api/packages/PZeta_Touch/npm/" >> ~/.npmrc
echo "//gitea.pzetatouch.it/api/packages/PZeta_Touch/npm/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Install dependencies
timeout-minutes: 15
run: npm ci
- name: Lint
run: npm run lint:check
- name: Type check
run: npm run typecheck
- name: Format check
run: npm run format:check
- name: Build
timeout-minutes: 15
run: npm run build
- name: Test
timeout-minutes: 20
run: npm run test
- name: Package VSIX
timeout-minutes: 10
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: Publish release with VSIX
timeout-minutes: 10
shell: bash
env:
GITEA_TOKEN: ${{ gitea.token }}
SERVER_URL: ${{ gitea.server_url }}
REPOSITORY: ${{ gitea.repository }}
run: |
set -euo pipefail
TAG=${GITHUB_REF#refs/tags/}
NAME=$(jq -r '.name' package.json)
VSIX="$NAME-$(jq -r '.version' package.json).vsix"
API="$SERVER_URL/api/v1/repos/$REPOSITORY"
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
;;
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
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