Files
unplayplay/.gitea/workflows/release.yml
T
dasemu 73f97d209f
Build and Release / build (push) Failing after 23s
Release workflow: use automatic GITHUB_TOKEN
2026-11-26 00:09:13 +01:00

64 lines
2.1 KiB
YAML

name: Build and Release
on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install build toolchain
run: |
if command -v apt-get >/dev/null; then
SUDO=$(command -v sudo || true)
$SUDO apt-get update -y
$SUDO apt-get install -y build-essential cmake
fi
- name: Build
run: |
mkdir build
cd build
cmake ../src
cmake --build . --target unplayplay --config Release
- name: Package binary
run: |
NAME=unplayplay-${GITHUB_REF_NAME:-dev}-linux-x64
mkdir -p dist-release
cp build/unplayplay "dist-release/${NAME}"
tar -czf "dist-release/${NAME}.tar.gz" -C build unplayplay
ls -la dist-release
- name: Create release and upload assets
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eu
[ -n "${TOKEN}" ] || { echo "ERROR: no token available (secrets.GITHUB_TOKEN is empty)"; exit 1; }
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
TAG="${GITHUB_REF_NAME}"
else
TAG="build-${GITHUB_RUN_NUMBER}"
fi
echo "Creating release ${TAG} on ${API}"
curl -sS --fail-with-body -X POST "$API/releases" \
-H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\"}" \
-o release.json
RELEASE_ID=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' release.json | head -1)
echo "Release id: ${RELEASE_ID}"
for f in dist-release/*; do
echo "Uploading $f"
curl -sS --fail-with-body -X POST "$API/releases/${RELEASE_ID}/assets?name=$(basename "$f")" \
-H "Authorization: token ${TOKEN}" -F "attachment=@${f}"
done