Files
zhanlu_proxy/.gitea/workflows/build.yml
T
root dd5c560b64
build / build (push) Successful in 1m52s
Build Windows release binaries
2026-08-14 15:48:52 +08:00

96 lines
3.5 KiB
YAML

name: build
on:
push:
branches:
- "**"
tags:
- "v*"
jobs:
build:
runs-on: debian-arm64
steps:
- name: Install toolchain (git, curl, tar, go)
run: |
set -e
export DEBIAN_FRONTEND=noninteractive
if ! command -v git >/dev/null || ! command -v curl >/dev/null || ! command -v tar >/dev/null; then
apt-get update
apt-get install -y --no-install-recommends git curl ca-certificates tar
fi
GO_VERSION=1.22.12
case "$(uname -m)" in
x86_64) HOST_ARCH=amd64 ;;
aarch64) HOST_ARCH=arm64 ;;
*) echo "unsupported host arch: $(uname -m)" >&2; exit 1 ;;
esac
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-${HOST_ARCH}.tar.gz" -o /tmp/go.tar.gz
rm -rf /usr/local/go
tar -C /usr/local -xzf /tmp/go.tar.gz
/usr/local/go/bin/go version
- name: Clone repository
run: |
set -e
git init -q .
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" 2>/dev/null || \
git remote set-url origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git -c http.extraHeader="Authorization: basic $(printf 'x-access-token:%s' "${GITHUB_TOKEN}" | base64 -w0)" \
fetch --depth 1 origin "${GITHUB_SHA}"
git checkout -q FETCH_HEAD
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build binaries
run: |
set -e
export PATH="/usr/local/go/bin:${PATH}"
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="${GITHUB_REF_NAME}-$(echo "${GITHUB_SHA}" | cut -c1-7)"
fi
echo "version: ${VERSION}"
LDFLAGS="-s -w"
for arch in amd64 arm64; do
echo "building linux/${arch}"
CGO_ENABLED=0 GOOS=linux GOARCH="${arch}" \
go build -trimpath -ldflags "${LDFLAGS}" \
-o "zhanlu-proxy-linux-${arch}" ./cmd/zhanlu-proxy
echo "building windows/${arch}"
CGO_ENABLED=0 GOOS=windows GOARCH="${arch}" \
go build -trimpath -ldflags "${LDFLAGS}" \
-o "zhanlu-proxy-windows-${arch}.exe" ./cmd/zhanlu-proxy
done
ls -lh zhanlu-proxy-linux-* zhanlu-proxy-windows-*.exe
- name: Publish release assets
if: startsWith(github.ref, 'refs/tags/v')
run: |
set -e
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
TAG="${GITHUB_REF_NAME}"
AUTH="Authorization: token ${GITHUB_TOKEN}"
RELEASE_ID=$(curl -fsSL -H "${AUTH}" "${API}/releases/tags/${TAG}" | \
grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2 || true)
if [ -z "${RELEASE_ID}" ]; then
RELEASE_ID=$(curl -fsSL -X POST -H "${AUTH}" -H "Content-Type: application/json" \
"${API}/releases" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\"}" | \
grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
fi
echo "release id: ${RELEASE_ID}"
for arch in amd64 arm64; do
for f in "zhanlu-proxy-linux-${arch}" "zhanlu-proxy-windows-${arch}.exe"; do
curl -fsSL -X POST -H "${AUTH}" \
-F "attachment=@${f};filename=${f}" \
"${API}/releases/${RELEASE_ID}/assets?name=${f}"
done
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}