ci: add multi-platform release build via Gitea Actions
Builds tea for linux/amd64, linux/arm64, darwin/amd64, darwin/arm64 and windows/amd64 on tag push and publishes them as a Gitea release.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
releases: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: build
|
||||
run: |
|
||||
set -e
|
||||
VERSION="${GITHUB_REF_NAME#v}"
|
||||
SDK="$(go list -f '{{.Version}}' -m gitea.dev/sdk)"
|
||||
mkdir -p dist
|
||||
for target in "linux amd64" "linux arm64" "darwin amd64" "darwin arm64" "windows amd64"; do
|
||||
GOOS="${target% *}"
|
||||
GOARCH="${target#* }"
|
||||
EXT=""
|
||||
if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi
|
||||
GOOS="$GOOS" GOARCH="$GOARCH" CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags "-X 'gitea.dev/tea/modules/version.Version=${VERSION}' -X 'gitea.dev/tea/modules/version.SDK=${SDK}' -s -w" \
|
||||
-o "dist/tea-${GOOS}-${GOARCH}${EXT}" .
|
||||
done
|
||||
cd dist
|
||||
for f in tea-*; do
|
||||
sha256sum "$f" > "$f.sha256"
|
||||
done
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: tea-binaries
|
||||
path: dist/*
|
||||
if-no-files-found: error
|
||||
- name: create release + upload assets
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -e
|
||||
TAG="${GITHUB_REF_NAME}"
|
||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
RESPONSE="$(curl -sf -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${API}/releases" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\"}")"
|
||||
RELEASE_ID="$(printf '%s' "$RESPONSE" | python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])')"
|
||||
for f in dist/tea-*; do
|
||||
curl -sf -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-F "attachment=@${f}" \
|
||||
"${API}/releases/${RELEASE_ID}/assets" >/dev/null
|
||||
done
|
||||
Reference in New Issue
Block a user