fix(ci): delegate Gitea release asset publishing to standalone python script
Build and Publish Release / test-and-release (push) Successful in 42s
Build and Publish Release / test-and-release (push) Successful in 42s
This commit is contained in:
1 parent
2462bdf097
commit
d18db76441
2 files changed
+120
-66
No files matched your search
@@ -40,16 +40,6 @@ jobs:
|
||||
echo "[INFO] Building .tar.gz, .deb, and .rpm distribution packages..."
|
||||
rm -rf dist
|
||||
python3 packaging/build_packages.py --all --out-dir dist
|
||||
|
||||
TAR_FILE=$(find dist -maxdepth 1 -name "*.tar.gz" | head -n 1)
|
||||
DEB_FILE=$(find dist -maxdepth 1 -name "*.deb" | head -n 1)
|
||||
RPM_FILE=$(find dist -maxdepth 1 -name "*.rpm" | head -n 1)
|
||||
|
||||
echo "TAR_FILE=$TAR_FILE" >> $GITHUB_ENV
|
||||
echo "DEB_FILE=$DEB_FILE" >> $GITHUB_ENV
|
||||
echo "RPM_FILE=$RPM_FILE" >> $GITHUB_ENV
|
||||
|
||||
echo "[INFO] Generated packages:"
|
||||
ls -lh dist/
|
||||
|
||||
- name: Publish to Gitea Package Registry
|
||||
@@ -61,26 +51,25 @@ jobs:
|
||||
REPO="${{ github.event.repository.name }}"
|
||||
SERVER="${{ github.server_url }}"
|
||||
|
||||
# Upload RPM
|
||||
RPM_FILE=$(find dist -maxdepth 1 -name "*.rpm" | head -n 1)
|
||||
DEB_FILE=$(find dist -maxdepth 1 -name "*.deb" | head -n 1)
|
||||
|
||||
if [[ -f "$RPM_FILE" ]]; then
|
||||
echo "[INFO] Publishing RPM to registry..."
|
||||
curl -k -s -f -X PUT -u "${{ github.actor }}:${PKG_TOKEN}" \
|
||||
--upload-file "$RPM_FILE" \
|
||||
"${SERVER}/api/packages/${OWNER}/rpm/upload" || echo "[WARNING] RPM upload returned non-zero (may already exist)"
|
||||
|
||||
# Link package to repository
|
||||
curl -k -s -X POST -H "Authorization: token ${PKG_TOKEN}" \
|
||||
"${SERVER}/api/v1/packages/${OWNER}/rpm/linux-backuper/-/link/${REPO}" || true
|
||||
fi
|
||||
|
||||
# Upload Debian
|
||||
if [[ -f "$DEB_FILE" ]]; then
|
||||
echo "[INFO] Publishing Debian to registry..."
|
||||
curl -k -s -f -X PUT -u "${{ github.actor }}:${PKG_TOKEN}" \
|
||||
--upload-file "$DEB_FILE" \
|
||||
"${SERVER}/api/packages/${OWNER}/debian/pool/stable/main/upload" || echo "[WARNING] DEB upload returned non-zero (may already exist)"
|
||||
|
||||
# Link package to repository
|
||||
curl -k -s -X POST -H "Authorization: token ${PKG_TOKEN}" \
|
||||
"${SERVER}/api/v1/packages/${OWNER}/debian/linux-backuper/-/link/${REPO}" || true
|
||||
fi
|
||||
@@ -90,55 +79,4 @@ jobs:
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.PACKAGES_GENERATION || secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||
OWNER="${{ github.repository_owner }}"
|
||||
REPO="${{ github.event.repository.name }}"
|
||||
API_URL="${{ github.server_url }}/api/v1/repos/${OWNER}/${REPO}"
|
||||
|
||||
echo "[INFO] Ensuring Gitea Release exists for tag ${TAG_NAME}..."
|
||||
REL_INFO=$(curl -k -s -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/tags/${TAG_NAME}")
|
||||
REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$REL_INFO" 2>/dev/null || true)
|
||||
|
||||
if [[ -z "$REL_ID" || "$REL_ID" == "null" ]]; then
|
||||
echo "[INFO] Creating release for tag ${TAG_NAME}..."
|
||||
CREATE_PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"tag_name": "${TAG_NAME}",
|
||||
"name": "linux-backuper ${TAG_NAME}",
|
||||
"body": "Automated release of linux-backuper.\\n\\nIncludes:\\n- Native Debian package (.deb)\\n- Native Red Hat / Fedora package (.rpm)\\n- Universal standalone archive (.tar.gz)",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
NEW_REL=$(curl -k -s -X POST -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$CREATE_PAYLOAD" \
|
||||
"${API_URL}/releases")
|
||||
REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$NEW_REL" 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
echo "[INFO] Release ID: ${REL_ID}"
|
||||
|
||||
# Idempotently upload assets
|
||||
for FPATH in "$TAR_FILE" "$DEB_FILE" "$RPM_FILE"; do
|
||||
if [[ -f "$FPATH" ]]; then
|
||||
FNAME=$(basename "$FPATH")
|
||||
echo "[INFO] Uploading asset: ${FNAME}..."
|
||||
|
||||
# Delete existing asset with same name if present
|
||||
EXISTING_ASSETS=$(curl -k -s -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets" || echo "[]")
|
||||
ASSET_ID=$(python3 -c "import sys, json; assets=json.loads(sys.argv[1]) if sys.argv[1] else []; fname=sys.argv[2]; print(next((str(a['id']) for a in assets if isinstance(a, dict) and a.get('name') == fname), ''))" "$EXISTING_ASSETS" "$FNAME" 2>/dev/null || true)
|
||||
if [[ -n "$ASSET_ID" ]]; then
|
||||
echo "[INFO] Deleting existing asset ${FNAME} (ID: ${ASSET_ID})..."
|
||||
curl -k -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets/${ASSET_ID}" || true
|
||||
fi
|
||||
|
||||
# Upload asset
|
||||
curl -k -s -X POST -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"$FPATH" \
|
||||
"${API_URL}/releases/${REL_ID}/assets?name=${FNAME}"
|
||||
fi
|
||||
done
|
||||
echo "[SUCCESS] Release publishing complete."
|
||||
python3 packaging/publish_release.py
|
||||
Reference in new issue
Block a user