All checks were successful
release-tools / build-release (push) Successful in 32s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MmdG9GqfSWCzts7AkDwRDh
110 lines
4.4 KiB
YAML
110 lines
4.4 KiB
YAML
name: release-tools
|
|
|
|
# På varje push till master/main: bygg de tools som fått ändringar
|
|
# (linux x64 + arm64) och lägg binärerna på en rullande
|
|
# "<tool>-latest"-release på släppsidan i Gitea.
|
|
on:
|
|
push:
|
|
branches: [master, main]
|
|
workflow_dispatch: {} # manuell körning bygger ALLA tools
|
|
|
|
jobs:
|
|
build-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # hela historiken behövs för diffen mot 'before'
|
|
|
|
- name: Detektera ändrade tools
|
|
id: changed
|
|
run: |
|
|
TOOLS="pixel-sprite-maker mesh-tool bitmap-font-maker sfx-maker"
|
|
BEFORE="${{ github.event.before }}"
|
|
CHANGED=""
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ] \
|
|
|| [ -z "$BEFORE" ] \
|
|
|| echo "$BEFORE" | grep -Eq '^0+$' \
|
|
|| ! git cat-file -e "$BEFORE" 2>/dev/null; then
|
|
echo "första push / manuell körning -> bygger alla tools"
|
|
CHANGED="$TOOLS"
|
|
else
|
|
for t in $TOOLS; do
|
|
if ! git diff --quiet "$BEFORE" "${{ github.sha }}" -- "$t/"; then
|
|
CHANGED="$CHANGED $t"
|
|
fi
|
|
done
|
|
fi
|
|
CHANGED="$(echo $CHANGED)" # trimma whitespace
|
|
echo "tools=$CHANGED" >> "$GITHUB_OUTPUT"
|
|
echo "bygger: ${CHANGED:-inget}"
|
|
|
|
- name: Installera Go
|
|
if: steps.changed.outputs.tools != ''
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: "1.24"
|
|
cache: false
|
|
|
|
- name: Testa + bygg (x64 + arm64)
|
|
if: steps.changed.outputs.tools != ''
|
|
run: |
|
|
set -e
|
|
VERSION="latest-$(git rev-parse --short HEAD)"
|
|
for t in ${{ steps.changed.outputs.tools }}; do
|
|
case "$t" in
|
|
pixel-sprite-maker) BIN=spritec ;;
|
|
mesh-tool) BIN=mesht ;;
|
|
bitmap-font-maker) BIN=fontc ;;
|
|
sfx-maker) BIN=sfxc ;;
|
|
*) echo "okänt tool $t"; exit 1 ;;
|
|
esac
|
|
echo "=== $t ($BIN) ==="
|
|
cd "$t"
|
|
go test ./...
|
|
mkdir -p build
|
|
GOOS=linux GOARCH=amd64 go build -trimpath \
|
|
-ldflags "-s -w -X main.version=$VERSION" -o "build/$BIN-linux-x64" .
|
|
GOOS=linux GOARCH=arm64 go build -trimpath \
|
|
-ldflags "-s -w -X main.version=$VERSION" -o "build/$BIN-linux-arm64" .
|
|
(cd build && sha256sum "$BIN"-linux-* > checksums.txt && ls -la)
|
|
cd ..
|
|
done
|
|
|
|
- name: Skapa/uppdatera releaser + ladda upp binärer
|
|
if: steps.changed.outputs.tools != ''
|
|
env:
|
|
API: http://gitea-d:3000/api/v1
|
|
REPO: ${{ github.repository }}
|
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -e
|
|
for t in ${{ steps.changed.outputs.tools }}; do
|
|
case "$t" in
|
|
pixel-sprite-maker) BIN=spritec ;;
|
|
mesh-tool) BIN=mesht ;;
|
|
bitmap-font-maker) BIN=fontc ;;
|
|
sfx-maker) BIN=sfxc ;;
|
|
esac
|
|
TAG="$t-latest"
|
|
BODY="$t (binär: $BIN) - rullande bygge från senaste master. Commit: ${{ github.sha }}. Arkitekturer: linux x64 + arm64 (Pi5)."
|
|
rid=$(curl -s -X POST "$API/repos/$REPO/releases" \
|
|
-H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"$BODY\"}" | jq -r '.id // empty')
|
|
[ -z "$rid" ] && rid=$(curl -s "$API/repos/$REPO/releases/tags/$TAG" \
|
|
-H "Authorization: token $TOKEN" | jq -r '.id')
|
|
echo "$t -> release id $rid"
|
|
for f in "$BIN-linux-x64" "$BIN-linux-arm64" checksums.txt; do
|
|
aid=$(curl -s "$API/repos/$REPO/releases/$rid/assets" \
|
|
-H "Authorization: token $TOKEN" | jq -r ".[] | select(.name==\"$f\") | .id")
|
|
if [ -n "$aid" ] && [ "$aid" != "null" ]; then
|
|
curl -s -X DELETE "$API/repos/$REPO/releases/$rid/assets/$aid" \
|
|
-H "Authorization: token $TOKEN" -o /dev/null
|
|
fi
|
|
curl -s -X POST "$API/repos/$REPO/releases/$rid/assets?name=$f" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-F "attachment=@$t/build/$f" -o /dev/null -w " $f -> HTTP %{http_code}\n"
|
|
done
|
|
done
|