when:
  - event: tag
    ref: "refs/tags/bugseti-v*"
  - event: push
    branch: main
    path: "cmd/bugseti/**"

steps:
  - name: frontend
    image: node:22-bookworm
    commands:
      - cd cmd/bugseti/frontend
      - npm ci --prefer-offline
      - npm run build

  - name: build-linux
    image: golang:1.25-bookworm
    environment:
      CGO_ENABLED: "1"
      GOOS: linux
      GOARCH: amd64
    commands:
      - apt-get update -qq && apt-get install -y -qq libgtk-3-dev libwebkit2gtk-4.1-dev > /dev/null 2>&1
      - cd cmd/bugseti
      - go build -tags production -trimpath -buildvcs=false -ldflags="-w -s" -o ../../bin/bugseti
    depends_on: [frontend]

  - name: package
    image: alpine:3.21
    commands:
      - cd bin
      - tar czf bugseti-linux-amd64.tar.gz bugseti
      - sha256sum bugseti-linux-amd64.tar.gz > bugseti-linux-amd64.tar.gz.sha256
      - echo "=== Package ==="
      - ls -lh bugseti-linux-amd64.*
      - cat bugseti-linux-amd64.tar.gz.sha256
    depends_on: [build-linux]

  - name: release
    image: plugins/gitea-release
    settings:
      api_key:
        from_secret: forgejo_token
      base_url: https://forge.lthn.io
      files:
        - bin/bugseti-linux-amd64.tar.gz
        - bin/bugseti-linux-amd64.tar.gz.sha256
      title: ${CI_COMMIT_TAG}
      note: "BugSETI ${CI_COMMIT_TAG} — Linux amd64 build"
    when:
      - event: tag
    depends_on: [package]
