upload iso as a release
Build NixOS ISOs / build-iso (buildbox) (push) Failing after 2s

This commit is contained in:
2026-06-20 11:56:15 -04:00
parent 18a84dbf38
commit ec42eed3e3
+19 -136
View File
@@ -98,141 +98,24 @@ jobs:
sha256sum "$ISO_NAME"
echo "::endgroup::"
- name: Pick release tag
id: tag
if: ${{ github.event_name != 'workflow_dispatch' || inputs.publish-release }}
run: |
if [ "${GITHUB_REF:-}" = "refs/tags/${GITHUB_REF_NAME:-}" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
echo "tag=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "tag=ci-${{ matrix.host }}-${GITHUB_SHA:0:12}-${GITHUB_RUN_NUMBER}" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi
- name: Publish ${{ matrix.host }} ISO as a Gitea release
if: ${{ github.event_name != 'workflow_dispatch' || inputs.publish-release }}
env:
GITEA_TOKEN: ${{ secrets.UPLOAD_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
# Strip any trailing slash from GITHUB_SERVER_URL so we don't end up
# with a double-slash in the API path.
SERVER_URL="${GITHUB_SERVER_URL%/}"
API="${SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
# Gitea accepts both `token <token>` and `Bearer <token>`; the
# auto-injected GITHUB_TOKEN works with the `token` scheme.
AUTH="Authorization: token ${GITEA_TOKEN}"
echo "API base: $API"
echo "Repo: $GITHUB_REPOSITORY"
# Sanity-check auth + reachability with a single authenticated GET.
# Print status + first chunk of body so failures are visible.
http_code=$(curl -sS -o /tmp/api-check.body -w '%{http_code}' \
-H "$AUTH" "$API" || true)
echo "GET $API -> HTTP $http_code"
if [ "$http_code" != "200" ]; then
echo "::error::Auth/reachability check failed (HTTP $http_code). Response body:"
head -c 2000 /tmp/api-check.body || true
echo
exit 1
fi
# 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)"
# Helper: parse the id field from a JSON body, returning "" on any error.
extract_id() {
local body
body=$(cat)
if [ -z "$body" ]; then
echo " (extract_id: empty body)" >&2
return 0
fi
# Print the id; suppress jq errors so non-JSON bodies don't abort.
local id
id=$(printf '%s' "$body" | jq -r '.id // empty' 2>/dev/null || true)
if [ -z "$id" ]; then
echo " (extract_id: no .id field; body starts with:)" >&2
printf '%s' "$body" | head -c 300 >&2
echo >&2
fi
printf '%s' "$id"
}
# Create the release. Capture status + body separately so we can
# diagnose non-JSON responses instead of feeding them to jq blindly.
http_code=$(curl -sS -o /tmp/release-create.body -w '%{http_code}' \
-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: ${SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\",\"prerelease\":$PRERELEASE}" \
|| true)
echo "POST $API/releases -> HTTP $http_code"
echo " create body size: $(wc -c < /tmp/release-create.body 2>/dev/null || echo 0) bytes"
RELEASE_ID=""
if [ "$http_code" = "201" ] || [ "$http_code" = "200" ]; then
RELEASE_ID=$(extract_id < /tmp/release-create.body)
echo " parsed RELEASE_ID from create: '${RELEASE_ID}'"
else
# Common case: tag already exists from a prior run. Show the body
# for any other error so it's debuggable.
echo "Create response body (first 2000 bytes):"
head -c 2000 /tmp/release-create.body || true
echo
fi
# Fall back to looking up an existing release by tag.
if [ -z "$RELEASE_ID" ]; then
http_code=$(curl -sS -o /tmp/release-lookup.body -w '%{http_code}' \
-H "$AUTH" "$API/releases/tags/$TAG" || true)
echo "GET $API/releases/tags/$TAG -> HTTP $http_code"
echo " lookup body size: $(wc -c < /tmp/release-lookup.body 2>/dev/null || echo 0) bytes"
if [ "$http_code" = "200" ]; then
RELEASE_ID=$(extract_id < /tmp/release-lookup.body)
echo " parsed RELEASE_ID from lookup: '${RELEASE_ID}'"
else
echo "Lookup response body (first 2000 bytes):"
head -c 2000 /tmp/release-lookup.body || true
echo
fi
fi
if [ -z "$RELEASE_ID" ]; 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.
http_code=$(curl -sS -o /tmp/assets.body -w '%{http_code}' \
-H "$AUTH" "$API/releases/$RELEASE_ID/assets" || true)
if [ "$http_code" = "200" ]; then
jq -r ".[] | select(.name == \"$ISO\") | .id" /tmp/assets.body 2>/dev/null \
| while read -r aid; do
curl -fsS -X DELETE "$API/releases/$RELEASE_ID/assets/$aid" \
-H "$AUTH" || true
done
fi
# Attach the ISO as a release asset (multipart form, Gitea-compatible).
http_code=$(curl -sS -o /tmp/asset-upload.body -w '%{http_code}' \
-X POST "$API/releases/$RELEASE_ID/assets?name=$ISO" \
-H "$AUTH" \
-F "attachment=@$ISO;type=application/octet-stream" \
|| true)
echo "POST .../assets?name=$ISO -> HTTP $http_code"
if [ "$http_code" != "201" ] && [ "$http_code" != "200" ]; then
echo "::error::Asset upload failed (HTTP $http_code). Response body:"
head -c 2000 /tmp/asset-upload.body || true
echo
exit 1
fi
echo "::notice::Published $ISO to release $TAG"
echo "::notice::Download: ${SERVER_URL}/${GITHUB_REPOSITORY}/releases/download/$TAG/$ISO"
uses: actions/gitea-release-action@v1
with:
token: ${{ secrets.UPLOAD_TOKEN }}
tag_name: ${{ steps.tag.outputs.tag }}
name: ${{ matrix.host }} ISO ${{ steps.tag.outputs.tag }}
prerelease: ${{ steps.tag.outputs.prerelease }}
files: ${{ matrix.host }}-installer.iso