fix(ci): harmonize release workflow with linux-updater proven architecture
Build and Publish Release / Build Packages and Publish (push) Successful in 43s

This commit is contained in:
soda64 committed 2026-10-09 20:33:13 +02:00
1 parent d18db76441
commit c89aa3d1c7
1 file changed
+110 -45
+110 -45
View File
@@ -5,78 +5,143 @@ on:
tags: tags:
- 'v*' - 'v*'
workflow_dispatch: workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 1.0.0)'
required: false
default: ''
jobs: jobs:
test-and-release: release:
name: Build Packages and Publish
runs-on: fedora runs-on: fedora
steps: steps:
- name: Checkout Source Code - name: Checkout Source Code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Build Dependencies - name: Verify Build Environment
run: | run: |
echo "[INFO] Verifying build dependencies..." echo "=== Runner System Info ==="
uname -a
python3 --version python3 --version
if ! command -v rpmbuild >/dev/null 2>&1; then if ! command -v rpmbuild &>/dev/null; then
echo "[INFO] Installing rpm-build..." echo "Installing rpm-build..."
sudo dnf install -y rpm-build sudo dnf install -y rpm-build
else
echo "rpmbuild is already available: $(which rpmbuild)"
fi fi
- name: Run Quality Gate Test Suite - name: Run Test Suite
run: | run: |
echo "[INFO] Executing comprehensive test suite..." echo "=== Running Unit Tests ==="
python3 -m unittest discover tests -v python3 -m unittest discover tests
- name: Build Distribution Packages - name: Build Distribution Packages
id: build_pkgs
run: | run: |
echo "[INFO] Building .tar.gz, .deb, and .rpm distribution packages..." echo "=== Building Packages (.rpm, .deb, .tar.gz) ==="
rm -rf dist python3 packaging/build_packages.py --all
python3 packaging/build_packages.py --all --out-dir dist echo "=== Built Artifacts ==="
ls -lh dist/ ls -lh dist/*.tar.gz dist/*.deb 2>/dev/null || true
ls -lh dist/*.rpm dist/rpmbuild/RPMS/*/*.rpm 2>/dev/null || true
- name: Publish to Gitea Package Registry - name: Publish to Gitea Package Registry
env: env:
PKG_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }} PKG_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }}
run: | run: |
echo "[INFO] Uploading packages to Gitea Package Registry..." echo "=== Publishing to Gitea Package Registry ==="
OWNER="${{ github.repository_owner }}" RPM_FILE=$(find dist -name "*.rpm" 2>/dev/null | head -n 1)
REPO="${{ github.event.repository.name }}" DEB_FILE=$(ls dist/*.deb 2>/dev/null | head -n 1)
SERVER="${{ github.server_url }}"
RPM_FILE=$(find dist -maxdepth 1 -name "*.rpm" | head -n 1) if [ -n "$RPM_FILE" ] && [ -f "$RPM_FILE" ]; then
DEB_FILE=$(find dist -maxdepth 1 -name "*.deb" | head -n 1) echo "Uploading RPM: $RPM_FILE"
HTTP_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" -X PUT \
if [[ -f "$RPM_FILE" ]]; then -u "${{ github.actor }}:${PKG_TOKEN}" \
echo "[INFO] Publishing RPM to registry..."
curl -k -s -f -X PUT -u "${{ github.actor }}:${PKG_TOKEN}" \
--upload-file "$RPM_FILE" \ --upload-file "$RPM_FILE" \
"${SERVER}/api/packages/${OWNER}/rpm/upload" || echo "[WARNING] RPM upload returned non-zero (may already exist)" "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/rpm/upload")
echo "RPM Registry HTTP status: $HTTP_CODE"
curl -k -s -X POST -H "Authorization: token ${PKG_TOKEN}" \
"${SERVER}/api/v1/packages/${OWNER}/rpm/linux-backuper/-/link/${REPO}" || true
fi fi
if [[ -f "$DEB_FILE" ]]; then if [ -n "$DEB_FILE" ] && [ -f "$DEB_FILE" ]; then
echo "[INFO] Publishing Debian to registry..." echo "Uploading DEB: $DEB_FILE"
curl -k -s -f -X PUT -u "${{ github.actor }}:${PKG_TOKEN}" \ HTTP_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" -X PUT \
-u "${{ github.actor }}:${PKG_TOKEN}" \
--upload-file "$DEB_FILE" \ --upload-file "$DEB_FILE" \
"${SERVER}/api/packages/${OWNER}/debian/pool/stable/main/upload" || echo "[WARNING] DEB upload returned non-zero (may already exist)" "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/debian/pool/stable/main/upload")
echo "Debian Registry HTTP status: $HTTP_CODE"
curl -k -s -X POST -H "Authorization: token ${PKG_TOKEN}" \
"${SERVER}/api/v1/packages/${OWNER}/debian/linux-backuper/-/link/${REPO}" || true
fi fi
- name: Publish Gitea Release & Upload Assets # Link packages to this repository in Gitea
if: startsWith(github.ref, 'refs/tags/v') REPO_NAME=$(basename "${{ github.repository }}")
echo "Linking RPM package 'linux-backuper' to repository ${REPO_NAME}..."
LINK_RPM=$(curl -k -s -w " (HTTP %{http_code})" -X POST \
-H "Authorization: token ${PKG_TOKEN}" \
"${{ github.server_url }}/api/v1/packages/${{ github.repository_owner }}/rpm/linux-backuper/-/link/${REPO_NAME}")
echo "RPM link result: $LINK_RPM"
echo "Linking Debian package 'linux-backuper' to repository ${REPO_NAME}..."
LINK_DEB=$(curl -k -s -w " (HTTP %{http_code})" -X POST \
-H "Authorization: token ${PKG_TOKEN}" \
"${{ github.server_url }}/api/v1/packages/${{ github.repository_owner }}/debian/linux-backuper/-/link/${REPO_NAME}")
echo "Debian link result: $LINK_DEB"
- name: Attach Artifacts to Gitea Release
env: env:
GITEA_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }}
SERVER_URL: ${{ github.server_url }}
REPO: ${{ github.repository }}
TAG_REF: ${{ github.ref_name }}
run: | run: |
python3 packaging/publish_release.py echo "=== Attaching Assets to Release ==="
TAG="${TAG_REF}"
if [[ "$TAG" == "main" || "$TAG" == "" ]]; then
VER=$(python3 -c "import linux_backuper; print(linux_backuper.__version__)")
TAG="v${VER}"
fi
echo "Target Release Tag: $TAG"
# 1. Fetch release ID or create release if missing
REL_JSON=$(curl -k -s -H "Authorization: token ${GITHUB_TOKEN}" \
"${SERVER_URL}/api/v1/repos/${REPO}/releases/tags/${TAG}")
REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$REL_JSON" 2>/dev/null || true)
if [ -z "$REL_ID" ]; then
echo "Release $TAG does not exist yet. Creating release..."
CREATE_DATA=$(python3 -c "import sys, json; print(json.dumps({'tag_name': sys.argv[1], 'name': 'linux-backuper ' + sys.argv[1], 'body': 'Automated build and release for ' + sys.argv[1] + ' (Debian, Red Hat/Fedora, and universal tarball).'}))" "$TAG")
CREATE_RESP=$(curl -k -s -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d "$CREATE_DATA" \
"${SERVER_URL}/api/v1/repos/${REPO}/releases")
REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$CREATE_RESP" 2>/dev/null || true)
echo "Create release response: $CREATE_RESP"
fi
echo "Release ID: $REL_ID"
if [ -n "$REL_ID" ]; then
# Clean up any existing assets for this release
EXISTING_ASSETS=$(curl -k -s -H "Authorization: token ${GITHUB_TOKEN}" \
"${SERVER_URL}/api/v1/repos/${REPO}/releases/${REL_ID}/assets" || true)
ASSET_IDS=$(python3 -c "import sys, json; print(' '.join(str(a['id']) for a in json.loads(sys.argv[1])))" "$EXISTING_ASSETS" 2>/dev/null || true)
for aid in $ASSET_IDS; do
echo "Removing previous asset ID $aid..."
curl -k -s -X DELETE -H "Authorization: token ${GITHUB_TOKEN}" \
"${SERVER_URL}/api/v1/repos/${REPO}/releases/${REL_ID}/assets/${aid}" || true
done
# Target only user-facing binaries
ASSET_FILES=(
$(ls dist/*.tar.gz 2>/dev/null || true)
$(ls dist/*.deb 2>/dev/null || true)
$(find dist -name "*.rpm" 2>/dev/null | grep -v 'src\.rpm' || true)
)
for f in "${ASSET_FILES[@]}"; do
if [ -f "$f" ]; then
fname=$(basename "$f")
echo "Uploading asset $fname from $f..."
curl -k -s -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-F "attachment=@${f}" \
"${SERVER_URL}/api/v1/repos/${REPO}/releases/${REL_ID}/assets?name=${fname}" || echo "Asset upload note: $?"
fi
done
echo "Artifacts successfully attached to release $TAG!"
else
echo "Could not obtain release ID, skipping asset attachment."
fi