diff --git a/.gitea/workflows/vsix-release.yml b/.gitea/workflows/vsix-release.yml new file mode 100644 index 0000000..fc6b419 --- /dev/null +++ b/.gitea/workflows/vsix-release.yml @@ -0,0 +1,133 @@ +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. +# +# Prerequisiti nel repository chiamante: +# - package.json con script: lint:check, typecheck, format:check, build, test, package +# - lo script package produce -.vsix nella working-directory +# - il tag deve essere 'v' + version + +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: + token: ${{ gitea.token }} + + # Prima di installare: un tag disallineato produrrebbe un .vsix con un'altra versione. + - name: Check tag version + shell: bash + 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 + + - 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 + run: npm run package + + - name: Attach VSIX to release + 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/} + VSIX="$(jq -r '.name' package.json)-$(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." + exit 1 + fi + + 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 + echo "$VSIX allegato alla release $TAG." diff --git a/examples/estensione-vscode/ci.yml b/examples/estensione-vscode/ci.yml new file mode 100644 index 0000000..1daea63 --- /dev/null +++ b/examples/estensione-vscode/ci.yml @@ -0,0 +1,23 @@ +# Copia in: .gitea/workflows/ci.yml +# Usato da: estensioni VS Code +# +# Prerequisiti: +# - package.json con script: lint:check, typecheck, format:check, build, test + +name: CI + +on: + push: + branches: + - main + paths-ignore: + - '**.md' + - 'docs/**' + pull_request: + branches: + - main + +jobs: + quality-gates: + uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/quality-gates.yml@v1 + secrets: inherit diff --git a/examples/estensione-vscode/maintenance.yml b/examples/estensione-vscode/maintenance.yml new file mode 100644 index 0000000..c9b6c6a --- /dev/null +++ b/examples/estensione-vscode/maintenance.yml @@ -0,0 +1,36 @@ +# Copia in: .gitea/workflows/maintenance.yml +# Trigger: +# - PR merged → cleanup branch sorgente +# - Ogni lunedì 08:00 → security audit vulnerabilità (settimanale) +# - Ogni 1° del mese → controllo pacchetti obsoleti (mensile) +# - Manuale → workflow_dispatch (esegue tutti i job di manutenzione) + +name: Maintenance + +on: + pull_request: + types: [closed] + schedule: + - cron: '0 2 * * 3' # ogni mercoledì alle 02:00 → security audit + - cron: '0 2 1 * *' # ogni 1° del mese alle 02:00 → outdated check + workflow_dispatch: + +jobs: + branch-cleanup: + if: gitea.event_name == 'pull_request' && gitea.event.pull_request.merged == true + uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/branch-cleanup.yml@v1 + secrets: inherit + + dependency-audit: + if: > + gitea.event_name == 'workflow_dispatch' || + (gitea.event_name == 'schedule' && gitea.event.schedule == '0 2 * * 3') + uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/dependency-check.yml@v1 + secrets: inherit + + dependency-outdated: + if: > + gitea.event_name == 'workflow_dispatch' || + (gitea.event_name == 'schedule' && gitea.event.schedule == '0 2 1 * *') + uses: https://gitea.pzetatouch.it/devops/shared-actions/.gitea/workflows/dependency-outdated.yml@v1 + secrets: inherit diff --git a/examples/estensione-vscode/release.yml b/examples/estensione-vscode/release.yml new file mode 100644 index 0000000..b5e9f8d --- /dev/null +++ b/examples/estensione-vscode/release.yml @@ -0,0 +1,26 @@ +# Copia in: .gitea/workflows/release.yml +# Trigger: git tag v* → crea la release Gitea e le allega il pacchetto .vsix +# +# 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. +# +# Prerequisiti: +# - package.json con script: lint:check, typecheck, format:check, build, test, package +# - il tag deve essere 'v' + version di package.json + +name: Release + +on: + push: + tags: + - '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