From 87a62c0d6cc4eb14ae8d2917acf30c6e7484b395 Mon Sep 17 00:00:00 2001 From: SGC Date: Sat, 4 Apr 2026 16:28:19 +0200 Subject: [PATCH] =?UTF-8?q?ci:=20add=20Gitea=20Actions=20=E2=80=94=20CI=20?= =?UTF-8?q?on=20push/PR,=20release=20on=20version=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .gitea/workflows/ci.yml: build + test on every push and PR - .gitea/workflows/release.yml: cross-platform release binaries on v*.*.* tags - Builds amcs-server and amcs-cli for linux/amd64, linux/arm64, darwin/amd64, darwin/arm64, windows/amd64 - Embeds version, commit, and build date via ldflags - Creates Gitea Release with all binaries and checksums.txt attached --- .gitea/workflows/ci.yml | 41 ++++++++++++++ .gitea/workflows/release.yml | 102 +++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..09d1db7 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + push: + branches: ['**'] + tags-ignore: ['v*'] + pull_request: + branches: ['**'] + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.26' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test ./... + + - name: Build amcs-server + run: go build -o /dev/null ./cmd/amcs-server + + - name: Build amcs-cli + run: go build -o /dev/null ./cmd/amcs-cli diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..5a8ffca --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,102 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +env: + GITEA_SERVER: https://git.warky.dev + GITEA_REPO: wdevs/amcs + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.26' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Set build vars + id: vars + run: | + echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT + echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT + + - name: Build release binaries + run: | + VERSION="${{ steps.vars.outputs.VERSION }}" + COMMIT="${{ steps.vars.outputs.COMMIT }}" + BUILD_DATE="${{ steps.vars.outputs.BUILD_DATE }}" + LDFLAGS="-s -w -X git.warky.dev/wdevs/amcs/internal/buildinfo.Version=${VERSION} -X git.warky.dev/wdevs/amcs/internal/buildinfo.TagName=${VERSION} -X git.warky.dev/wdevs/amcs/internal/buildinfo.Commit=${COMMIT} -X git.warky.dev/wdevs/amcs/internal/buildinfo.BuildDate=${BUILD_DATE}" + mkdir -p dist + for BINARY in amcs-server amcs-cli; do + CMD="./cmd/${BINARY}" + for PLATFORM in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64; do + OS="${PLATFORM%/*}" + ARCH="${PLATFORM#*/}" + EXT="" + [ "$OS" = "windows" ] && EXT=".exe" + OUTPUT="dist/${BINARY}-${OS}-${ARCH}${EXT}" + echo "Building ${OUTPUT}..." + GOOS=$OS GOARCH=$ARCH go build -ldflags "${LDFLAGS}" -o "${OUTPUT}" "${CMD}" + done + done + cd dist && sha256sum * > checksums.txt && cd .. + + - name: Create Gitea Release + id: create_release + run: | + VERSION="${{ steps.vars.outputs.VERSION }}" + BODY=$(python3 <<'PY' +import json, subprocess, os +version = os.environ['VERSION'] +commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], text=True).strip() +body = f"## {version}\n\nBuilt from commit {commit}.\n\nSee `checksums.txt` to verify downloads." +print(json.dumps({ + 'tag_name': version, + 'name': version, + 'body': body, + 'draft': False, + 'prerelease': False, +})) +PY +) + RESPONSE=$(curl -fsS -X POST "${{ env.GITEA_SERVER }}/api/v1/repos/${{ env.GITEA_REPO }}/releases" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "$BODY") + RELEASE_ID=$(printf '%s' "$RESPONSE" | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])') + echo "RELEASE_ID=${RELEASE_ID}" >> $GITHUB_OUTPUT + + - name: Upload release assets + run: | + RELEASE_ID="${{ steps.create_release.outputs.RELEASE_ID }}" + for f in dist/*; do + name=$(basename "$f") + echo "Uploading ${name}..." + curl -fsS -X POST \ + "${{ env.GITEA_SERVER }}/api/v1/repos/${{ env.GITEA_REPO }}/releases/${RELEASE_ID}/assets?name=${name}" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @"${f}" + done