From db2c51f9dc7c257d4f906ba89e614174f064ae1f Mon Sep 17 00:00:00 2001 From: Grok Date: Sat, 6 Jun 2026 15:21:02 +0100 Subject: [PATCH] ci: add Gitea Actions workflows (build/CI + release) modeled after gostations and grokkit - build.yml: CI on push/PR with Go 1.24.2, test-short via Makefile, Linux build, verify binary (go mod tidy to ensure clean sums for deps like lipgloss/bubbletea) - release.yml: on v* tags, cross build via make cross (with VERSION/COMMIT/DATE ldflags), prepare tar.gz + checksums (gralculator-*), conditional install scripts, create Gitea release via API (RELEASE_TOKEN), upload assets. Customized release notes for this TUI calculator project. - Very close structure, caching, tidy steps, asset prep, and release creation/upload logic to the reference projects. - Uses our existing Makefile cross target and internal/version ldflags. - No external ci-build.sh needed; leverages Makefile directly for simplicity. --- .gitea/workflows/build.yml | 68 +++++++++++++++++++ .gitea/workflows/release.yml | 123 +++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..aeeab88 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,68 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + name: Test + runs-on: ubuntu-gitea + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.2' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/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 (short) + run: | + go mod tidy + make test-short + # go mod tidy ensures go.sum is complete (fixes "missing go.sum entry" for deps during `go test`) + + build: + name: Build + runs-on: ubuntu-gitea + needs: [test] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.2' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Linux Build + run: | + go mod tidy + make build + # go mod tidy ensures go.sum is fully populated for this Go version before the make build / go build + + - name: Verify binary + run: | + ./build/gralculator -v || true + ls -lh build/gralculator || true diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..1defee7 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,123 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release: + name: Create Release + runs-on: ubuntu-gitea + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.2' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download Go modules + run: go mod download + + - name: Build for multiple platforms + shell: bash + run: | + VERSION=${GITHUB_REF#refs/tags/} + COMMIT=$(git rev-parse --short HEAD) + DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) + go mod tidy + make cross VERSION="$VERSION" COMMIT="$COMMIT" DATE="$DATE" + # go mod tidy ensures go.sum is complete for this Go version in CI (common fix for "missing go.sum entry" during cross builds) + # make cross (with deps) handles the loop + ldflags + + - name: Prepare assets + shell: bash + run: | + VERSION=${GITHUB_REF#refs/tags/} + for bin in build/gralculator-* ; do + if [ ! -f "$bin" ]; then continue; fi + OSARCH=$(basename "$bin" | sed 's/gralculator-//' | sed 's/\.exe$//') + tar czf "build/gralculator-${OSARCH}-${VERSION}.tar.gz" -C build "$(basename "$bin")" + done + sha256sum build/gralculator-*.tar.gz | tee build/checksums.txt + + # Include useful scripts from repo (if present) + [ -f scripts/gralculator-install.sh ] && cp scripts/gralculator-install.sh build/ + [ -f scripts/gralculator-install.ps1 ] && cp scripts/gralculator-install.ps1 build/ + + # Clean raw binaries (we ship the tarballs) + for plat in 'linux/amd64' 'linux/arm64' 'darwin/amd64' 'darwin/arm64' 'windows/amd64'; do + OS=$(echo "$plat" | cut -d/ -f1) + ARCH=$(echo "$plat" | cut -d/ -f2) + BIN="gralculator-${OS}-${ARCH}" + if [ "$OS" = "windows" ]; then BIN="${BIN}.exe"; fi + rm -f "build/${BIN}" + done + + - name: Install dependencies + run: apt update && apt install -y jq + + - name: Create Release & Upload Assets + shell: bash + env: + GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }} + run: | + set -euo pipefail + + VERSION=${GITHUB_REF#refs/tags/} + GITEA_API=https://repos.gmgauthier.com/api/v1 + REPO=${GITHUB_REPOSITORY} + + echo "Creating release for tag ${VERSION} on ${REPO}..." + + curl --fail --silent --show-error -X POST "${GITEA_API}/repos/${REPO}/releases" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{ + \"tag_name\": \"${VERSION}\", + \"name\": \"gralculator ${VERSION}\", + \"target\": \"${GITHUB_SHA}\", + \"draft\": false, + \"body\": \"## Quick Start\n\nDownload the appropriate archive for your platform, extract the gralculator binary, and run it.\n\n\`\`\`bash\n./gralculator\n\`\`\`\n\nFeatures a wide integrated display with base cycling (Tab), MOD support, CERR on non-integer base switches, and a tactile keypad.\n\nPlatform binaries (tar.gz) + checksums.txt are attached. See README.md (when present) and the design docs for details.\" + }" > release.json + + echo "Release creation response:" + cat release.json + + RELEASE_ID=$(jq -r '.id // empty' release.json) + + if [ -z "$RELEASE_ID" ]; then + echo "ERROR: Failed to create release. No release ID returned. Check the response above and your RELEASE_TOKEN secret (must have 'repo' scope and write access)." + exit 1 + fi + + echo "Release created with ID: $RELEASE_ID" + + for asset in build/* ; do + name=$(basename "$asset") + mime="application/octet-stream" + [[ "$name" =~ \.tar\.gz$ ]] && mime="application/gzip" + [[ "$name" =~ \.(txt|sh|ps1)$ ]] && mime="text/plain" + echo "Uploading asset: $name" + curl --fail --silent --show-error -X POST "${GITEA_API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${name}" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: ${mime}" \ + --data-binary "@$asset" + done + + echo "All assets uploaded successfully."