- runner 镜像缺少 node,JS 类 action(checkout/setup-go/upload-artifact)无法运行 - 改为 shell 步骤:apt 装 git/curl/tar,手动下载 Go 工具链 - 用 git 直接 clone 当前 commit,交叉编译 amd64/arm64 - 打 v* 标签时通过 Gitea API(curl)创建 Release 并上传二进制
This commit is contained in:
+63
-35
@@ -10,47 +10,75 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: debian
|
runs-on: debian
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- goarch: amd64
|
|
||||||
output: docker-compose-backup-linux-amd64
|
|
||||||
- goarch: arm64
|
|
||||||
output: docker-compose-backup-linux-arm64
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Install toolchain (git, curl, tar, go)
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: "1.26"
|
|
||||||
|
|
||||||
- name: Build ${{ matrix.output }}
|
|
||||||
env:
|
|
||||||
CGO_ENABLED: "0"
|
|
||||||
GOOS: linux
|
|
||||||
GOARCH: ${{ matrix.goarch }}
|
|
||||||
run: |
|
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.26.0
|
||||||
|
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.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
|
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
|
||||||
VERSION="${GITHUB_REF_NAME}"
|
VERSION="${GITHUB_REF_NAME}"
|
||||||
else
|
else
|
||||||
VERSION="${GITHUB_REF_NAME}-${GITHUB_SHA::7}"
|
VERSION="${GITHUB_REF_NAME}-$(echo "${GITHUB_SHA}" | cut -c1-7)"
|
||||||
fi
|
fi
|
||||||
go build -trimpath \
|
LDFLAGS="-s -w -X git.misaka.ren/M1saka/docker_backup/cmd/backup.Version=${VERSION}"
|
||||||
-ldflags "-s -w -X git.misaka.ren/M1saka/docker_backup/cmd/backup.Version=${VERSION}" \
|
for arch in amd64 arm64; do
|
||||||
-o "${{ matrix.output }}" .
|
echo "building linux/${arch}"
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH="${arch}" \
|
||||||
|
go build -trimpath -ldflags "${LDFLAGS}" \
|
||||||
|
-o "docker-compose-backup-linux-${arch}" .
|
||||||
|
done
|
||||||
|
ls -lh docker-compose-backup-linux-*
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Publish release assets
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.output }}
|
|
||||||
path: ${{ matrix.output }}
|
|
||||||
|
|
||||||
- name: Attach to release
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
uses: akkuman/gitea-release-action@v1
|
run: |
|
||||||
with:
|
set -e
|
||||||
files: ${{ matrix.output }}
|
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
AUTH="Authorization: token ${GITHUB_TOKEN}"
|
||||||
|
|
||||||
|
# Find the release for this tag, or create it.
|
||||||
|
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
|
||||||
|
f="docker-compose-backup-linux-${arch}"
|
||||||
|
curl -fsSL -X POST -H "${AUTH}" \
|
||||||
|
-F "attachment=@${f};filename=${f}" \
|
||||||
|
"${API}/releases/${RELEASE_ID}/assets"
|
||||||
|
done
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: "--experimental-fetch"
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
Reference in New Issue
Block a user