85 lines
3.1 KiB
YAML
85 lines
3.1 KiB
YAML
name: build-and-release
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # svu needs full history + tags
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.26'
|
|
cache: false
|
|
|
|
- name: Install svu
|
|
timeout-minutes: 3
|
|
run: |
|
|
set -ex
|
|
which curl tar
|
|
curl -fL --max-time 120 --connect-timeout 15 \
|
|
-o /tmp/svu.tar.gz \
|
|
https://github.com/caarlos0/svu/releases/download/v3.2.2/svu_3.2.2_linux_amd64.tar.gz
|
|
ls -la /tmp/svu.tar.gz
|
|
tar -xzf /tmp/svu.tar.gz -C /usr/local/bin svu
|
|
svu --version
|
|
|
|
- name: Compute next version
|
|
id: ver
|
|
run: |
|
|
CURRENT=$(svu current 2>/dev/null || echo v0.0.0)
|
|
NEXT=$(svu next)
|
|
echo "current=$CURRENT" >> $GITHUB_OUTPUT
|
|
echo "next=$NEXT" >> $GITHUB_OUTPUT
|
|
if [ "$CURRENT" = "$NEXT" ]; then
|
|
echo "release=false" >> $GITHUB_OUTPUT
|
|
echo "No version-worthy commits since $CURRENT; skipping release."
|
|
else
|
|
echo "release=true" >> $GITHUB_OUTPUT
|
|
echo "Releasing $NEXT (was $CURRENT)."
|
|
fi
|
|
|
|
- name: Install UPX
|
|
if: steps.ver.outputs.release == 'true'
|
|
run: sudo apt-get update && sudo apt-get install -y upx-ucl
|
|
|
|
- name: Build binaries
|
|
if: steps.ver.outputs.release == 'true'
|
|
env:
|
|
VERSION: ${{ steps.ver.outputs.next }}
|
|
LDFLAGS: -s -w -X nadir.Version=${{ steps.ver.outputs.next }}
|
|
run: |
|
|
mkdir -p dist
|
|
GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS" -o dist/nadir-$VERSION-linux-amd64 ./cmd/server
|
|
GOOS=linux GOARCH=arm64 go build -ldflags="$LDFLAGS" -o dist/nadir-$VERSION-linux-arm64 ./cmd/server
|
|
upx --best --lzma dist/nadir-$VERSION-linux-amd64 dist/nadir-$VERSION-linux-arm64
|
|
|
|
- name: Tag and release
|
|
if: steps.ver.outputs.release == 'true'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEATOKEN }}
|
|
VERSION: ${{ steps.ver.outputs.next }}
|
|
run: |
|
|
git config user.email "ci@nadir"
|
|
git config user.name "nadir-ci"
|
|
git tag -a "$VERSION" -m "$VERSION"
|
|
git push "https://x:${GITEA_TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" "$VERSION"
|
|
# Create the release via Gitea API (works on any Gitea ≥ 1.20)
|
|
curl -sSf -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"$VERSION\",\"name\":\"$VERSION\"}" \
|
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases" > release.json
|
|
RELEASE_ID=$(grep -o '"id":[0-9]*' release.json | head -1 | cut -d: -f2)
|
|
for f in dist/*; do
|
|
curl -sSf -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-F "attachment=@$f" \
|
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/$RELEASE_ID/assets?name=$(basename $f)"
|
|
done
|