gostations/.gitea/workflows/release.yml
Greg Gauthier 1d2dfc1c8d
Some checks failed
gobuild / build (push) Failing after 7s
fix(workflows): use dynamic ${REPO} variable in release body URLs
Replace hardcoded gmgauthier/gostations path with ${REPO} variable so release install instructions work correctly regardless of repository owner or name.
2026-06-05 23:43:37 +01:00

97 lines
4.0 KiB
YAML

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'
- name: Build for multiple platforms
run: |
VERSION=${GITHUB_REF#refs/tags/}
COMMIT=$(git rev-parse --short HEAD)
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
mkdir -p build
for plat in 'linux/amd64' 'linux/arm64' 'darwin/amd64' 'darwin/arm64' 'windows/amd64'; do
IFS='/' read -r OS ARCH <<< "$plat"
BIN="gostations-${OS}-${ARCH}"
if [ "$OS" = "windows" ]; then BIN="${BIN}.exe"; fi
GOOS="$OS" GOARCH="$ARCH" go build -trimpath -ldflags "-s -w \
-X 'github.com/gmgauthier/gostations/internal/version.Version=${VERSION}' \
-X 'github.com/gmgauthier/gostations/internal/version.Commit=${COMMIT}' \
-X 'github.com/gmgauthier/gostations/internal/version.BuildDate=${DATE}' \
-X 'main.version=${VERSION}'" -o "build/${BIN}" .
done
- name: Prepare assets
run: |
VERSION=${GITHUB_REF#refs/tags/}
for bin in build/gostations-* ; do
if [ ! -f "$bin" ]; then continue; fi
OSARCH=$(basename "$bin" | sed 's/gostations-//' | sed 's/\.exe$//')
tar czf "build/gostations-${OSARCH}-${VERSION}.tar.gz" -C build "$(basename "$bin")"
done
sha256sum build/gostations-*.tar.gz | tee build/checksums.txt
# Include useful scripts from repo (if present)
[ -f scripts/gostations-install.sh ] && cp scripts/gostations-install.sh build/
[ -f scripts/gostations-install.ps1 ] && cp scripts/gostations-install.ps1 build/
# Clean raw binaries (we ship the tarballs)
for plat in 'linux/amd64' 'linux/arm64' 'darwin/amd64' 'darwin/arm64' 'windows/amd64'; do
IFS='/' read -r OS ARCH <<< "$plat"
BIN="gostations-${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
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
VERSION=${GITHUB_REF#refs/tags/}
GITEA_API=https://repos.gmgauthier.com/api/v1
REPO=${GITHUB_REPOSITORY}
curl -X POST "${GITEA_API}/repos/${REPO}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${VERSION}\",
\"name\": \"gostations ${VERSION}\",
\"body\": \"## Quick Install\n\n### Bash (Linux/macOS)\n\n\`\`\`bash\ncurl -L https://repos.gmgauthier.com/${REPO}/releases/download/${VERSION}/gostations-install.sh | VERSION=${VERSION} bash\n\`\`\`\n\n### PowerShell (Windows/macOS/Linux)\n\n\`\`\`powershell\nirm https://repos.gmgauthier.com/${REPO}/releases/download/${VERSION}/gostations-install.ps1 | iex\n\`\`\`\n\nPlatform binaries (tar.gz) + checksums.txt are attached. See README.md and CHANGELOG (if present) for details. Legacy wmenu UI still available with --legacy.\"
}" > release.json
RELEASE_ID=$(jq .id release.json)
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"
curl -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