2026-03-20 12:51:45 +00:00
|
|
|
name: Build and Release auth-rt
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
tags:
|
|
|
|
|
- 'v*'
|
|
|
|
|
|
|
|
|
|
jobs:
|
2026-03-20 13:03:32 +00:00
|
|
|
release:
|
2026-03-20 12:51:45 +00:00
|
|
|
runs-on: docker
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
|
2026-03-20 13:17:45 +00:00
|
|
|
- name: Install Go
|
|
|
|
|
run: |
|
|
|
|
|
curl -fsSL https://go.dev/dl/go1.22.12.linux-amd64.tar.gz | tar -C /usr/local -xz
|
|
|
|
|
echo "/usr/local/go/bin" >> $GITHUB_PATH
|
|
|
|
|
|
2026-03-20 13:03:32 +00:00
|
|
|
- name: Build all platforms
|
|
|
|
|
run: |
|
2026-03-20 13:17:45 +00:00
|
|
|
export PATH="/usr/local/go/bin:$PATH"
|
2026-03-20 13:24:22 +00:00
|
|
|
export GOTOOLCHAIN=local
|
2026-03-20 13:03:32 +00:00
|
|
|
cd cli
|
|
|
|
|
for pair in darwin/arm64 darwin/amd64 linux/amd64 linux/arm64; do
|
|
|
|
|
os="${pair%/*}"
|
|
|
|
|
arch="${pair#*/}"
|
|
|
|
|
echo "Building auth-rt-${os}-${arch}..."
|
2026-03-20 13:17:45 +00:00
|
|
|
GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 go build -ldflags="-s -w" -o "../auth-rt-${os}-${arch}" .
|
2026-03-20 13:03:32 +00:00
|
|
|
done
|
|
|
|
|
ls -lh ../auth-rt-*
|
2026-03-20 12:51:45 +00:00
|
|
|
|
2026-03-20 13:03:32 +00:00
|
|
|
- name: Create release and upload binaries
|
2026-03-20 12:51:45 +00:00
|
|
|
env:
|
2026-03-20 13:03:32 +00:00
|
|
|
TAG: ${{ github.ref_name }}
|
|
|
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
|
|
|
API_URL: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
2026-03-20 12:51:45 +00:00
|
|
|
run: |
|
2026-03-20 13:21:42 +00:00
|
|
|
json_get() { node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).$1 || ''))"; }
|
|
|
|
|
|
2026-03-20 13:03:32 +00:00
|
|
|
# Create release
|
|
|
|
|
RELEASE_ID=$(curl -s -X POST "$API_URL/releases" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"auth-rt $TAG\"}" \
|
2026-03-20 13:21:42 +00:00
|
|
|
| json_get id)
|
2026-03-20 12:51:45 +00:00
|
|
|
|
2026-03-20 13:03:32 +00:00
|
|
|
echo "Created release ID: $RELEASE_ID"
|
2026-03-20 12:51:45 +00:00
|
|
|
|
2026-03-20 13:03:32 +00:00
|
|
|
# Upload each binary
|
|
|
|
|
for f in auth-rt-*; do
|
|
|
|
|
echo "Uploading $f..."
|
|
|
|
|
curl -s -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$f" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
-H "Content-Type: application/octet-stream" \
|
|
|
|
|
--data-binary "@$f"
|
|
|
|
|
echo ""
|
|
|
|
|
done
|
2026-03-20 12:51:45 +00:00
|
|
|
|
2026-03-20 13:17:45 +00:00
|
|
|
# Maintain "latest" release
|
2026-03-20 13:03:32 +00:00
|
|
|
LATEST_ID=$(curl -s "$API_URL/releases/tags/latest" \
|
2026-03-20 13:21:42 +00:00
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" | json_get id)
|
2026-03-20 13:03:32 +00:00
|
|
|
|
|
|
|
|
if [ -n "$LATEST_ID" ]; then
|
|
|
|
|
# Delete old assets
|
2026-03-20 13:21:42 +00:00
|
|
|
ASSET_IDS=$(curl -s "$API_URL/releases/$LATEST_ID/assets" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
| node -e "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).forEach(a=>console.log(a.id))")
|
|
|
|
|
for aid in $ASSET_IDS; do
|
2026-03-20 13:03:32 +00:00
|
|
|
curl -s -X DELETE "$API_URL/releases/$LATEST_ID/assets/$aid" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN"
|
|
|
|
|
done
|
|
|
|
|
curl -s -X PATCH "$API_URL/releases/$LATEST_ID" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d "{\"body\":\"auth-rt latest (from $TAG)\"}"
|
|
|
|
|
else
|
|
|
|
|
LATEST_ID=$(curl -s -X POST "$API_URL/releases" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d '{"tag_name":"latest","name":"latest","body":"auth-rt latest","prerelease":true}' \
|
2026-03-20 13:21:42 +00:00
|
|
|
| json_get id)
|
2026-03-20 13:03:32 +00:00
|
|
|
fi
|
|
|
|
|
|
2026-03-20 12:51:45 +00:00
|
|
|
for f in auth-rt-*; do
|
2026-03-20 13:03:32 +00:00
|
|
|
curl -s -X POST "$API_URL/releases/$LATEST_ID/assets?name=$f" \
|
|
|
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
|
|
|
-H "Content-Type: application/octet-stream" \
|
|
|
|
|
--data-binary "@$f"
|
2026-03-20 12:51:45 +00:00
|
|
|
done
|
2026-03-20 13:03:32 +00:00
|
|
|
|
|
|
|
|
echo "Done. Release $TAG + latest updated."
|