name: Build heartbeat on: push: branches: [main] paths: - '**/*.go' - 'go.mod' - 'go.sum' - '.gitea/workflows/build.yml' workflow_dispatch: jobs: build: runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.22' cache: true - name: Build binary run: | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o heartbeat ./cmd/heartbeat - name: Publish release env: GITEA_TOKEN: ${{ gitea.token }} SERVER_URL: ${{ gitea.server_url }} REPO: ${{ gitea.repository }} SHA: ${{ gitea.sha }} run: | set -e TAG="build-${SHA::8}" # Delete existing release + tag with this name if present (idempotent re-runs) EXISTING=$(curl -sf \ -H "Authorization: token $GITEA_TOKEN" \ "$SERVER_URL/api/v1/repos/$REPO/releases/tags/$TAG" || true) if [ -n "$EXISTING" ]; then EXISTING_ID=$(echo "$EXISTING" | jq -r '.id') curl -sf -X DELETE \ -H "Authorization: token $GITEA_TOKEN" \ "$SERVER_URL/api/v1/repos/$REPO/releases/$EXISTING_ID" || true curl -sf -X DELETE \ -H "Authorization: token $GITEA_TOKEN" \ "$SERVER_URL/api/v1/repos/$REPO/tags/$TAG" || true fi # Create a pre-release tagged with the short commit SHA RELEASE=$(curl -sf -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ "$SERVER_URL/api/v1/repos/$REPO/releases" \ -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"prerelease\":true,\"draft\":false}") RELEASE_ID=$(echo "$RELEASE" | jq -r '.id') # Upload binary as release asset curl -sf -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/octet-stream" \ "$SERVER_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=heartbeat" \ --data-binary @heartbeat