92 lines
3.2 KiB
YAML
92 lines
3.2 KiB
YAML
name: release
|
|
|
|
on:
|
|
release:
|
|
types: [published]
|
|
push:
|
|
tags:
|
|
- '*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Tag name for release (creates tag at HEAD)'
|
|
required: true
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
container: catthehacker/ubuntu:act-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Install Zig
|
|
run: |
|
|
curl -L https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz | tar -xJ
|
|
echo "$PWD/zig-x86_64-linux-0.15.2" >> $GITHUB_PATH
|
|
|
|
- name: Install X11 dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libgl1-mesa-dev
|
|
|
|
- name: Build Linux x86_64
|
|
run: |
|
|
zig build -Doptimize=ReleaseFast
|
|
mv zig-out/bin/sandbox lofivor-linux-x86_64
|
|
|
|
- name: Build Windows x86_64
|
|
run: |
|
|
zig build -Dtarget=x86_64-windows-gnu -Doptimize=ReleaseFast
|
|
mv zig-out/bin/sandbox.exe lofivor-windows-x86_64.exe
|
|
|
|
- name: Upload to release
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
run: |
|
|
echo "Token present: ${FORGEJO_TOKEN:+yes}"
|
|
echo "Token length: ${#FORGEJO_TOKEN}"
|
|
|
|
TAG="${{ github.event.inputs.tag || github.ref_name }}"
|
|
API_BASE="${{ github.server_url }}/api/v1"
|
|
REPO="${{ github.repository }}"
|
|
|
|
# ensure tag exists (create at HEAD if not)
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"${TAG}\"}" \
|
|
"${API_BASE}/repos/${REPO}/tags" || true
|
|
|
|
# get or create release
|
|
echo "Looking for release: ${API_BASE}/repos/${REPO}/releases/tags/${TAG}"
|
|
RESPONSE=$(curl -s -H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
"${API_BASE}/repos/${REPO}/releases/tags/${TAG}")
|
|
echo "Lookup response: ${RESPONSE}"
|
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
|
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Creating release for ${TAG}..."
|
|
echo '{"tag_name": "'"${TAG}"'", "name": "'"${TAG}"'"}' > /tmp/payload.json
|
|
cat /tmp/payload.json
|
|
RESPONSE=$(curl -sv --http1.1 -X POST \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
--data-binary @/tmp/payload.json \
|
|
"${API_BASE}/repos/${REPO}/releases" 2>&1)
|
|
echo "Full response: ${RESPONSE}"
|
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
fi
|
|
|
|
echo "Release ID: ${RELEASE_ID}"
|
|
|
|
# upload assets
|
|
for file in lofivor-linux-x86_64 lofivor-windows-x86_64.exe; do
|
|
echo "Uploading $file..."
|
|
curl -sf -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-F "attachment=@${file}" \
|
|
"${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${file}"
|
|
done
|