name: Build and Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  build-and-release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup Zig
        uses: mlugg/setup-zig@v1
        with:
          version: 0.13.0

      - name: Build release artifacts
        run: |
          zig build release

      - name: Create zip files for release artifacts
        run: |
          mkdir -p release/zips
          for file in zig-out/release/*; do
            if [ -f "$file" ]; then
              zip -j "zig-out/release/zips/${file##*/}.zip" "$file"
            fi
          done

      - name: Upload release artifacts
        uses: ncipollo/release-action@v1
        with:
          name: "Release ${{ github.ref_name }}"
          body: "Base release. Most ZipponQL features are here but stuffs around is missing."
          artifacts: zig-out/release/zips/*.zip
