Add automated cross-platform builds
Some checks failed
Build / Test and build (push) Failing after 12m31s

This commit is contained in:
2026-08-14 13:55:30 +08:00
parent 606fe362f0
commit f23f1a4e5a

View File

@@ -0,0 +1,86 @@
name: Build
on:
push:
branches:
- "**"
tags:
- "v*"
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: Test and build
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Test
run: go test -race ./...
- name: Vet
run: go vet ./...
- name: Build release archives
shell: bash
env:
BUILD_REF: ${{ github.ref }}
BUILD_REF_NAME: ${{ github.ref_name }}
BUILD_SHA: ${{ github.sha }}
run: |
set -euo pipefail
package_version="snapshot-${BUILD_SHA:0:8}"
version_flags=""
if [[ "$BUILD_REF" == refs/tags/v* ]]; then
package_version="${BUILD_REF_NAME//\//-}"
version_flags="-X main.version=$BUILD_REF_NAME"
fi
mkdir -p dist
for target in \
linux/amd64 linux/arm64 \
darwin/amd64 darwin/arm64 \
windows/amd64 windows/arm64
do
target_os="${target%/*}"
target_arch="${target#*/}"
archive="bdrclone-${package_version}-${target_os}-${target_arch}"
executable="bdrclone"
if [[ "$target_os" == "windows" ]]; then
executable="bdrclone.exe"
fi
package_dir="dist/$archive"
mkdir -p "$package_dir"
CGO_ENABLED=0 GOOS="$target_os" GOARCH="$target_arch" \
go build -trimpath -ldflags "-s -w $version_flags" \
-o "$package_dir/$executable" ./cmd/bdrclone
cp README.md "$package_dir/"
tar -C dist -czf "dist/$archive.tar.gz" "$archive"
rm -rf "$package_dir"
done
cd dist
sha256sum ./*.tar.gz > SHA256SUMS
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: bdrclone-build-${{ github.run_number }}
path: |
dist/*.tar.gz
dist/SHA256SUMS
if-no-files-found: error
retention-days: 30