name: Create DokuWiki Plugin ZIP and Changelog on Tag

on:
  push:
    tags:
      - 'v*'

jobs:
  build-release:
    name: Build and Release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up git config
        run: |
          git config --global user.name "GitHub Actions"
          git config --global user.email "actions@github.com"

      - name: Install git-cliff
        run: |
          curl -sSL https://github.com/orhun/git-cliff/releases/download/v1.3.0/git-cliff-1.3.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz
          sudo mv git-cliff /usr/local/bin/

      - name: Generate CHANGELOG.md from commits
        run: git-cliff -o CHANGELOG.md

      - name: Create plugin zip
        run: |
          mkdir -p build
          zip -r build/pagecss.zip \
            action.php \
            plugin.info.txt \
            syntax.php \
            conf/ \
            lang/

          cp CHANGELOG.md build/

      - name: Create GitHub Release and upload assets
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          name: Release ${{ github.ref_name }}
          body_path: build/CHANGELOG.md
          files: |
            build/pagecss.zip
            build/CHANGELOG.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
