name: build on: push: branches: ["**"] tags: ["v*"] pull_request: permissions: contents: write jobs: build: runs-on: ubuntu-latest steps: - uses: https://gitea.com/actions/checkout@v4 - uses: https://gitea.com/actions/setup-go@v5 with: go-version: "1.22" - name: vet & test run: | go vet ./... go test ./... - name: install nfpm run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest - name: build packages run: | export PATH="$PATH:$(go env GOPATH)/bin" ./build.sh # upload-artifact@v4 needs the newer Actions Results API, which Gitea # doesn't implement yet ("GHESNotSupportedError") - v3 works. - uses: https://gitea.com/actions/upload-artifact@v3 with: name: nasmon-packages path: | dist/*.deb dist/*.rpm - name: publish release if: startsWith(github.ref, 'refs/tags/') env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} API: ${{ github.api_url }}/repos/${{ github.repository }} run: | set -euo pipefail tag="${GITHUB_REF#refs/tags/}" release_id=$(curl -sf -X POST "$API/releases" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \ | grep -oP '"id":\s*\K[0-9]+' | head -1) || \ release_id=$(curl -sf "$API/releases/tags/$tag" \ -H "Authorization: token $GITEA_TOKEN" \ | grep -oP '"id":\s*\K[0-9]+' | head -1) if [ -z "$release_id" ]; then echo "could not create or find a release for tag $tag" >&2 exit 1 fi for f in dist/*.deb dist/*.rpm; do [ -e "$f" ] || continue curl -sf -X POST "$API/releases/$release_id/assets?name=$(basename "$f")" \ -H "Authorization: token $GITEA_TOKEN" \ -F "attachment=@${f}" done