All checks were successful
main.go's version var now defaults to "dev" for local builds and is overridden at build time via -ldflags "-X main.version=...". The release workflow computes VERSION with `git describe --tags --always --dirty` (fetch-depth: 0 so tags are available) and injects it into the Go build inside the container.
75 lines
2.2 KiB
YAML
75 lines
2.2 KiB
YAML
name: Release Binaries
|
|
|
|
on:
|
|
release:
|
|
types: [published]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
platform: linux/amd64
|
|
image: golang:1.24-alpine
|
|
runner: linux-amd64
|
|
upx_install: "apk add --no-cache upx"
|
|
- arch: arm64
|
|
platform: linux/arm64
|
|
image: golang:1.24-alpine
|
|
runner: linux-arm64
|
|
upx_install: "apk add --no-cache upx zstd-static"
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Build (${{ matrix.arch }})
|
|
run: |
|
|
set -o pipefail
|
|
|
|
VERSION="$(git describe --tags --always --dirty)"
|
|
echo "Version: $VERSION"
|
|
|
|
# Crea il container senza avviarlo
|
|
CID=$(docker create \
|
|
--platform ${{ matrix.platform }} \
|
|
-w /src \
|
|
${{ matrix.image }} \
|
|
sleep infinity)
|
|
|
|
# Copia i sorgenti dentro con docker cp (funziona anche in DinD)
|
|
docker cp "${{ github.workspace }}/." "$CID:/src"
|
|
|
|
# Avvia ed esegui la build
|
|
docker start "$CID"
|
|
docker exec "$CID" sh -c "
|
|
${{ matrix.upx_install }}
|
|
export CGO_ENABLED=0
|
|
go build -trimpath -ldflags='-s -w -X main.version=$VERSION' -o /src/dist/todotxt2remind .
|
|
upx /src/dist/todotxt2remind
|
|
" 2>&1 | cat
|
|
|
|
# Copia il binario fuori
|
|
docker cp "$CID:/src/dist/todotxt2remind" \
|
|
"${{ github.workspace }}/todotxt2remind-linux-${{ matrix.arch }}"
|
|
|
|
docker rm -f "$CID"
|
|
|
|
- name: Carica artefatto sulla release
|
|
env:
|
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
RELEASE_ID: ${{ github.event.release.id }}
|
|
run: |
|
|
FILENAME="todotxt2remind-linux-${{ matrix.arch }}"
|
|
curl -s -X POST \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${FILENAME}" \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@${FILENAME}"
|