commit 395f3c7096881d803f8e1f97992c449b74938fbb Author: Roberto Guagliardo Date: Sun Feb 1 13:02:03 2026 +0000 feat: add WP Plugin Build & Release workflow and update README diff --git a/.gitea/workflows/wp-plugin-release.yml b/.gitea/workflows/wp-plugin-release.yml new file mode 100644 index 0000000..e68c739 --- /dev/null +++ b/.gitea/workflows/wp-plugin-release.yml @@ -0,0 +1,224 @@ +name: WP Plugin Build & Release + +on: + workflow_call: + inputs: + main_file: + type: string + required: true + description: "Pad naar hoofd pluginbestand (met Version header)" + slug: + type: string + required: true + description: "Plugin slug / mapnaam in zip" + build_paths: + type: string + required: false + default: "" + description: "Newline-separated glob paths die de workflow triggeren (alleen informatief in reusable variant)" + release_title: + type: string + required: false + default: "" + release_body: + type: string + required: false + default: "" + + secrets: + RELEASE_TOKEN: + required: true + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Determine plugin version + id: meta + run: | + MAIN_FILE="${{ inputs.main_file }}" + VERSION=$(grep -E "^\s*\*\s*Version:" -m 1 "$MAIN_FILE" | sed -E 's/.*Version:\s*//') + VERSION=$(echo "$VERSION" | tr -d '\r') + if [ -z "$VERSION" ]; then + echo "::error::Kon pluginversie niet bepalen." + exit 1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Genereer manifest.json uit plugin header + run: | + MAIN_FILE="${{ inputs.main_file }}" + python3 - <<'PY' + import json, re, os + main_file = os.environ["MAIN_FILE"] + + with open(main_file, "r", encoding="utf-8") as handle: + content = handle.read() + + header_match = re.search(r"/\*\*(.*?)\*/", content, re.S) + header = header_match.group(1) if header_match else "" + + def read_field(label: str) -> str: + match = re.search(r"^\s*\*\s*" + re.escape(label) + r"\s*:\s*(.+)$", header, re.M) + return match.group(1).strip() if match else "" + + manifest = { + "plugin_name": read_field("Plugin Name"), + "description": read_field("Description"), + "version": read_field("Version"), + "author": read_field("Author"), + "author_url": read_field("Author URI"), + } + + with open("manifest.json", "w", encoding="utf-8") as handle: + json.dump(manifest, handle, ensure_ascii=False, indent=2) + + print("manifest.json aangemaakt/bijgewerkt") + PY + env: + MAIN_FILE: ${{ inputs.main_file }} + + - name: Commit & push manifest.json (optioneel) + run: | + if git diff --quiet -- manifest.json; then + echo "manifest.json ongewijzigd; geen commit nodig." + exit 0 + fi + + # Voor Gitea kan je dit aanpassen naar een eigen bot user + git config user.name "actions-bot" + git config user.email "actions-bot@localhost" + git add manifest.json + git commit -m "chore: update manifest.json" + git push + + - name: Check if tag exists + id: tagcheck + run: | + TAG="v${{ steps.meta.outputs.version }}" + if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "refs/tags/$TAG$"; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Tag bestaat al – workflow afronden + if: steps.tagcheck.outputs.exists == 'true' + run: | + echo "Tag v${{ steps.meta.outputs.version }} bestaat al. Release wordt overgeslagen." + + - name: Build distributie-zip + if: steps.tagcheck.outputs.exists == 'false' + id: package + run: | + if ! command -v zip >/dev/null 2>&1; then + apt-get update -y + apt-get install -y zip + fi + + VERSION="${{ steps.meta.outputs.version }}" + SLUG="${{ inputs.slug }}" + BUILD_ROOT="$RUNNER_TEMP/build" + DEST_DIR="$BUILD_ROOT/$SLUG" + mkdir -p "$DEST_DIR" + + tar -cf - \ + --exclude='.git' \ + --exclude='.gitea' \ + --exclude='.github' \ + --exclude='docker' \ + --exclude='docs' \ + --exclude='dist' \ + --exclude='docker-compose.yml' \ + --exclude='PLAN.md' \ + . | tar -xf - -C "$DEST_DIR" + + mkdir -p dist + ZIP_PATH="dist/${SLUG}-${VERSION}.zip" + (cd "$BUILD_ROOT" && zip -r "$GITHUB_WORKSPACE/$ZIP_PATH" "$SLUG") + + echo "asset_path=$ZIP_PATH" >> "$GITHUB_OUTPUT" + echo "asset_name=${SLUG}-${VERSION}.zip" >> "$GITHUB_OUTPUT" + + - name: Maak Gitea release + if: steps.tagcheck.outputs.exists == 'false' + env: + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} + RELEASE_SERVER_URL: ${{ vars.RELEASE_SERVER_URL }} + RELEASE_REPOSITORY: ${{ vars.RELEASE_REPOSITORY }} + run: | + VERSION="${{ steps.meta.outputs.version }}" + TAG="v$VERSION" + ASSET_PATH="${{ steps.package.outputs.asset_path }}" + ASSET_NAME="${{ steps.package.outputs.asset_name }}" + + if [ -z "$RELEASE_TOKEN" ]; then + echo "::error::RELEASE_TOKEN ontbreekt. Voeg deze secret toe om releases te kunnen maken." + exit 1 + fi + + # Gitea Actions zet meestal GITEA_SERVER_URL / GITEA_REPOSITORY, + # maar je gebruikt vars als override (prima). + SERVER_URL="${RELEASE_SERVER_URL:-${GITEA_SERVER_URL:-${GITHUB_SERVER_URL}}}" + REPO="${RELEASE_REPOSITORY:-${GITEA_REPOSITORY:-${GITHUB_REPOSITORY}}}" + + if [ -z "$SERVER_URL" ] || [ -z "$REPO" ]; then + echo "::error::Kan server of repository niet bepalen. Stel RELEASE_SERVER_URL en RELEASE_REPOSITORY in." + exit 1 + fi + + API_URL="${SERVER_URL%/}/api/v1" + + python3 - <<'PY' + import json, os + + tag = os.environ["TAG"] + title = os.environ.get("RELEASE_TITLE") or f"Release {tag}" + body = os.environ.get("RELEASE_BODY") or f"Automatische release op basis van versie {tag[1:]}" + + payload = { + "tag_name": tag, + "name": title, + "body": body, + "target_commitish": os.environ.get("GITHUB_SHA") or os.environ.get("GITEA_SHA") or "", + } + + with open("release.json", "w", encoding="utf-8") as handle: + json.dump(payload, handle, ensure_ascii=False) + PY + + curl -sS -X POST "$API_URL/repos/$REPO/releases" \ + -H "Authorization: token $RELEASE_TOKEN" \ + -H "Content-Type: application/json" \ + -d @release.json \ + -o release-response.json + + RELEASE_ID=$(python3 - <<'PY' + import json + with open("release-response.json", "r", encoding="utf-8") as handle: + data = json.load(handle) + print(data.get("id","")) + PY + ) + + if [ -z "$RELEASE_ID" ]; then + echo "::error::Kon release-ID niet bepalen. Response: $(cat release-response.json)" + exit 1 + fi + + curl -sS -X POST "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets?name=$ASSET_NAME" \ + -H "Authorization: token $RELEASE_TOKEN" \ + -H "Content-Type: application/zip" \ + --data-binary "@$ASSET_PATH" + env: + TAG: v${{ steps.meta.outputs.version }} + RELEASE_TITLE: ${{ inputs.release_title }} + RELEASE_BODY: ${{ inputs.release_body }} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f748277 --- /dev/null +++ b/readme.md @@ -0,0 +1,178 @@ +# CI Workflows Repository + +Dit repository bevat **centrale CI/CD workflows** voor gebruik met **Gitea Actions + runners**. +Het doel is om build-, release- en deploylogica **één keer te definiëren** en vervolgens **herbruikbaar** te maken voor meerdere repositories. + +De workflows in dit repo worden gebruikt via **reusable workflows (`workflow_call`)**, zodat individuele projecten alleen nog een dunne “wrapper”-workflow nodig hebben. + +--- + +## 📦 Wat zit er in dit repository? + +Momenteel bevat dit repo onder andere: + +- **WP Plugin Build & Release workflow** + - Leest de pluginversie uit de plugin header + - Genereert automatisch `manifest.json` + - Bouwt een distributie-zip + - Maakt (indien nodig) een Gitea release + - Uploadt het zip-bestand als release asset + - Slaat releases over als de tag al bestaat + +De workflows zijn ontworpen om: +- versie-gebaseerd te werken (`vX.Y.Z`) +- veilig herbruikbaar te zijn +- zonder repo-specifieke aannames te functioneren + +--- + +## 🧠 Architectuur + +**Waarom centraal?** +- Geen copy-paste CI meer +- Eén plek om fixes en verbeteringen door te voeren +- Consistente releasestructuur +- Minder onderhoud per project + +**Hoe?** +- Dit repo bevat de *logica* +- Consumer repos bepalen: + - wanneer een workflow draait (`on: push`, `workflow_dispatch`, `paths`) + - welke parameters worden doorgegeven (slug, main file, release notes) + +--- + +## 🔁 Gebruik in andere repositories + +### 1. Voorwaarden +De consumer repo moet: +- Gitea Actions ingeschakeld hebben +- Toegang hebben tot dit repo +- Een `RELEASE_TOKEN` secret bevatten met `repo`-rechten + +Optioneel kunnen repo-variables gebruikt worden: +- `RELEASE_SERVER_URL` +- `RELEASE_REPOSITORY` + +--- + +### 2. Voorbeeld: WordPress plugin release + +In de **consumer repo**: + +`.gitea/workflows/release.yml` + +```yaml +name: Build & Release Plugin + +on: + workflow_dispatch: + inputs: + release_notes: + description: "Optionele release-opmerkingen" + required: false + push: + branches: [ main ] + paths: + - 'plugin-main-file.php' + - 'includes/**' + - 'assets/**' + - 'README.md' + +jobs: + release: + uses: org/ci-workflows/.gitea/workflows/wp-plugin-release.yml@v1 + with: + main_file: plugin-main-file.php + slug: my-plugin-slug + release_body: "${{ inputs.release_notes }}" + secrets: + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} +``` +De volledige build- en releaseflow wordt hiermee centraal uitgevoerd. + +--- + +## 🔧 Beschikbare inputs (WP Plugin workflow) + +| Input | Verplicht | Beschrijving | +|------|----------|-------------| +| `main_file` | ✅ | Pad naar het hoofd pluginbestand met `Version:` header | +| `slug` | ✅ | Plugin slug / mapnaam in de zip | +| `release_title` | ❌ | Titel van de release | +| `release_body` | ❌ | Release notes (bijv. via workflow_dispatch) | + +--- + +## 🔐 Secrets & rechten + +### Vereist +- `RELEASE_TOKEN` + Gitea API token met `repo`-rechten + +### Optioneel (repo variables) +- `RELEASE_SERVER_URL` + Voor self-hosted Gitea (override van server URL) +- `RELEASE_REPOSITORY` + Override voor `owner/repository` + +--- + +## 🏷️ Versiebeheer van workflows + +Gebruik **tags** in dit repository: + +- `v1` → stabiele major versie +- `v1.0.1` → bugfix / non-breaking wijziging +- `v2` → breaking changes + +Consumer repositories **moeten altijd pinnen** op een tag of commit SHA: + +```yaml +uses: org/ci-workflows/.gitea/workflows/wp-plugin-release.yml@v1 +Dit voorkomt onverwachte regressies bij wijzigingen in centrale CI-logica. +``` +--- + +## 🧪 Ontwikkelen & testen van workflows + +Aanpak voor wijzigingen in dit CI-repository: + +1. Maak een feature branch in dit repository +2. Pas de workflow(s) aan +3. Test de wijzigingen via een aparte test-repository +4. Merge de branch naar `main` +5. Tag een nieuwe versie (`vX.Y.Z`) + +**Breaking change?** +→ verhoog altijd de major versie (`v2`, `v3`, …) + +--- + +## 🚫 Wat hoort niet in dit repository? + +Dit repository bevat **uitsluitend generieke CI/CD-logica**. + +Niet opnemen: +- Project- of plugin-specifieke bestandsnamen +- Hardcoded slugs, paden of repository-namen +- Triggers zoals `on: push`, `paths` of branch-namen +- Omgevingsspecifieke aannames of secrets + +Alles wat per project verschilt hoort in de **consumer workflow**. + +--- + +## 📌 Richtlijn + +> Consumer repositories bepalen **wanneer** een workflow draait. +> Dit repository bepaalt **hoe** de workflow wordt uitgevoerd. + +--- + +## 📄 Gebruik & scope + +Intern CI/CD repository voor herbruikbare Gitea Actions workflows. +Bedoeld voor gebruik binnen de organisatie en gekoppelde projecten. + +---