diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..6b39736 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,151 @@ +name: Release su wordpress.org + +# Pubblica il plugin sulla directory di wordpress.org, che accetta SOLO SVN. +# Git resta la fonte di verita', SVN e' il nastro trasportatore verso la +# directory: qui dentro non si fa versionamento, si fa un rilascio e basta. +# +# Come si rilascia: +# 1. alza la versione nei TRE posti (vedi sotto), commit, push +# 2. git tag v1.0.1 && git push origin v1.0.1 +# 3. questo workflow fa il resto +# +# La versione sta in tre punti che devono combaciare, e il job si ferma se non +# combaciano: l'header `Version:` di piazza-in-festa.php, la costante +# PINFESTA_VERSION nello stesso file, e `Stable tag:` di readme.txt. Lo Stable +# tag e' quello che wordpress.org serve davvero agli utenti: se punta a un tag +# che in SVN non esiste, la pagina pubblica resta ferma o si rompe. +# +# Secrets richiesti (Impostazioni del repo -> Actions -> Secrets): +# WPORG_SVN_PASSWORD password SVN del profilo wordpress.org (NON quella del sito) +# Variabili opzionali (-> Variables): +# WPORG_SVN_USERNAME default 'thisloke', maiuscole/minuscole contano + +on: + push: + tags: ['v*'] + workflow_dispatch: + +env: + SLUG: piazza-in-festa + SVN_URL: https://plugins.svn.wordpress.org/piazza-in-festa + +jobs: + rilascio: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Strumenti (svn, zip, rsync) + run: | + set -e + apt-get update -qq + apt-get install -y --no-install-recommends subversion zip rsync ca-certificates + + - name: Versione coerente nei tre posti + run: | + set -e + HEADER=$(grep -m1 '^ \* Version:' piazza-in-festa.php | awk '{print $3}') + COSTANTE=$(grep -m1 "define( 'PINFESTA_VERSION'" piazza-in-festa.php | sed -E "s/.*'([0-9][^']*)'.*/\1/") + STABLE=$(grep -m1 '^Stable tag:' readme.txt | awk '{print $3}') + + echo "header=$HEADER costante=$COSTANTE stable=$STABLE" + + if [ "$HEADER" != "$COSTANTE" ] || [ "$HEADER" != "$STABLE" ]; then + echo "Le tre versioni non combaciano: alza header, PINFESTA_VERSION e Stable tag insieme." >&2 + exit 1 + fi + + # Se il giro parte da un tag git, deve essere lo stesso numero. + case "${{ github.ref }}" in + refs/tags/*) + TAG_GIT="${{ github.ref_name }}" + if [ "${TAG_GIT#v}" != "$HEADER" ]; then + echo "Il tag git $TAG_GIT non corrisponde alla versione $HEADER del plugin." >&2 + exit 1 + fi + ;; + esac + + echo "VERSIONE=$HEADER" >> "$GITHUB_ENV" + + - name: Il tag non deve esistere gia' su wordpress.org + run: | + # Un tag pubblicato non si sovrascrive: se serve correggerlo si alza + # la versione. Meglio fermarsi qui che accorgersene a rilascio fatto. + if svn ls "$SVN_URL/tags/$VERSIONE" >/dev/null 2>&1; then + echo "tags/$VERSIONE esiste gia' in SVN. Alza la versione." >&2 + exit 1 + fi + + - name: Costruisci il pacchetto + run: | + set -e + ./build.sh + # Si lavora sul contenuto dello zip, non sulla cartella del repo: in + # trunk deve finire esattamente cio' che l'utente si installa, senza + # build.sh, .gitignore e cartelle di sviluppo. + mkdir -p pacchetto + unzip -q "dist/$SLUG.zip" -d pacchetto + test -f "pacchetto/$SLUG/piazza-in-festa.php" + + - name: Copia di lavoro SVN + run: | + set -e + # --depth immediates: non scarica i rilasci passati, servono solo i + # nomi delle cartelle sotto tags/ per poterci copiare dentro. + svn co --depth immediates "$SVN_URL" svn + svn up --set-depth infinity svn/trunk + svn up --set-depth infinity svn/assets + + - name: Aggiorna trunk, assets e il tag + run: | + set -e + rsync -a --delete --exclude '.svn' "pacchetto/$SLUG/" svn/trunk/ + + # Le immagini della pagina pubblica (icon-256x256.png, + # banner-1544x500.png, screenshot-N.png) stanno in assets/ del SVN e + # NON dentro al plugin: se .wordpress-org/ e' vuota si salta. + if [ -n "$(ls -A .wordpress-org 2>/dev/null)" ]; then + rsync -a --delete --exclude '.svn' .wordpress-org/ svn/assets/ + fi + + cd svn + # File spariti dal pacchetto: via anche da SVN. Prima le rimozioni, + # cosi' le aggiunte non ricreano voci gia' marcate. + svn status | sed -n 's/^![[:space:]]*//p' | while IFS= read -r morto; do + svn rm --force "$morto" + done + # --force su una cartella gia' versionata non e' un errore: aggiunge + # solo cio' che ancora non c'e'. + svn add --force trunk assets + svn copy trunk "tags/$VERSIONE" + svn status + + - name: Pubblica + env: + SVN_USER: ${{ vars.WPORG_SVN_USERNAME || 'thisloke' }} + SVN_PASS: ${{ secrets.WPORG_SVN_PASSWORD }} + run: | + set -e + if [ -z "$SVN_PASS" ]; then + echo "Manca il secret WPORG_SVN_PASSWORD." >&2 + exit 1 + fi + cd svn + # Un solo commit per trunk, assets e tag: in SVN e' atomico, quindi + # non esiste lo stato intermedio in cui lo Stable tag punta a un tag + # non ancora caricato. + svn ci \ + -m "Release $VERSIONE" \ + --username "$SVN_USER" \ + --password "$SVN_PASS" \ + --non-interactive --no-auth-cache --trust-server-cert + echo "Pubblicata la $VERSIONE su https://wordpress.org/plugins/$SLUG" + + - name: Conserva lo zip + uses: actions/upload-artifact@v3 + with: + name: piazza-in-festa-${{ env.VERSIONE }} + path: dist/piazza-in-festa.zip