Files
shared-actions/.gitea/workflows/docker-release.yml
T
LucaZanni f7a39c8ae3 ✨ feat(ci): blocca i microfrontend il cui dist importa ancora vue
- passo dopo Build in quality-gates e docker-release, solo con dist/mfe-entry.js
- ignora gli esempi nei commenti e si autoverifica su casi di prova

Fixes #31 @1h30m

Claude-Session: https://claude.ai/code/session_018fSA352dm2Px856dGvQfyq
2026-12-05 22:36:33 +01:00

162 lines
6.0 KiB
YAML

name: Docker Release
on:
workflow_call:
inputs:
node-version:
type: string
default: '24.16.0'
npm-version:
type: string
default: ''
runner:
type: string
default: 'catthehacker-latest'
jobs:
docker-release:
runs-on: ${{ inputs.runner }}
# 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: 45
steps:
- name: Checkout
timeout-minutes: 10
uses: https://gitea.pzetatouch.it/actions/checkout@v7
- 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: Upgrade npm
if: inputs.npm-version != ''
timeout-minutes: 10
run: npm install -g npm@${{ inputs.npm-version }}
- 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: Type check
run: npm run typecheck
- name: Lint
run: npm run lint:check
- name: Format check
run: npm run format:check
- name: Build
timeout-minutes: 15
run: npm run build
- name: Microfrontend - nessun import di vue nel dist
timeout-minutes: 5
shell: bash
# BLOCCANTE (devops/shared-actions#31). Nella shell un import di vue rimasto
# nel dist non si risolve e il modulo non si carica, con build e test verdi.
run: |
node - <<'FINE'
const fs = require('fs')
const path = require('path')
// Solo i microfrontend: la shell fornisce vue, quindi nel loro dist non deve restarne un import.
if (!fs.existsSync('dist/mfe-entry.js')) {
console.log('Nessun dist/mfe-entry.js: controllo non applicabile.')
process.exit(0)
}
// Ancorata a inizio riga, ';' o '}': un esempio in un commento (' * import ...') non e' un import.
const IMPORT = /(?:^|[;}])[ \t]*(?:import|export)\b[^;"'()=]*?(?:\bfrom\s*)?["'](?:vue|vue-router)["']/m
const prove = [
['import "vue";', true],
['var a=1;import{ref as r}from"vue";', true],
["import {\n ref,\n} from 'vue'", true],
['export * from "vue-router"', true],
[" * import { createApp } from 'vue'", false],
['// import "vue"', false],
['const s = "import x from \'vue\'"', false],
['import{a}from"vue-i18n";', false],
]
for (const [testo, atteso] of prove) {
if (IMPORT.test(testo) !== atteso) {
console.log(`::error::Controllo non affidabile: caso di prova fallito (${JSON.stringify(testo)}).`)
process.exit(1)
}
}
const file = fs.readdirSync('dist', { recursive: true }).filter((f) => /\.m?js$/.test(f))
const difettosi = file.filter((f) => IMPORT.test(fs.readFileSync(path.join('dist', f), 'utf8')))
if (difettosi.length) {
console.log("::error::Il dist del microfrontend importa ancora 'vue' o 'vue-router': nella shell il modulo non si carica.")
for (const f of difettosi) console.log(' dist/' + f)
console.log('Controllare il plugin external-globals in vite.config: deve trattare anche l\'import senza nomi (import "vue";).')
process.exit(1)
}
console.log(`Nessun import di vue nel dist (${file.length} file JavaScript).`)
FINE
- name: Test
timeout-minutes: 20
run: npm run test
- name: Login to container registry
timeout-minutes: 5
uses: https://gitea.pzetatouch.it/actions/login-action@v4
with:
registry: gitea.pzetatouch.it
username: ${{ secrets.G_USER }}
password: ${{ secrets.NPM_TOKEN }}
- name: Determine image tags
id: tags
run: |
RAW_NAME=$(jq -r '.name' package.json)
APP_NAME=$(echo "$RAW_NAME" | sed 's|^@[^/]*/||')
VERSION=$(jq -r '.version' package.json)
REGISTRY="gitea.pzetatouch.it/pzeta_touch"
echo "version_tag=${REGISTRY}/${APP_NAME}:${VERSION}" >> $GITHUB_OUTPUT
echo "latest_tag=${REGISTRY}/${APP_NAME}:latest" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
timeout-minutes: 30
uses: https://gitea.pzetatouch.it/actions/build-push-action@v7
with:
push: true
context: .
file: ./Dockerfile
tags: |
${{ steps.tags.outputs.version_tag }}
${{ steps.tags.outputs.latest_tag }}
labels: |
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
org.opencontainers.image.revision=${{ gitea.sha }}
org.opencontainers.image.version=${{ steps.tags.outputs.version }}
build-args: |
NODE_VERSION=${{ vars.NODE_DOCKER_VERSION || '24.16.0-alpine3.22' }}
NGINX_VERSION=${{ vars.NGINX_DOCKER_VERSION || '1.30.2-alpine3.23' }}
NPM_VERSION=${{ vars.NPM_VERSION || '11.16.0' }}
secrets: |
npm_token=${{ secrets.NPM_TOKEN }}