Update .github/workflows/build-xpi.yml

Cette révision appartient à :
2026-05-24 15:06:13 +00:00
Parent 28c79bbb03
révision dbd14921d4
+148 -147
Voir le fichier
@@ -1,147 +1,148 @@
name: Build & Sign XPI name: Build & Sign XPI
on: on:
push: push:
branches: branches:
- main - main
- "feat/**" - "feat/**"
- "fix/**" - "fix/**"
paths: paths:
- "src/**" - "src/**"
workflow_dispatch:
jobs:
build: jobs:
name: Package, sign and release build:
runs-on: ubuntu-latest name: Package, sign and release
runs-on: ubuntu-latest
permissions:
contents: write # nécessaire pour créer la release GitHub permissions:
contents: write # nécessaire pour créer la release GitHub
steps:
# --------------------------------------------------------------- steps:
# 1. Récupérer le code # ---------------------------------------------------------------
# --------------------------------------------------------------- # 1. Récupérer le code
- name: Checkout # ---------------------------------------------------------------
uses: actions/checkout@v4 - name: Checkout
uses: actions/checkout@v4
# ---------------------------------------------------------------
# 2. Installer Node.js + web-ext (outil officiel Mozilla) # ---------------------------------------------------------------
# --------------------------------------------------------------- # 2. Installer Node.js + web-ext (outil officiel Mozilla)
- name: Setup Node.js # ---------------------------------------------------------------
uses: actions/setup-node@v4 - name: Setup Node.js
with: uses: actions/setup-node@v4
node-version: "20" with:
node-version: "20"
- name: Install web-ext
run: npm install -g web-ext - name: Install web-ext
run: npm install -g web-ext
# ---------------------------------------------------------------
# 3. Lire la version depuis manifest.json # ---------------------------------------------------------------
# --------------------------------------------------------------- # 3. Lire la version depuis manifest.json
- name: Read version # ---------------------------------------------------------------
id: version - name: Read version
run: | id: version
VERSION=$(jq -r '.version' src/manifest.json) run: |
echo "version=${VERSION}" >> "$GITHUB_OUTPUT" VERSION=$(jq -r '.version' src/manifest.json)
echo "unsigned_xpi=ytptube-extension-${VERSION}.xpi" >> "$GITHUB_OUTPUT" echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "signed_xpi=ytptube-extension-${VERSION}-signed.xpi" >> "$GITHUB_OUTPUT" echo "unsigned_xpi=ytptube-extension-${VERSION}.xpi" >> "$GITHUB_OUTPUT"
echo "signed_xpi=ytptube-extension-${VERSION}-signed.xpi" >> "$GITHUB_OUTPUT"
# ---------------------------------------------------------------
# 4. Construire le XPI non signé (lint + zip) # ---------------------------------------------------------------
# --------------------------------------------------------------- # 4. Construire le XPI non signé (lint + zip)
- name: Lint extension # ---------------------------------------------------------------
run: web-ext lint --source-dir src/ - name: Lint extension
run: web-ext lint --source-dir src/
- name: Build unsigned XPI
run: | - name: Build unsigned XPI
web-ext build \ run: |
--source-dir src/ \ web-ext build \
--artifacts-dir dist/ \ --source-dir src/ \
--filename "${{ steps.version.outputs.unsigned_xpi }}" \ --artifacts-dir dist/ \
--overwrite-dest --filename "${{ steps.version.outputs.unsigned_xpi }}" \
echo "Contenu du XPI :" --overwrite-dest
unzip -l "dist/${{ steps.version.outputs.unsigned_xpi }}" echo "Contenu du XPI :"
unzip -l "dist/${{ steps.version.outputs.unsigned_xpi }}"
# ---------------------------------------------------------------
# 5. Uploader le XPI non signé comme artefact CI # ---------------------------------------------------------------
# (toutes branches, utile pour debug) # 5. Uploader le XPI non signé comme artefact CI
# --------------------------------------------------------------- # (toutes branches, utile pour debug)
- name: Upload unsigned artifact # ---------------------------------------------------------------
uses: actions/upload-artifact@v4 - name: Upload unsigned artifact
with: uses: actions/upload-artifact@v4
name: ${{ steps.version.outputs.unsigned_xpi }} with:
path: dist/${{ steps.version.outputs.unsigned_xpi }} name: ${{ steps.version.outputs.unsigned_xpi }}
retention-days: 30 path: dist/${{ steps.version.outputs.unsigned_xpi }}
retention-days: 30
# ---------------------------------------------------------------
# 6. Signer via l'API Mozilla AMO (uniquement sur main) # ---------------------------------------------------------------
# Requiert les secrets AMO_JWT_ISSUER et AMO_JWT_SECRET # 6. Signer via l'API Mozilla AMO (uniquement sur main)
# --------------------------------------------------------------- # Requiert les secrets AMO_JWT_ISSUER et AMO_JWT_SECRET
- name: Sign XPI with Mozilla # ---------------------------------------------------------------
if: github.ref == 'refs/heads/main' - name: Sign XPI with Mozilla
id: sign if: github.ref == 'refs/heads/main'
env: id: sign
AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }} env:
AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }} AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }}
run: | AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }}
web-ext sign \ run: |
--source-dir src/ \ web-ext sign \
--artifacts-dir dist/ \ --source-dir src/ \
--api-key "$AMO_JWT_ISSUER" \ --artifacts-dir dist/ \
--api-secret "$AMO_JWT_SECRET" \ --api-key "$AMO_JWT_ISSUER" \
--channel unlisted --api-secret "$AMO_JWT_SECRET" \
--channel unlisted
# web-ext sign produit un fichier signé dans dist/ — on le retrouve
SIGNED=$(find dist/ -name "*.xpi" ! -name "${{ steps.version.outputs.unsigned_xpi }}" | head -1) # web-ext sign produit un fichier signé dans dist/ — on le retrouve
if [ -z "$SIGNED" ]; then SIGNED=$(find dist/ -name "*.xpi" ! -name "${{ steps.version.outputs.unsigned_xpi }}" | head -1)
echo "Aucun XPI signé trouvé, on utilise l'unsigned en fallback" if [ -z "$SIGNED" ]; then
SIGNED="dist/${{ steps.version.outputs.unsigned_xpi }}" echo "Aucun XPI signé trouvé, on utilise l'unsigned en fallback"
fi SIGNED="dist/${{ steps.version.outputs.unsigned_xpi }}"
cp "$SIGNED" "dist/${{ steps.version.outputs.signed_xpi }}" fi
echo "signed_path=dist/${{ steps.version.outputs.signed_xpi }}" >> "$GITHUB_OUTPUT" cp "$SIGNED" "dist/${{ steps.version.outputs.signed_xpi }}"
echo "signed_path=dist/${{ steps.version.outputs.signed_xpi }}" >> "$GITHUB_OUTPUT"
# ---------------------------------------------------------------
# 7. Uploader le XPI signé comme artefact CI # ---------------------------------------------------------------
# --------------------------------------------------------------- # 7. Uploader le XPI signé comme artefact CI
- name: Upload signed artifact # ---------------------------------------------------------------
if: github.ref == 'refs/heads/main' - name: Upload signed artifact
uses: actions/upload-artifact@v3 if: github.ref == 'refs/heads/main'
with: uses: actions/upload-artifact@v3
name: ${{ steps.version.outputs.signed_xpi }} with:
path: ${{ steps.sign.outputs.signed_path }} name: ${{ steps.version.outputs.signed_xpi }}
retention-days: 90 path: ${{ steps.sign.outputs.signed_path }}
retention-days: 90
# ---------------------------------------------------------------
# 8. Créer ou mettre à jour la pre-release "latest-dev" sur main # ---------------------------------------------------------------
# avec le XPI signé en pièce jointe # 8. Créer ou mettre à jour la pre-release "latest-dev" sur main
# --------------------------------------------------------------- # avec le XPI signé en pièce jointe
- name: Create or update dev release # ---------------------------------------------------------------
if: github.ref == 'refs/heads/main' - name: Create or update dev release
env: if: github.ref == 'refs/heads/main'
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} env:
run: | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG="latest-dev" run: |
XPI="${{ steps.sign.outputs.signed_path }}" TAG="latest-dev"
SHORT_SHA="${GITHUB_SHA::7}" XPI="${{ steps.sign.outputs.signed_path }}"
VERSION="${{ steps.version.outputs.version }}" SHORT_SHA="${GITHUB_SHA::7}"
TITLE="Dev build v${VERSION} (${SHORT_SHA})" VERSION="${{ steps.version.outputs.version }}"
TITLE="Dev build v${VERSION} (${SHORT_SHA})"
# Supprimer l'ancienne release/tag si elle existe
gh release delete "$TAG" --yes 2>/dev/null || true # Supprimer l'ancienne release/tag si elle existe
git push --delete origin "$TAG" 2>/dev/null || true gh release delete "$TAG" --yes 2>/dev/null || true
git push --delete origin "$TAG" 2>/dev/null || true
# Recréer la release pre-release avec le XPI signé
gh release create "$TAG" "$XPI" \ # Recréer la release pre-release avec le XPI signé
--title "$TITLE" \ gh release create "$TAG" "$XPI" \
--notes "$(cat <<NOTES --title "$TITLE" \
## Dev build v${VERSION} --notes "$(cat <<NOTES
## Dev build v${VERSION}
Commit : \`${SHORT_SHA}\` sur \`main\`
Commit : \`${SHORT_SHA}\` sur \`main\`
### Installation sur Firefox Android
1. Ouvrir Firefox Android ### Installation sur Firefox Android
2. Aller sur cette page de release et télécharger le \`.xpi\` 1. Ouvrir Firefox Android
3. Firefox installe automatiquement l'extension (signée Mozilla ✓) 2. Aller sur cette page de release et télécharger le \`.xpi\`
NOTES 3. Firefox installe automatiquement l'extension (signée Mozilla ✓)
)" \ NOTES
--prerelease )" \
--prerelease