diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 768881c..d4982ee 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -1,95 +1,166 @@ -name: Build WordPress Plugin (XML-driven) + +name: Build and Release WordPress Plugin on: push: branches: - main + workflow_dispatch: + +permissions: + contents: write jobs: build-release: runs-on: ubuntu-latest steps: + # 1. Checkout - name: Checkout uses: actions/checkout@v4 - - name: Install XML tools and zip + # 2. Install dependencies + - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y libxml2-utils zip + sudo apt-get install -y \ + php-cli \ + zip \ + unzip \ + rsync \ + curl - # ------------------------------------------------------------ - # 1. Extract metadata from plugin.xml - # ------------------------------------------------------------ - - name: Extract metadata from plugin.xml - id: meta + # 3. Extract plugin metadata + - name: Extract plugin metadata run: | - if [ ! -f plugin.xml ]; then - echo "❌ plugin.xml not found!" >&2 - exit 1 - fi + set -euo pipefail - NAME=$(xmllint --xpath "string(//name)" plugin.xml) - VERSION=v$(xmllint --xpath "string(//version)" plugin.xml) + MAIN_FILE="advanced-seo-keywords.php" + SLUG="advanced-seo-keywords" + + test -f "$MAIN_FILE" + + NAME=$(sed -nE \ + 's/^[[:space:]]*\*[[:space:]]*Plugin Name:[[:space:]]*(.*)/\1/p' \ + "$MAIN_FILE" | head -n1) + + VERSION=$(sed -nE \ + 's/^[[:space:]]*\*[[:space:]]*Version:[[:space:]]*([^[:space:]]+).*/\1/p' \ + "$MAIN_FILE" | head -n1) if [ -z "$NAME" ] || [ -z "$VERSION" ]; then - echo "❌ Could not extract or from plugin.xml" >&2 + echo "Plugin metadata missing" exit 1 fi - # Sanitize the name to a safe slug (lowercase, replace non-alnum with '-') - SLUG=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//') + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version: $VERSION" + exit 1 + fi - echo "PLUGIN_NAME=$NAME" >> $GITHUB_ENV - echo "SLUG=$SLUG" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV + echo "PLUGIN_NAME=$NAME" >> "$GITHUB_ENV" + echo "VERSION=v$VERSION" >> "$GITHUB_ENV" + echo "SLUG=$SLUG" >> "$GITHUB_ENV" + echo "FILENAME=$SLUG-v$VERSION.zip" >> "$GITHUB_ENV" - echo "✅ Plugin: $NAME, Slug: $SLUG, Version: $VERSION" + echo "Plugin: $NAME" + echo "Version: $VERSION" + echo "Slug: $SLUG" - # ------------------------------------------------------------ - # 2. Prepare package (copy everything EXCEPT plugin.xml, .git, .github) - # ------------------------------------------------------------ + # 4. Validate PHP + - name: Validate PHP + run: | + set -euo pipefail + php -l advanced-seo-keywords.php + + # 5. Prepare package - name: Prepare package run: | - mkdir -p build/"$SLUG" - # Copy everything except .git, .github, and plugin.xml - find . -maxdepth 1 -not -name "." -not -name ".git" -not -name ".github" -not -name "plugin.xml" -exec cp -r {} build/"$SLUG"/ \; + set -euo pipefail - # ------------------------------------------------------------ - # 3. Build the zip - # ------------------------------------------------------------ - - name: Build plugin zip + rm -rf build + mkdir -p "build/$SLUG" + + rsync -a \ + --exclude='/.git/' \ + --exclude='/.gitea/' \ + --exclude='/.github/' \ + --exclude='/build/' \ + --exclude='/plugin.xml' \ + --exclude='/node_modules/' \ + --exclude='/tests/' \ + ./ "build/$SLUG/" + + test -f "build/$SLUG/advanced-seo-keywords.php" + + # 6. Build ZIP + - name: Build ZIP run: | + set -euo pipefail + cd build - zip -r "../$FILENAME" "$SLUG" + zip -qr "../$FILENAME" "$SLUG" cd .. - # ------------------------------------------------------------ - # 4. Install tea CLI - # ------------------------------------------------------------ - - name: Install tea CLI - run: | - curl -L https://dl.gitea.io/tea/main/tea-main-linux-amd64 -o tea - chmod +x tea - sudo mv tea /usr/local/bin/ + test -s "$FILENAME" + unzip -t "$FILENAME" - # ------------------------------------------------------------ - # 5. Configure tea - # ------------------------------------------------------------ - - name: Configure tea + # 7. Verify package + - name: Verify package run: | + set -euo pipefail + + unzip -l "$FILENAME" + + unzip -p "$FILENAME" \ + "$SLUG/advanced-seo-keywords.php" \ + | grep -E 'Plugin Name:|Version:' + + # 8. Install Gitea CLI + - name: Install tea + run: | + set -euo pipefail + + curl -fL \ + https://dl.gitea.io/tea/main/tea-main-linux-amd64 \ + -o tea + + chmod +x tea + sudo install tea /usr/local/bin/tea + + tea --version + + # 9. Configure Gitea authentication + - name: Configure Gitea + env: + GITEA_URL: ${{ vars.SERVER_URL }} + GITEA_TOKEN: ${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }} + run: | + set -euo pipefail + + test -n "$GITEA_URL" + test -n "$GITEA_TOKEN" + tea login add \ --name gitea \ - --url "${{ vars.SERVER_URL }}" \ - --token "${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}" + --url "$GITEA_URL" \ + --token "$GITEA_TOKEN" - # ------------------------------------------------------------ - # 6. Create (or force‑update) release - # ------------------------------------------------------------ - - name: Create release + # 10. Create release and upload ZIP + - name: Publish release run: | + set -euo pipefail + tea release create "$VERSION" \ - --title "${PLUGIN_NAME}_${VERSION}" \ - --asset "${FILENAME}" \ - --force \ No newline at end of file + --title "$PLUGIN_NAME $VERSION" \ + --note "Automated WordPress plugin release $VERSION" \ + --asset "$FILENAME" \ + --force + + # 11. Report + - name: Release summary + run: | + echo "Release successfully submitted." + echo "Version: $VERSION" + echo "Asset: $FILENAME" + echo "Repository: $GITHUB_REPOSITORY" diff --git a/plugin.xml b/plugin.xml index 2f27a46..b3aac5a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,4 +1,6 @@ + - Advanced SEO Meta + AI FAQ Schema - 3.0.0 - \ No newline at end of file + Advanced SEO Meta + AI FAQ Schema + 4.1.0 + advanced-seo-keywords +