From e48317d60c979c747e238239b7a3afb3276212be Mon Sep 17 00:00:00 2001 From: rogueking Date: Sat, 20 Jun 2026 11:23:28 -0400 Subject: [PATCH] upload iso as a release --- .gitea/workflows/iso-builder.yml | 73 ++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/iso-builder.yml b/.gitea/workflows/iso-builder.yml index 020f8b6..adb6002 100644 --- a/.gitea/workflows/iso-builder.yml +++ b/.gitea/workflows/iso-builder.yml @@ -14,8 +14,8 @@ on: - .gitea/workflows/iso-builder.yml workflow_dispatch: inputs: - upload-artifact: - description: "Upload the ISOs as artifacts" + publish-release: + description: "Publish the ISOs as a Gitea release" type: boolean default: true @@ -98,13 +98,62 @@ jobs: sha256sum "$ISO_NAME" echo "::endgroup::" - - name: Upload ${{ matrix.host }} ISO artifact - if: ${{ github.event_name != 'workflow_dispatch' || inputs.upload-artifact }} - uses: https://github.com/christopherHX/gitea-upload-artifact@v4 - with: - name: ${{ matrix.host }}-installer-iso - # Point directly at the .iso file so the artifact contains a single - # file (not a directory of files that gets zipped together). - path: ${{ matrix.host }}-installer.iso - if-no-files-found: error - compression-level: 0 + - name: Publish ${{ matrix.host }} ISO as a Gitea release + if: ${{ github.event_name != 'workflow_dispatch' || inputs.publish-release }} + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + + ISO="${{ matrix.host }}-installer.iso" + if [ ! -f "$ISO" ]; then + echo "::error::$ISO not found in workspace" + ls -la + exit 1 + fi + + API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}" + AUTH="Authorization: token ${GITEA_TOKEN}" + + # Pick a release tag. Use the pushed tag for tag-triggered runs; + # otherwise generate a unique CI tag so re-runs don't collide. + if [ "${GITHUB_REF:-}" = "refs/tags/${GITHUB_REF_NAME:-}" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then + TAG="$GITHUB_REF_NAME" + PRERELEASE="false" + else + SHORT_SHA="${GITHUB_SHA:0:12}" + TAG="ci-${{ matrix.host }}-${SHORT_SHA}-${GITHUB_RUN_NUMBER}" + PRERELEASE="true" + fi + echo "Release tag: $TAG (prerelease=$PRERELEASE)" + + # Create the release. If it already exists (re-run), fall back to lookup. + RELEASE_ID=$(curl -fsS -X POST "$API/releases" \ + -H "$AUTH" -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"$TAG\",\"name\":\"${{ matrix.host }} ISO $TAG\",\"body\":\"Automated ISO build for ${{ matrix.host }}.\\n\\nCommit: ${GITHUB_SHA}\\nRun: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\",\"prerelease\":$PRERELEASE}" \ + | jq -r '.id') || RELEASE_ID="" + + if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then + RELEASE_ID=$(curl -fsS "$API/releases/tags/$TAG" -H "$AUTH" | jq -r '.id') + fi + if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then + echo "::error::Could not create or find release for tag $TAG" + exit 1 + fi + echo "Release ID: $RELEASE_ID" + + # Remove any existing asset with the same name so re-runs succeed. + curl -fsS "$API/releases/$RELEASE_ID/assets" -H "$AUTH" \ + | jq -r ".[] | select(.name == \"$ISO\") | .id" \ + | while read -r aid; do + curl -fsS -X DELETE "$API/releases/$RELEASE_ID/assets/$aid" -H "$AUTH" || true + done + + # Attach the ISO as a release asset (multipart form, Gitea-compatible). + curl -fsS -X POST "$API/releases/$RELEASE_ID/assets?name=$ISO" \ + -H "$AUTH" \ + -F "attachment=@$ISO;type=application/octet-stream" \ + -o /dev/null + + echo "::notice::Published $ISO to release $TAG" + echo "::notice::Download: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/download/$TAG/$ISO"