feat(ci): publish heartbeat as release
All checks were successful
Build heartbeat / build (push) Successful in 8s
All checks were successful
Build heartbeat / build (push) Successful in 8s
This commit is contained in:
@@ -28,9 +28,41 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o heartbeat ./cmd/heartbeat
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o heartbeat ./cmd/heartbeat
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Publish release
|
||||||
uses: actions/upload-artifact@v3
|
env:
|
||||||
with:
|
GITEA_TOKEN: ${{ gitea.token }}
|
||||||
name: heartbeat-linux-amd64
|
SERVER_URL: ${{ gitea.server_url }}
|
||||||
path: heartbeat
|
REPO: ${{ gitea.repository }}
|
||||||
retention-days: 365
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user