From 0b98dbb11f99915e79aa5ac88b6eb4fb98389675 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 3 Oct 2025 18:45:55 +0200 Subject: [PATCH] change to zipping --- .gitea/workflows/release.yml | 62 +++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 0ee4520..99d3728 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -14,10 +14,14 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Ensure zip is available + - name: Ensure tools are available (zip, curl, jq) run: | - if ! command -v zip >/dev/null 2>&1; then - sudo apt-get update && sudo apt-get install -y zip + need_install=false + for b in zip curl jq; do + if ! command -v "$b" >/dev/null 2>&1; then need_install=true; fi + done + if [ "$need_install" = true ]; then + sudo apt-get update && sudo apt-get install -y zip curl jq ca-certificates fi - name: Zip and SHA1 @@ -32,13 +36,49 @@ jobs: echo "ZIP_PATH=${ZIP_NAME}" >> "$GITHUB_ENV" echo "SHA1_PATH=${ZIP_NAME}.sha1" >> "$GITHUB_ENV" - - name: Release (Forgejo/Gitea) - uses: https://gitea.com/actions/forgejo-release@v1 + - name: Create Release and Upload Assets (Gitea API) env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - with: - direction: upload - tag: ${{ github.ref_name }} - files: | - ${{ env.ZIP_PATH }} - ${{ env.SHA1_PATH }} + run: | + set -euo pipefail + : "${GITEA_TOKEN:?Missing GITEA_TOKEN secret}" + TAG="${GITHUB_REF_NAME:-dev}" + OWNER="${GITHUB_REPOSITORY%/*}" + REPO="${GITHUB_REPOSITORY##*/}" + API_BASE="${GITHUB_SERVER_URL%/}/api/v1" + + echo "Creating or fetching release for tag: $TAG" + create_json=$(jq -n --arg tag "$TAG" --arg name "$TAG" --arg target "${GITHUB_SHA:-}" '{tag_name:$tag, name:$name, target_commitish:$target, draft:false, prerelease:false}') + # Try to create the release + set +e + resp=$(curl -sS -w "\n%{http_code}" -H "Authorization: token ${GITEA_TOKEN}" -H 'Content-Type: application/json' \ + -X POST "${API_BASE}/repos/${OWNER}/${REPO}/releases" -d "$create_json") + http_code=$(echo "$resp" | tail -n1) + body=$(echo "$resp" | head -n-1) + set -e + if [ "$http_code" = "201" ] || [ "$http_code" = "200" ]; then + release_id=$(echo "$body" | jq -r '.id') + else + # If already exists, fetch by tag + body=$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" "${API_BASE}/repos/${OWNER}/${REPO}/releases/tags/${TAG}") + release_id=$(echo "$body" | jq -r '.id') + if [ -z "$release_id" ] || [ "$release_id" = "null" ]; then + echo "Failed to create or fetch release (HTTP $http_code)" >&2 + echo "$body" >&2 + exit 1 + fi + fi + echo "Release ID: $release_id" + + # Upload assets; remove existing with same name if present + for path in "$ZIP_PATH" "$SHA1_PATH"; do + name=$(basename "$path") + assets=$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" "${API_BASE}/repos/${OWNER}/${REPO}/releases/${release_id}/assets") + existing_id=$(echo "$assets" | jq -r ".[] | select(.name==\"${name}\") | .id" || true) + if [ -n "${existing_id:-}" ] && [ "${existing_id}" != "null" ]; then + curl -sS -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API_BASE}/repos/${OWNER}/${REPO}/releases/assets/${existing_id}" >/dev/null || true + fi + curl -sS -H "Authorization: token ${GITEA_TOKEN}" -F "attachment=@${path}" -F "name=${name}" \ + "${API_BASE}/repos/${OWNER}/${REPO}/releases/${release_id}/assets" >/dev/null + echo "Uploaded ${name}" + done