Cette révision appartient à :
jimmyGALLAND committed 2026-11-22 14:29:41 +01:00
1 Parent 670d251a6f
révision c971022faa
4 files changed
+246 -94

No files matched your search

+218 -84
Voir le fichier
@@ -1,8 +1,8 @@
name: Firefox extension release
name: Firefox extension release
on: on:
release: workflow_dispatch:
types: [published]
permissions: permissions:
contents: write contents: write
@@ -14,73 +14,183 @@ jobs:
env: env:
EXTENSION_DIR: src/ EXTENSION_DIR: src/
RELEASE_TAG: ${{ gitea.event.release.tag_name }}
RELEASE_ID: ${{ gitea.event.release.id }}
REPOSITORY: ${{ gitea.repository }} REPOSITORY: ${{ gitea.repository }}
GITEA_SERVER_URL: ${{ gitea.server_url }} GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_SHA: ${{ gitea.sha }}
steps: steps:
- name: Checkout release commit # --------------------------------------------------
# 1. Checkout du dépôt
# --------------------------------------------------
- name: Checkout main branch
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ gitea.sha }} ref: main
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
- name: Ensure the release tag exists # --------------------------------------------------
# 2. Détermination de la prochaine version
# --------------------------------------------------
- name: Determine next version
id: version
shell: bash shell: bash
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: | run: |
set -euo pipefail set -euo pipefail
if [[ -z "${RELEASE_TAG}" ]]; then if [[ -z "${GITEA_TOKEN:-}" ]]; then
echo "::error::The release event does not contain a tag name." echo "::error::GITEA_TOKEN is missing."
exit 1 exit 1
fi fi
git fetch --force origin \ git fetch --force --tags origin
"+refs/tags/${RELEASE_TAG}:refs/tags/${RELEASE_TAG}" \
2>/dev/null || true
if git show-ref --verify --quiet "refs/tags/${RELEASE_TAG}"; then CURRENT_VERSION="$(node -p \
echo "Tag ${RELEASE_TAG} already exists." "require('./${EXTENSION_DIR}/manifest.json').version")"
else
if [[ -z "${GITEA_SHA}" ]]; then
echo "::error::Cannot create the tag: the release commit SHA is missing."
exit 1
fi
git tag -a "${RELEASE_TAG}" "${GITEA_SHA}" \ if [[ ! "${CURRENT_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
-m "Release ${RELEASE_TAG}" echo "::error::Invalid manifest version: ${CURRENT_VERSION}"
exit 1
# Use an HTTP authorization header so the token is not embedded
# in the remote URL or written to the Git configuration.
AUTH="$(printf 'x-access-token:%s' "${GITEA_TOKEN}" | base64 -w 0)"
git -c http.extraheader="AUTHORIZATION: basic ${AUTH}" \
push origin "refs/tags/${RELEASE_TAG}"
fi fi
git checkout --detach "refs/tags/${RELEASE_TAG}" VERSION="${CURRENT_VERSION}"
echo "Release tag points to $(git rev-parse HEAD)."
- name: Validate release version echo "Version found in manifest: ${VERSION}"
# Increment patch version while the corresponding tag exists.
while git show-ref --verify --quiet "refs/tags/v${VERSION}"; do
echo "Tag v${VERSION} already exists."
IFS='.' read -r MAJOR MINOR PATCH <<< "${VERSION}"
PATCH=$((PATCH + 1))
VERSION="${MAJOR}.${MINOR}.${PATCH}"
done
RELEASE_TAG="v${VERSION}"
echo "Selected version: ${VERSION}"
echo "Selected tag: ${RELEASE_TAG}"
# Update manifest version.
node - "${EXTENSION_DIR}/manifest.json" "${VERSION}" <<'NODE'
const fs = require("node:fs");
const file = process.argv[2];
const version = process.argv[3];
const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
manifest.version = version;
fs.writeFileSync(
file,
JSON.stringify(manifest, null, 2) + "\n"
);
console.log(`Manifest updated to ${version}`);
NODE
# Configure Git identity.
git config user.name "Gitea Actions"
git config user.email "actions@celjim.fr"
# Commit the manifest only if it has changed.
if ! git diff --quiet -- "${EXTENSION_DIR}/manifest.json"; then
git add "${EXTENSION_DIR}/manifest.json"
git commit -m "chore(release): ${RELEASE_TAG}"
AUTH="$(printf 'x-access-token:%s' "${GITEA_TOKEN}" | base64 -w 0)"
git -c http.extraheader="AUTHORIZATION: basic ${AUTH}" \
push origin HEAD:main
else
echo "Manifest version is unchanged."
fi
# Create and push the annotated tag.
git tag -a "${RELEASE_TAG}" HEAD \
-m "Release ${RELEASE_TAG}"
AUTH="$(printf 'x-access-token:%s' "${GITEA_TOKEN}" | base64 -w 0)"
git -c http.extraheader="AUTHORIZATION: basic ${AUTH}" \
push origin "refs/tags/${RELEASE_TAG}"
echo "VERSION=${VERSION}" >> "${GITEA_ENV:-$GITHUB_ENV}"
echo "RELEASE_TAG=${RELEASE_TAG}" >> "${GITEA_ENV:-$GITHUB_ENV}"
echo "GITEA_SHA=$(git rev-parse HEAD)" >> "${GITEA_ENV:-$GITHUB_ENV}"
# --------------------------------------------------
# 3. Création de la release Gitea
# --------------------------------------------------
- name: Create Gitea release
id: release
shell: bash
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
set -euo pipefail
API_BASE="${GITEA_SERVER_URL%/}/api/v1"
OWNER="${REPOSITORY%%/*}"
REPO="${REPOSITORY#*/}"
echo "Creating release ${RELEASE_TAG}..."
jq -n \
--arg tag "${RELEASE_TAG}" \
--arg version "${VERSION}" \
'{
tag_name: $tag,
target_commitish: "main",
name: ("SKYNET SSO " + $tag),
body: ("Release automatique de SKYNET SSO version " + $version + "."),
draft: false,
prerelease: false
}' > release-payload.json
curl --fail --silent --show-error \
--request POST \
--header "Authorization: token ${GITEA_TOKEN}" \
--header "Content-Type: application/json" \
--data @release-payload.json \
"${API_BASE}/repos/${OWNER}/${REPO}/releases" \
--output release-response.json
RELEASE_ID="$(jq -r '.id // empty' release-response.json)"
if [[ -z "${RELEASE_ID}" ]]; then
echo "::error::Unable to retrieve the Gitea release ID."
cat release-response.json
exit 1
fi
echo "Release created: ${RELEASE_TAG} (ID: ${RELEASE_ID})"
echo "RELEASE_ID=${RELEASE_ID}" >> "${GITEA_ENV:-$GITHUB_ENV}"
# --------------------------------------------------
# 4. Checkout du commit associé au tag
# --------------------------------------------------
- name: Checkout release commit
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
TAG_VERSION="${RELEASE_TAG#v}" git checkout --detach "refs/tags/${RELEASE_TAG}"
MANIFEST_VERSION="$(node -p \
"require('./${EXTENSION_DIR}/manifest.json').version")"
if [[ "${TAG_VERSION}" != "${MANIFEST_VERSION}" ]]; then echo "Building ${RELEASE_TAG}"
echo "::error::Release tag ${RELEASE_TAG} does not match manifest version ${MANIFEST_VERSION}." echo "Commit: $(git rev-parse HEAD)"
echo "Expected tag: v${MANIFEST_VERSION} (or ${MANIFEST_VERSION})."
exit 1
fi
echo "Release ${RELEASE_TAG} matches manifest version ${MANIFEST_VERSION}." # --------------------------------------------------
# 5. Installation des outils de compilation
# --------------------------------------------------
- name: Install build tools - name: Install build tools
run: | run: |
@@ -90,6 +200,10 @@ jobs:
html-minifier-terser@7.2.0 \ html-minifier-terser@7.2.0 \
web-ext@8.9.0 web-ext@8.9.0
# --------------------------------------------------
# 6. Préparation et minification
# --------------------------------------------------
- name: Prepare and safely minify extension - name: Prepare and safely minify extension
shell: bash shell: bash
run: | run: |
@@ -97,45 +211,55 @@ jobs:
rm -rf dist artifacts rm -rf dist artifacts
mkdir -p dist artifacts mkdir -p dist artifacts
cp -a "${EXTENSION_DIR}/." dist/ cp -a "${EXTENSION_DIR}/." dist/
rm -f dist/README.md rm -f dist/README.md
# Minify JavaScript, CSS and HTML in the build copy only. # JavaScript
# The tracked source files are never rewritten.
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
tmp="${file}.min" tmp="${file}.min"
npx --no-install terser "${file}" \ npx --no-install terser "${file}" \
--compress --mangle \ --compress --mangle \
--output "${tmp}" --output "${tmp}"
mv "${tmp}" "${file}" mv "${tmp}" "${file}"
done < <(find dist -type f -name '*.js' -print0) done < <(find dist -type f -name '*.js' -print0)
# CSS
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
tmp="${file}.min" tmp="${file}.min"
npx --no-install cleancss \ npx --no-install cleancss \
--compatibility ie11 -O2 \ --compatibility ie11 -O2 \
--output "${tmp}" "${file}" --output "${tmp}" "${file}"
mv "${tmp}" "${file}" mv "${tmp}" "${file}"
done < <(find dist -type f -name '*.css' -print0) done < <(find dist -type f -name '*.css' -print0)
# HTML
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
tmp="${file}.min" tmp="${file}.min"
npx --no-install html-minifier-terser \
--collapse-whitespace \ npx --no-install html-minifier-terser \
--remove-comments \ --collapse-whitespace \
--minify-css \ --remove-comments \
--keep-closing-slash \ --minify-css \
"${file}" --output "${tmp}" --keep-closing-slash \
mv "${tmp}" "${file}" "${file}" --output "${tmp}"
mv "${tmp}" "${file}"
done < <(find dist -type f -name '*.html' -print0) done < <(find dist -type f -name '*.html' -print0)
# Validate that the resulting manifest is still valid JSON and # Validate manifest and referenced files.
# that all referenced entry-point files are present.
node <<'NODE' node <<'NODE'
const fs = require("node:fs"); const fs = require("node:fs");
const path = require("node:path"); const path = require("node:path");
const root = path.resolve("dist"); const root = path.resolve("dist");
const manifest = JSON.parse(fs.readFileSync(path.join(root, "manifest.json"), "utf8")); const manifest = JSON.parse(
fs.readFileSync(path.join(root, "manifest.json"), "utf8")
);
const required = [ const required = [
...(manifest.background?.scripts || []), ...(manifest.background?.scripts || []),
@@ -146,29 +270,43 @@ jobs:
...(manifest.options_ui?.page ? [manifest.options_ui.page] : []), ...(manifest.options_ui?.page ? [manifest.options_ui.page] : []),
...(manifest.action?.default_popup ? [manifest.action.default_popup] : []), ...(manifest.action?.default_popup ? [manifest.action.default_popup] : []),
...Object.values(manifest.icons || {}), ...Object.values(manifest.icons || {}),
...(manifest.web_accessible_resources || []).flatMap(r => r.resources || []) ...(manifest.web_accessible_resources || []).flatMap(
r => r.resources || []
)
]; ];
for (const entry of required) { for (const entry of required) {
const target = path.resolve(root, entry); const target = path.resolve(root, entry);
if (!target.startsWith(root + path.sep) || !fs.existsSync(target)) {
if (
!target.startsWith(root + path.sep) ||
!fs.existsSync(target)
) {
throw new Error(`Manifest resource missing or invalid: ${entry}`); throw new Error(`Manifest resource missing or invalid: ${entry}`);
} }
} }
console.log(`Manifest OK; ${required.length} referenced resources verified.`); console.log(
`Manifest OK; ${required.length} referenced resources verified.`
);
NODE NODE
# Firefox extension validation.
npx --no-install web-ext lint --source-dir dist npx --no-install web-ext lint --source-dir dist
# ZIP archive.
ZIP_NAME="SKYNET-SSO-${RELEASE_TAG}.zip" ZIP_NAME="SKYNET-SSO-${RELEASE_TAG}.zip"
( (
cd dist cd dist
zip -qr "../artifacts/${ZIP_NAME}" . zip -qr "../artifacts/${ZIP_NAME}" .
) )
echo "ZIP_NAME=${ZIP_NAME}" >> "${GITEA_ENV:-$GITHUB_ENV}" echo "ZIP_NAME=${ZIP_NAME}" >> "${GITEA_ENV:-$GITHUB_ENV}"
echo "ZIP_PATH=artifacts/${ZIP_NAME}" >> "${GITEA_ENV:-$GITHUB_ENV}"
# --------------------------------------------------
# 7. Signature et soumission AMO
# --------------------------------------------------
- name: Sign and submit to Firefox Add-ons (AMO) - name: Sign and submit to Firefox Add-ons (AMO)
id: amo id: amo
@@ -178,21 +316,10 @@ jobs:
AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }} AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }}
run: | run: |
set -euo pipefail set -euo pipefail
mkdir -p artifacts/amo mkdir -p artifacts/amo
test -n "${AMO_JWT_ISSUER:-}" || { echo "AMO credentials available."
echo "AMO_JWT_ISSUER absent"
exit 1
}
test -n "${AMO_JWT_SECRET:-}" || {
echo "AMO_JWT_SECRET absent"
exit 1
}
echo "Identifiants AMO présents."
echo "Longueur issuer : ${#AMO_JWT_ISSUER}"
echo "Longueur secret : ${#AMO_JWT_SECRET}"
npx --no-install web-ext sign \ npx --no-install web-ext sign \
--source-dir dist \ --source-dir dist \
@@ -200,43 +327,44 @@ jobs:
--channel unlisted \ --channel unlisted \
--api-key "${AMO_JWT_ISSUER}" \ --api-key "${AMO_JWT_ISSUER}" \
--api-secret "${AMO_JWT_SECRET}" \ --api-secret "${AMO_JWT_SECRET}" \
--amo-metadata artifacts/amo-metadata.json \
--no-input --no-input
XPI="$(find artifacts/amo -maxdepth 1 -type f -name '*.xpi' -print -quit)" XPI="$(find artifacts/amo -maxdepth 1 -type f -name '*.xpi' -print -quit)"
if [[ -z "${XPI}" ]]; then if [[ -z "${XPI}" ]]; then
echo "::error::AMO did not return a signed XPI." echo "::error::AMO did not return a signed XPI."
exit 1 exit 1
fi fi
cp "${XPI}" "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi" cp "${XPI}" "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi"
echo "AMO submission/signing completed."
echo "AMO signing completed."
# --------------------------------------------------
# 8. Envoi des fichiers vers la release Gitea
# --------------------------------------------------
- name: Upload release files to Gitea - name: Upload release files to Gitea
shell: bash shell: bash
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }}
AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }}
run: | run: |
set -euo pipefail set -euo pipefail
if [[ -z "${GITEA_TOKEN}" ]]; then
echo "::error::Add the GITEA_TOKEN repository secret (write access required)."
exit 1
fi
API_BASE="${GITEA_SERVER_URL%/}/api/v1" API_BASE="${GITEA_SERVER_URL%/}/api/v1"
OWNER="${REPOSITORY%%/*}" OWNER="${REPOSITORY%%/*}"
REPO="${REPOSITORY#*/}" REPO="${REPOSITORY#*/}"
AUTH_HEADER="Authorization: token ${GITEA_TOKEN}" AUTH_HEADER="Authorization: token ${GITEA_TOKEN}"
upload_asset() { upload_asset() {
local file="$1" local file="$1"
local name local name
name="$(basename "${file}")" name="$(basename "${file}")"
echo "Uploading ${name} to release ${RELEASE_TAG}..." echo "Uploading ${name}..."
curl --fail --silent --show-error \ curl --fail --silent --show-error \
--request POST \ --request POST \
--header "${AUTH_HEADER}" \ --header "${AUTH_HEADER}" \
@@ -244,17 +372,23 @@ jobs:
"${API_BASE}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=${name}" "${API_BASE}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=${name}"
} }
upload_asset "artifacts/${ZIP_NAME}" # ZIP is always uploaded.
upload_asset "artifacts/SKYNET-SSO-${RELEASE_TAG}.zip"
# XPI is uploaded only if AMO signing succeeded.
if [[ -f "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi" ]]; then if [[ -f "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi" ]]; then
upload_asset "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi" upload_asset "artifacts/SKYNET-SSO-${RELEASE_TAG}.xpi"
else else
echo "AMO credentials are not configured; ZIP is attached, AMO publication skipped." echo "AMO credentials unavailable; XPI publication skipped."
fi fi
# --------------------------------------------------
# 9. Conservation des artefacts du workflow
# --------------------------------------------------
- name: Preserve build files in workflow artifacts - name: Preserve build files in workflow artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: SKYNET-SSO-${{ gitea.event.release.tag_name }} name: SKYNET-SSO-${{ gitea.run_number }}
path: artifacts/* path: artifacts/*
if-no-files-found: error if-no-files-found: error
+19 -6
Voir le fichier
@@ -248,18 +248,31 @@
} }
}, true); }, true);
collapse.addEventListener("click", event => {
event.preventDefault();
event.stopPropagation();
bar.dataset.collapsed = "true";
});
function revealBar(event) { function revealBar(event) {
event?.preventDefault(); event?.preventDefault();
event?.stopPropagation(); event?.stopPropagation();
bar.dataset.collapsed = "false"; bar.dataset.collapsed = "false";
} }
// Tout clic dans la barre annule le repli automatique.
// Le clic sur l'encoche reste une action d'ouverture.
bar.addEventListener("click", event => {
if (!tab.contains(event.target)) {
clearAutoCollapse();
}
}, true);
// Repli manuel
collapse.addEventListener("click", event => {
event.preventDefault();
event.stopPropagation();
clearAutoCollapse();
bar.dataset.collapsed = "true";
});
// Déploiement au survol ou au clic de l'encoche
tab.addEventListener("mouseenter", revealBar); tab.addEventListener("mouseenter", revealBar);
tab.addEventListener("click", revealBar); tab.addEventListener("click", revealBar);
+8 -3
Voir le fichier
@@ -1,12 +1,17 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "SKYNET SSO", "name": "SKYNET SSO",
"version": "0.0.1", "version": "0.0.2",
"description": "Affiche l'état de la session SSO Zoraxy et permet une déconnexion.", "description": "Affiche l'état de la session SSO Zoraxy et permet une déconnexion.",
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "skynet-sso@celjim.fr", "id": "skynet-sso@celjim.fr",
"strict_min_version": "128.0" "strict_min_version": "128.0",
"data_collection_permissions": {
"required": [
"none"
]
}
} }
}, },
"permissions": ["storage", "tabs"], "permissions": ["storage", "tabs"],
@@ -29,6 +34,6 @@
"action": { "action": {
"default_title": "SKYNET SSO", "default_title": "SKYNET SSO",
"default_popup": "popup.html", "default_popup": "popup.html",
"default_icon": { "128": "icons/logoSkynet.ico" } "default_icon": { "128": "icons/logoSkynet.png" }
} }
} }
+1 -1
Voir le fichier
@@ -32,7 +32,7 @@
> >
<label for="issuer"> <label for="issuer">
URL du serveur Zoraxy URL du serveur SSO
</label> </label>
<input <input
id="issuer" id="issuer"