diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 2f9ebb2..b2b7cbe 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -4,6 +4,13 @@ # Creates a Gitea release tagged with the new version — but ONLY if the # version in `version` differs from the latest released tag. # +# The release also uploads a prebuilt binary archive +# (PacManager--x86_64.tar.gz with the binary, version file and +# plugins) so installed apps without a build toolchain can self-update +# WITHOUT recompiling. UpdateManager uses it as a fallback when git/cmake/a +# compiler are unavailable; otherwise it clones the repo and rebuilds. The +# upload is best-effort, so a failed build never blocks the release itself. +# # No secret is required: `secrets.GITEA_TOKEN` is the built-in automatic # token provided by Gitea on every run. The `permissions: contents: write` # block below asks for write access to contents and releases, so the release @@ -56,6 +63,7 @@ jobs: - name: Create release if: steps.check.outputs.new == 'true' + id: create env: # Built-in automatic token, no secret to configure. The # `permissions` block at the top grants it write access to @@ -69,7 +77,7 @@ jobs: `version` file was bumped. EOF ) - curl -sS -X POST "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \ + RESP=$(curl -sS -X POST "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d @- <> "$GITHUB_OUTPUT" + + - name: Build prebuilt binary archive + if: steps.check.outputs.new == 'true' + id: build + run: | + VERSION="${{ steps.version.outputs.value }}" + if command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm --needed git cmake gcc make qt6-base + elif command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get install -y git cmake g++ make qt6-base-dev + elif command -v dnf >/dev/null 2>&1; then + sudo dnf install -y git cmake gcc-c++ make qt6-qtbase-devel + else + echo "Unsupported package manager — skipping prebuilt archive" + echo "ok=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build -j$(nproc) + STAGE="pacmanager-dist" + rm -rf "${STAGE}" && mkdir -p "${STAGE}/bin" "${STAGE}/plugins" + cp build/PacManager "${STAGE}/bin/" + cp version "${STAGE}/bin/" + if ls build/plugins/*.so >/dev/null 2>&1; then + cp build/plugins/*.so "${STAGE}/plugins/" + fi + # Layout consumed by UpdateManager's prebuilt path: bin/PacManager, + # bin/version and plugins/ (unpacked next to the running executable, + # wherever it lives). + ARCHIVE="PacManager-${VERSION}-x86_64.tar.gz" + tar czf "${ARCHIVE}" -C "${STAGE}" bin plugins + echo "archive=${ARCHIVE}" >> "$GITHUB_OUTPUT" + echo "ok=true" >> "$GITHUB_OUTPUT" + + - name: Upload prebuilt archive to release + if: steps.check.outputs.new == 'true' && steps.build.outputs.ok == 'true' + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + ARCHIVE="${{ steps.build.outputs.archive }}" + RELEASE_ID="${{ steps.create.outputs.release_id }}" + if [ -z "${RELEASE_ID}" ]; then + echo "No release id — skipping upload" + exit 0 + fi + curl -sS -X POST \ + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/${RELEASE_ID}/assets?name=$(basename ${ARCHIVE})" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/gzip" \ + --data-binary "@${ARCHIVE}" || echo "Asset upload failed — release still valid without prebuilt binary" diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 06641a1..911aad1 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -2,7 +2,9 @@ # # Dedicated test workflow: builds the application and runs the full test suite # (ctest) on every push and pull request. Kept separate from the release -# workflow so a failing test never blocks a release. +# workflow so a failing test never blocks a release. Also guards the +# `version` file: it must match the latest git tag (if any), otherwise the +# self-update check would report a phantom update. name: tests @@ -12,6 +14,33 @@ on: workflow_dispatch: jobs: + version-guard: + runs-on: linux + steps: + - name: Checkout with full history and tags + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Check version file matches latest tag (when tags exist) + run: | + VERSION=$(tr -d ' \n' < version) + echo "version file: ${VERSION}" + LATEST=$(git describe --tags --abbrev=0 2>/dev/null || true) + if [ -z "${LATEST}" ]; then + echo "No tags yet — skipping version guard" + exit 0 + fi + # Tags are like v1.3.1 / V1.3.1 ; the file holds 1.3.1 + NORMALIZED=$(echo "${LATEST}" | sed -E 's/^[vV]//') + echo "latest tag: ${LATEST} (normalized: ${NORMALIZED})" + if [ "${VERSION}" != "${NORMALIZED}" ]; then + echo "::error::version file (${VERSION}) does not match latest tag ${LATEST} (expected ${NORMALIZED}). Bump the version file before tagging." + exit 1 + fi + echo "version file matches latest tag" + build-test: runs-on: linux steps: