All checks were successful
Build & Release / build (push) Successful in 34s
grep-based JSON parsing broke on Gitea's response format (exit 3: URL malformat from corrupted release ID). Use python3 json module for reliable parsing. Also add trap-based token cleanup and upload status verification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
4.2 KiB
YAML
107 lines
4.2 KiB
YAML
name: Build & Release
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
tags: ['v*']
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update -qq && apt-get install -y -qq ca-certificates curl >/dev/null
|
|
install -m 0755 -d /etc/apt/keyrings
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable" > /etc/apt/sources.list.d/docker.list
|
|
apt-get update -qq && apt-get install -y -qq docker-ce-cli >/dev/null
|
|
|
|
- name: Build mod
|
|
run: |
|
|
VERSION=$(grep -oPm1 '"version":\s*"\K[^"]+' resources/modinfo.json)
|
|
MODID="welcomescreen"
|
|
echo "Building ${MODID} v${VERSION}..."
|
|
|
|
# DinD: bind mounts don't work — use docker cp with a volume
|
|
docker volume create mod-build
|
|
docker pull alpine:3 >/dev/null 2>&1
|
|
HELPER=$(docker create -v mod-build:/src alpine:3 true)
|
|
docker cp . $HELPER:/src/
|
|
docker rm $HELPER >/dev/null
|
|
|
|
docker run --rm -v mod-build:/src -w /src mcr.microsoft.com/dotnet/sdk:8.0 \
|
|
dotnet build -c Release
|
|
|
|
# Extract build output from volume
|
|
HELPER=$(docker create -v mod-build:/src alpine:3 true)
|
|
docker cp $HELPER:/src/bin/Release/WelcomeScreen.dll ./WelcomeScreen.dll
|
|
docker rm $HELPER >/dev/null
|
|
docker volume rm mod-build >/dev/null
|
|
|
|
# Package mod ZIP
|
|
mkdir -p dist
|
|
cp WelcomeScreen.dll dist/
|
|
cp resources/modinfo.json dist/
|
|
cd dist && zip -j "../${MODID}_${VERSION}.zip" WelcomeScreen.dll modinfo.json
|
|
cd ..
|
|
|
|
echo "MOD_ZIP=${MODID}_${VERSION}.zip" >> $GITHUB_ENV
|
|
echo "MOD_VERSION=${VERSION}" >> $GITHUB_ENV
|
|
echo "Built: ${MODID}_${VERSION}.zip"
|
|
|
|
- name: Create release
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
run: |
|
|
TAG="${GITHUB_REF#refs/tags/}"
|
|
TOKEN_NAME="ci-release-$$"
|
|
|
|
# Generate temporary Gitea API token via docker exec (host Docker socket)
|
|
# --user git = container OS user; -u calic = Gitea account
|
|
TOKEN=$(docker exec --user git gitea gitea admin user generate-access-token \
|
|
-u calic -t "$TOKEN_NAME" --scopes all --raw)
|
|
if [ -z "$TOKEN" ]; then
|
|
echo "ERROR: Failed to generate Gitea API token"
|
|
exit 1
|
|
fi
|
|
|
|
# API calls use git.davoryn.de (NGINX proxy) — gitea:3000 is NOT
|
|
# resolvable from CI job containers (separate Docker network)
|
|
API="https://git.davoryn.de/api/v1"
|
|
|
|
cleanup_token() {
|
|
curl -s -X DELETE -u "calic:${TOKEN}" "${API}/users/calic/tokens/${TOKEN_NAME}" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup_token EXIT
|
|
|
|
# Create release — use python3 for reliable JSON parsing
|
|
echo "Creating release ${TAG}..."
|
|
RELEASE_JSON=$(curl -s \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Welcome Screen ${MOD_VERSION}\",\"body\":\"Release ${MOD_VERSION}\"}" \
|
|
"${API}/repos/calic/vs-welcome-screen/releases")
|
|
|
|
RELEASE_ID=$(echo "$RELEASE_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "ERROR: Failed to create release. Response: ${RELEASE_JSON}"
|
|
exit 1
|
|
fi
|
|
echo "Release created (id: ${RELEASE_ID})"
|
|
|
|
# Attach mod ZIP to release
|
|
echo "Uploading ${MOD_ZIP}..."
|
|
UPLOAD_RESP=$(curl -s -w "\nHTTP_%{http_code}" \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-F "attachment=@${MOD_ZIP}" \
|
|
"${API}/repos/calic/vs-welcome-screen/releases/${RELEASE_ID}/assets")
|
|
if ! echo "$UPLOAD_RESP" | grep -q "HTTP_201"; then
|
|
echo "ERROR: Upload failed. Response: ${UPLOAD_RESP}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release ${TAG} created with ${MOD_ZIP}"
|