feat: add system packaging (.rpm, .deb, .tar.gz) and Gitea Actions CI/CD release workflow
This commit is contained in:
1 parent
e5784db650
commit
a03d9a85e6
10 files changed
+834
No files matched your search
@@ -0,0 +1,155 @@
|
||||
name: Build and Publish Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Build Packages and Publish
|
||||
runs-on: fedora
|
||||
steps:
|
||||
- name: Checkout Source Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Verify Build Environment
|
||||
run: |
|
||||
echo "=== Runner System Info ==="
|
||||
uname -a
|
||||
python3 --version
|
||||
if ! command -v rpmbuild &>/dev/null; then
|
||||
echo "Installing rpm-build..."
|
||||
sudo dnf install -y rpm-build
|
||||
else
|
||||
echo "rpmbuild is already available: $(which rpmbuild)"
|
||||
fi
|
||||
|
||||
- name: Run Test Suite
|
||||
run: |
|
||||
echo "=== Running Unit Tests ==="
|
||||
python3 -m unittest discover tests
|
||||
|
||||
- name: Build Distribution Packages
|
||||
run: |
|
||||
echo "=== Building Packages (.rpm, .deb, .tar.gz) ==="
|
||||
python3 packaging/build_packages.py
|
||||
echo "=== Built Artifacts in dist/ ==="
|
||||
ls -lh dist/*.tar.gz dist/*.deb 2>/dev/null || true
|
||||
ls -lh dist/*.rpm 2>/dev/null || true
|
||||
ls -lh dist/rpm/RPMS/*/*.rpm 2>/dev/null || true
|
||||
|
||||
- name: Publish to Gitea Package Registry
|
||||
env:
|
||||
PKG_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
echo "=== Publishing to Gitea Package Registry ==="
|
||||
RPM_FILE=$(find dist -maxdepth 2 -name "*.rpm" 2>/dev/null | head -n 1)
|
||||
DEB_FILE=$(ls dist/*.deb 2>/dev/null | head -n 1)
|
||||
|
||||
if [ -n "$RPM_FILE" ] && [ -f "$RPM_FILE" ]; then
|
||||
echo "Uploading RPM: $RPM_FILE"
|
||||
HTTP_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" -X PUT \
|
||||
-u "${{ github.actor }}:${PKG_TOKEN}" \
|
||||
--upload-file "$RPM_FILE" \
|
||||
"${{ github.server_url }}/api/packages/${{ github.repository_owner }}/rpm/upload")
|
||||
echo "RPM Registry HTTP status: $HTTP_CODE"
|
||||
fi
|
||||
|
||||
if [ -n "$DEB_FILE" ] && [ -f "$DEB_FILE" ]; then
|
||||
echo "Uploading DEB: $DEB_FILE"
|
||||
HTTP_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" -X PUT \
|
||||
-u "${{ github.actor }}:${PKG_TOKEN}" \
|
||||
--upload-file "$DEB_FILE" \
|
||||
"${{ github.server_url }}/api/packages/${{ github.repository_owner }}/debian/pool/stable/main/upload")
|
||||
echo "Debian Registry HTTP status: $HTTP_CODE"
|
||||
fi
|
||||
|
||||
# Link packages to this repository in Gitea
|
||||
REPO_NAME=$(basename "${{ github.repository }}")
|
||||
echo "Linking RPM package 'inventory-collector' 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/inventory-collector/-/link/${REPO_NAME}")
|
||||
echo "RPM link result: $LINK_RPM"
|
||||
|
||||
echo "Linking Debian package 'inventory-collector' 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/inventory-collector/-/link/${REPO_NAME}")
|
||||
echo "Debian link result: $LINK_DEB"
|
||||
|
||||
- name: Attach Artifacts to Gitea Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
REPO: ${{ github.repository }}
|
||||
TAG_REF: ${{ github.ref_name }}
|
||||
run: |
|
||||
echo "=== Attaching Assets to Release ==="
|
||||
# Determine tag name (default to package version if workflow_dispatch on branch)
|
||||
TAG="${TAG_REF}"
|
||||
if [[ "$TAG" == "main" || "$TAG" == "" ]]; then
|
||||
VER=$(python3 -c "import inventory_collector; print(inventory_collector.__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': 'Release ' + sys.argv[1], 'body': 'Automated build and release for ' + sys.argv[1]}))" "$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 (ensures idempotency on re-runs)
|
||||
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 (exclude internal rpm SOURCES and SRPMS)
|
||||
ASSET_FILES=(
|
||||
$(ls dist/*.tar.gz 2>/dev/null || true)
|
||||
$(ls dist/*.deb 2>/dev/null || true)
|
||||
$(ls dist/*.rpm 2>/dev/null || true)
|
||||
$(ls dist/rpm/RPMS/*/*.rpm 2>/dev/null || true)
|
||||
)
|
||||
|
||||
# Deduplicate list
|
||||
declare -A SEEN
|
||||
for f in "${ASSET_FILES[@]}"; do
|
||||
if [ -f "$f" ]; then
|
||||
fname=$(basename "$f")
|
||||
if [[ -z "${SEEN[$fname]:-}" ]]; then
|
||||
SEEN[$fname]=1
|
||||
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
|
||||
fi
|
||||
done
|
||||
echo "Artifacts successfully attached to release $TAG!"
|
||||
else
|
||||
echo "Could not obtain release ID, skipping asset attachment."
|
||||
fi
|
||||
Reference in new issue
Block a user