name: build-plugin-zip

on:
  release:
    types: [published]

permissions:
  contents: write

jobs:
  zip:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Build zip module
        run: |
          set -euo pipefail

          PLUGIN="ovesio-ecommerce-for-woocommerce"
          BUILD_DIR="$(mktemp -d)"
          mkdir -p "${BUILD_DIR}/${PLUGIN}"

          rsync -a ./ "${BUILD_DIR}/${PLUGIN}/" \
            --exclude '.git' \
            --exclude '.git/' \
            --exclude '.github' \
            --exclude '.github/'

          (cd "${BUILD_DIR}" && zip -r "${GITHUB_WORKSPACE}/ovesio-ecommerce-for-woocommerce.zip" "${PLUGIN}")

      - name: Upload asset
        uses: softprops/action-gh-release@v1
        with:
          files: ovesio-ecommerce-for-woocommerce.zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
