name: Build & Release Plugin on: workflow_dispatch: inputs: release_notes: description: 'Optionele release-opmerkingen' required: false push: branches: - main paths: - 'groq-ai-product-text.php' - 'includes/**' - 'assets/**' - 'README.md' - '.github/workflows/release.yml' 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: | VERSION=$(grep -E "^\s*\*\s*Version:" -m 1 groq-ai-product-text.php | 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: | python3 - <<'PY' import json import re with open('groq-ai-product-text.php', '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 - name: Toon manifest.json run: | echo "manifest.json inhoud:" cat manifest.json - name: Commit & push manifest.json run: | if git diff --quiet -- manifest.json; then echo "manifest.json ongewijzigd; geen commit nodig." exit 0 fi git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 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 "$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: | VERSION="${{ steps.meta.outputs.version }}" SLUG="siti-ai-product-content-generator" BUILD_ROOT="$RUNNER_TEMP/build" DEST_DIR="$BUILD_ROOT/$SLUG" mkdir -p "$DEST_DIR" rsync -a ./ "$DEST_DIR" \ --exclude '.git/' \ --exclude '.github/' \ --exclude 'docker/' \ --exclude 'docs/' \ --exclude 'dist/' \ --exclude 'docker-compose.yml' \ --exclude 'PLAN.md' 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: Stel release-body samen if: steps.tagcheck.outputs.exists == 'false' id: releasebody run: | if [ -n "$RELEASE_NOTES" ]; then echo "text=$RELEASE_NOTES" >> "$GITHUB_OUTPUT" else echo "text=Automatische release op basis van versie ${{ steps.meta.outputs.version }}." >> "$GITHUB_OUTPUT" fi env: RELEASE_NOTES: ${{ github.event.inputs.release_notes }} - name: Maak Gitea tag if: steps.tagcheck.outputs.exists == 'false' env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_SERVER_URL: ${{ vars.GITEA_SERVER_URL }} GITEA_REPOSITORY: ${{ vars.GITEA_REPOSITORY }} run: | VERSION="${{ steps.meta.outputs.version }}" TAG="v$VERSION" if [ -z "$GITEA_TOKEN" ]; then echo "::error::GITEA_TOKEN ontbreekt. Voeg deze secret toe om tags te kunnen pushen." exit 1 fi SERVER_URL="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL}}" REPO="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY}}" if [ -z "$SERVER_URL" ] || [ -z "$REPO" ]; then echo "::error::Kan Gitea server of repository niet bepalen. Stel GITEA_SERVER_URL en GITEA_REPOSITORY in." exit 1 fi HOST="${SERVER_URL#https://}" HOST="${HOST#http://}" AUTH_URL="https://oauth2:${GITEA_TOKEN}@${HOST}/${REPO}.git" git tag -a "$TAG" -m "$TAG" git push "$AUTH_URL" "$TAG" - name: Maak Gitea release if: steps.tagcheck.outputs.exists == 'false' env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_SERVER_URL: ${{ vars.GITEA_SERVER_URL }} GITEA_REPOSITORY: ${{ vars.GITEA_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 "$GITEA_TOKEN" ]; then echo "::error::GITEA_TOKEN ontbreekt. Voeg deze secret toe om releases te kunnen maken." exit 1 fi SERVER_URL="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL}}" REPO="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY}}" if [ -z "$SERVER_URL" ] || [ -z "$REPO" ]; then echo "::error::Kan Gitea server of repository niet bepalen. Stel GITEA_SERVER_URL en GITEA_REPOSITORY in." exit 1 fi API_URL="${SERVER_URL%/}/api/v1" BODY="${{ steps.releasebody.outputs.text }}" export TAG export BODY python3 - <<'PY' import json import os payload = { "tag_name": os.environ["TAG"], "name": f"Siti AI Product Teksten {os.environ['TAG']}", "body": os.environ.get("BODY", ""), "target_commitish": os.environ.get("GITHUB_SHA") or os.environ.get("GITEA_SHA", ""), } with open("release.json", "w", encoding="utf-8") as handle: json.dump(payload, handle, ensure_ascii=False) PY RESPONSE=$(curl -sS -X POST "$API_URL/repos/$REPO/releases" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d @release.json) RELEASE_ID=$(python3 - <<'PY' import json import sys data = json.loads(sys.stdin.read()) print(data.get('id', '')) PY <<< "$RESPONSE") if [ -z "$RELEASE_ID" ]; then echo "::error::Kon release-ID niet bepalen. Response: $RESPONSE" exit 1 fi curl -sS -X POST "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets?name=$ASSET_NAME" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/zip" \ --data-binary "@$ASSET_PATH"