From 1c85341b1fe5918e03a9cc213a5def146a16a343 Mon Sep 17 00:00:00 2001 From: Docker Build Date: Sun, 10 May 2026 14:24:33 -0500 Subject: [PATCH] ci: disable electron-builder GitHub publish; add Gitea sync workflow - Use --publish never in pack/CI so tagged builds do not require GH_TOKEN. - Set build.publish to null and align publish:win with local-only packaging. - Add Gitea release sync workflow and upload script; fetch script from default branch so reruns work for tags that predate the script. Co-authored-by: Cursor --- .github/workflows/fractured-launcher-ci.yml | 2 +- .github/workflows/gitea-release-sync.yml | 156 ++++++++++++++++++ .../fractured-launcher-electron/package.json | 12 +- .../scripts/upload-release-to-gitea.sh | 85 ++++++++++ 4 files changed, 245 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/gitea-release-sync.yml create mode 100644 tools/fractured-launcher-electron/scripts/upload-release-to-gitea.sh diff --git a/.github/workflows/fractured-launcher-ci.yml b/.github/workflows/fractured-launcher-ci.yml index 2236397..d66a062 100644 --- a/.github/workflows/fractured-launcher-ci.yml +++ b/.github/workflows/fractured-launcher-ci.yml @@ -40,7 +40,7 @@ jobs: - name: Install and pack (NSIS + portable) run: | npm ci - npm run pack:win + npx electron-builder --win nsis portable --x64 --publish never - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/gitea-release-sync.yml b/.github/workflows/gitea-release-sync.yml new file mode 100644 index 0000000..ef8af71 --- /dev/null +++ b/.github/workflows/gitea-release-sync.yml @@ -0,0 +1,156 @@ +# Primary path for player-facing binaries: every *published* GitHub Release on this repo +# is mirrored to your self-hosted Gitea (same tag). No public GitHub distro repo. +# +# Triggers: +# - release: published / released → GitHub “Release” (not a raw git tag alone). +# - workflow_dispatch → re-run for a tag manually. +# +# Important: pushing only a git tag does NOT run this — you must create/publish a +# Release on github.com (Releases → Draft/new release → Publish). The workflow +# definition must exist on the repo DEFAULT branch (GitHub runs it from there). +# +# Steps: build Electron from tag → download this repo’s release attachments → upload all to Gitea. +# +# Secrets: GITEA_BASE_URL, GITEA_TOKEN, GITEA_OWNER, GITEA_REPO +# Optional variable: GITEA_TARGET_REF (see tools/fractured-launcher-electron/README.md) +# +# Job guard: edit `if:` if github.repository is not Dawnforger/Fractured. + +name: Sync release to Gitea + +on: + release: + types: [published, released] + workflow_dispatch: + inputs: + tag: + description: 'Release tag on this GitHub repo (must exist; e.g. v1.0.0)' + required: true + type: string + +permissions: + contents: read + +concurrency: + group: gitea-release-sync-${{ github.repository }}-${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.event.release.tag_name }} + cancel-in-progress: false + +jobs: + meta: + runs-on: ubuntu-latest + if: github.repository == 'Dawnforger/Fractured' + outputs: + tag: ${{ steps.t.outputs.tag }} + steps: + - name: Resolve tag + id: t + shell: bash + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT" + else + echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" + fi + + build-electron: + needs: meta + if: github.repository == 'Dawnforger/Fractured' + runs-on: windows-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.meta.outputs.tag }} + + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: npm + cache-dependency-path: tools/fractured-launcher-electron/package-lock.json + + - name: Install and pack (NSIS + portable) + working-directory: tools/fractured-launcher-electron + run: | + npm ci + # --publish never: on tagged checkouts electron-builder otherwise tries to + # push to GitHub releases and fails without GH_TOKEN (we upload via Gitea). + npx electron-builder --win nsis portable --x64 --publish never + + - name: Stage launcher files for upload + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path launcher-publish | Out-Null + Copy-Item tools/fractured-launcher-electron/dist/*.exe launcher-publish/ + if (Test-Path tools/fractured-launcher-electron/dist/latest.yml) { + Copy-Item tools/fractured-launcher-electron/dist/latest.yml launcher-publish/ + } + Get-ChildItem tools/fractured-launcher-electron/dist/*.blockmap -ErrorAction SilentlyContinue | + Copy-Item -Destination launcher-publish/ + + - uses: actions/upload-artifact@v4 + with: + name: electron-dist + path: launcher-publish/ + + sync-gitea: + needs: [meta, build-electron] + if: github.repository == 'Dawnforger/Fractured' + runs-on: ubuntu-latest + env: + GITEA_BASE_URL: ${{ secrets.GITEA_BASE_URL }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_OWNER: ${{ secrets.GITEA_OWNER }} + GITEA_REPO: ${{ secrets.GITEA_REPO }} + GITEA_TARGET_REF: ${{ vars.GITEA_TARGET_REF }} + steps: + - uses: actions/checkout@v4 + with: + # Script may not exist on older release tags; always use default branch. + ref: ${{ github.event.repository.default_branch }} + sparse-checkout: | + tools/fractured-launcher-electron/scripts + sparse-checkout-cone-mode: true + + - uses: actions/download-artifact@v4 + with: + name: electron-dist + path: /tmp/electron + + - name: Merge GitHub release assets + Electron build + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + TAG="${{ needs.meta.outputs.tag }}" + mkdir -p combined + mkdir -p /tmp/from-main + if gh release download "$TAG" -R "${{ github.repository }}" -D /tmp/from-main 2>/tmp/dl.err; then + shopt -s nullglob + for f in /tmp/from-main/*; do + if [ -f "$f" ]; then + cp -f "$f" combined/ + fi + done + echo "Merged assets from ${{ github.repository }} release $TAG" + else + echo "GitHub release download note (continuing with launcher only):" + cat /tmp/dl.err || true + fi + shopt -s nullglob + for f in /tmp/electron/*; do + if [ -f "$f" ]; then + cp -f "$f" combined/ + fi + done + ls -la combined/ + + - name: Upload to Gitea + run: | + set -euo pipefail + for v in GITEA_BASE_URL GITEA_TOKEN GITEA_OWNER GITEA_REPO; do + if [ -z "${!v:-}" ]; then + echo "Missing secret $v — add it under repo Settings → Secrets and variables → Actions." >&2 + exit 1 + fi + done + bash tools/fractured-launcher-electron/scripts/upload-release-to-gitea.sh combined "${{ needs.meta.outputs.tag }}" diff --git a/tools/fractured-launcher-electron/package.json b/tools/fractured-launcher-electron/package.json index bce5cd3..e480994 100644 --- a/tools/fractured-launcher-electron/package.json +++ b/tools/fractured-launcher-electron/package.json @@ -9,8 +9,8 @@ }, "scripts": { "start": "electron .", - "pack:win": "electron-builder --win nsis portable --x64", - "publish:win": "electron-builder --win nsis portable --x64 --publish always" + "pack:win": "electron-builder --win nsis portable --x64 --publish never", + "publish:win": "electron-builder --win nsis portable --x64 --publish never" }, "author": "", "license": "GPL-3.0", @@ -27,13 +27,7 @@ "directories": { "output": "dist" }, - "publish": [ - { - "provider": "github", - "owner": "Dawnforger", - "repo": "Fractured-Distro" - } - ], + "publish": null, "files": [ "main.js", "preload.cjs", diff --git a/tools/fractured-launcher-electron/scripts/upload-release-to-gitea.sh b/tools/fractured-launcher-electron/scripts/upload-release-to-gitea.sh new file mode 100644 index 0000000..7419760 --- /dev/null +++ b/tools/fractured-launcher-electron/scripts/upload-release-to-gitea.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# Upload all files in a directory as attachments on a Gitea release (create release if missing). +# +# Usage: +# export GITEA_BASE_URL=https://git.example.com +# export GITEA_TOKEN=gta_... +# export GITEA_OWNER=myorg +# export GITEA_REPO=fractured-patches +# export GITEA_TARGET_REF=main # optional, used when creating a new release (tag must not exist yet) +# ./upload-release-to-gitea.sh /path/to/combined v1.0.0 +# +set -euo pipefail + +COMBINED_DIR="${1:?first arg: directory of files to attach}" +TAG="${2:?second arg: release tag (e.g. v1.0.0)}" + +: "${GITEA_BASE_URL:?Set GITEA_BASE_URL (no trailing slash required)}" +: "${GITEA_TOKEN:?Set GITEA_TOKEN}" +: "${GITEA_OWNER:?Set GITEA_OWNER}" +: "${GITEA_REPO:?Set GITEA_REPO}" + +BASE="${GITEA_BASE_URL%/}" +API="$BASE/api/v1" +TARGET="${GITEA_TARGET_REF:-main}" +AUTH_H=(-H "Authorization: token ${GITEA_TOKEN}" -H "Accept: application/json") + +TAG_ENC=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$TAG") +REL_JSON=$(mktemp) +trap 'rm -f "$REL_JSON"' EXIT + +code=$(curl -sS -o "$REL_JSON" -w "%{http_code}" "${AUTH_H[@]}" \ + "$API/repos/${GITEA_OWNER}/${GITEA_REPO}/releases/tags/${TAG_ENC}") + +if [ "$code" = "200" ]; then + rel_id=$(jq -r '.id' "$REL_JSON") +elif [ "$code" = "404" ]; then + body=$(jq -n \ + --arg tag "$TAG" \ + --arg name "Fractured $TAG" \ + --arg body "Synced from GitHub Actions (Fractured)." \ + --arg target "$TARGET" \ + '{tag_name:$tag,name:$name,body:$body,draft:false,prerelease:false,target_commitish:$target}') + code=$(curl -sS -o "$REL_JSON" -w "%{http_code}" -X POST "${AUTH_H[@]}" \ + -H "Content-Type: application/json" \ + -d "$body" \ + "$API/repos/${GITEA_OWNER}/${GITEA_REPO}/releases") + if [ "$code" != "201" ] && [ "$code" != "200" ]; then + echo "Gitea create release failed HTTP $code:" >&2 + cat "$REL_JSON" >&2 + exit 1 + fi + rel_id=$(jq -r '.id' "$REL_JSON") +else + echo "Gitea GET release by tag failed HTTP $code:" >&2 + cat "$REL_JSON" >&2 + exit 1 +fi + +if [ -z "$rel_id" ] || [ "$rel_id" = "null" ]; then + echo "Could not resolve Gitea release id" >&2 + exit 1 +fi + +while read -r aid; do + [ -z "$aid" ] || [ "$aid" = "null" ] && continue + curl -fsS -X DELETE "${AUTH_H[@]}" \ + "$API/repos/${GITEA_OWNER}/${GITEA_REPO}/releases/${rel_id}/assets/${aid}" || true +done < <(jq -r '(.attachments // .assets // [])[] | .id' "$REL_JSON") + +shopt -s nullglob +files=("$COMBINED_DIR"/*) +if [ "${#files[@]}" -eq 0 ]; then + echo "No files in $COMBINED_DIR" >&2 + exit 1 +fi + +for f in "${files[@]}"; do + [ -f "$f" ] || continue + echo "Uploading $(basename "$f") …" + curl -fsS -X POST "${AUTH_H[@]}" \ + -F "attachment=@${f}" \ + "$API/repos/${GITEA_OWNER}/${GITEA_REPO}/releases/${rel_id}/assets" +done + +echo "Gitea release $TAG (id=$rel_id) updated with ${#files[@]} file(s)."