name: Build & Release

on:
  push:
    tags:
      - 'v*'

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        goos: [linux, windows]
        goarch: [amd64, arm]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22.x'

      - name: Build binary
        run: |
          GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o dist/app-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} main.go

      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: app-${{ matrix.goos }}-${{ matrix.goarch }}
          path: dist/app-*

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v3
        with:
          path: ./dist

      - name: Create Release & Attach Files
        uses: rosven9856/gitea_creating_release_action@master
        with:
          gitea_schema: 'https'
          gitea_host: 'git.ztsw.de'
          gitea_organization: 'pedan'
          gitea_repo: 'go-fileserver'
          access_token: ${{ secrets.GITEA_TOKEN }}
          release_body: 'Auto-build release'
          release_draft: 'false'
          release_name: ${{ github.ref_name }}
          release_prerelease: 'false'
          release_tag_name: ${{ github.ref_name }}
          release_target_commitish: ${{ github.sha }}
          # Optional: attach all built binaries
        env:
          ASSETS_PATH: ./dist/app-*
