CI: nightly release via Gitea API (no gh CLI)
Made-with: Cursor
This commit is contained in:
53
.github/workflows/build-and-release.yml
vendored
53
.github/workflows/build-and-release.yml
vendored
@@ -48,35 +48,64 @@ jobs:
|
|||||||
- name: Build zip package
|
- name: Build zip package
|
||||||
run: make zip
|
run: make zip
|
||||||
|
|
||||||
|
# Gitea has no `gh` CLI; use REST API (same host as checkout).
|
||||||
- name: Nightly release (single tag, updated in place)
|
- name: Nightly release (single tag, updated in place)
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG=nightly
|
TAG=nightly
|
||||||
ZIP="./output/OmniNX Downloader.zip"
|
ZIP="./output/OmniNX Downloader.zip"
|
||||||
REPO="${{ github.repository }}"
|
FULL="${{ github.repository }}"
|
||||||
|
OWNER="${FULL%%/*}"
|
||||||
|
REPO_NAME="${FULL#*/}"
|
||||||
SHA="${{ github.sha }}"
|
SHA="${{ github.sha }}"
|
||||||
REF="${{ github.ref_name }}"
|
REF="${{ github.ref_name }}"
|
||||||
|
API="${SERVER_URL%/}/api/v1"
|
||||||
|
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
git tag -f "$TAG"
|
git tag -f "$TAG"
|
||||||
git push origin "refs/tags/$TAG" --force
|
git push origin "refs/tags/$TAG" --force
|
||||||
|
|
||||||
NOTES="Single nightly build artifact (updated every push).
|
NOTES="Single nightly build artifact (updated on schedule or manual run).
|
||||||
|
|
||||||
**Commit:** \`${SHA}\`
|
**Commit:** \`${SHA}\`
|
||||||
**Branch:** \`${REF}\`
|
**Branch:** \`${REF}\`
|
||||||
**Built:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
|
**Built:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
|
||||||
|
|
||||||
if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
|
AUTH=(-H "Authorization: token ${GITHUB_TOKEN}")
|
||||||
gh release upload "$TAG" "$ZIP" --clobber --repo "$REPO"
|
|
||||||
gh release edit "$TAG" --title "Nightly" --notes "$NOTES" --prerelease --repo "$REPO"
|
# Remove existing release so we can recreate with a fresh attachment (Gitea has no clobber).
|
||||||
else
|
HTTP_CODE=$(curl -sS -o /tmp/gitea_rel.json -w "%{http_code}" "${AUTH[@]}" \
|
||||||
gh release create "$TAG" "$ZIP" \
|
"${API}/repos/${OWNER}/${REPO_NAME}/releases/tags/${TAG}")
|
||||||
--title "Nightly" \
|
if [ "$HTTP_CODE" = "200" ]; then
|
||||||
--notes "$NOTES" \
|
RID=$(python3 -c "import json; print(json.load(open('/tmp/gitea_rel.json'))['id'])")
|
||||||
--prerelease \
|
curl -sS -X DELETE "${AUTH[@]}" \
|
||||||
--repo "$REPO"
|
"${API}/repos/${OWNER}/${REPO_NAME}/releases/${RID}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export NOTES TAG
|
||||||
|
JSON_BODY=$(python3 <<'PY'
|
||||||
|
import json, os
|
||||||
|
print(json.dumps({
|
||||||
|
"tag_name": os.environ["TAG"],
|
||||||
|
"name": "Nightly",
|
||||||
|
"body": os.environ["NOTES"],
|
||||||
|
"draft": False,
|
||||||
|
"prerelease": True,
|
||||||
|
}))
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
curl -sS -f -X POST "${AUTH[@]}" -H "Content-Type: application/json" \
|
||||||
|
-d "$JSON_BODY" \
|
||||||
|
"${API}/repos/${OWNER}/${REPO_NAME}/releases" | tee /tmp/gitea_create.json
|
||||||
|
|
||||||
|
RID=$(python3 -c "import json; print(json.load(open('/tmp/gitea_create.json'))['id'])")
|
||||||
|
export ASSET_NAME="OmniNX Downloader.zip"
|
||||||
|
QNAME=$(python3 -c "import urllib.parse,os; print(urllib.parse.quote(os.environ['ASSET_NAME']))")
|
||||||
|
|
||||||
|
curl -sS -f -X POST "${AUTH[@]}" \
|
||||||
|
-F "attachment=@${ZIP};filename=${ASSET_NAME}" \
|
||||||
|
"${API}/repos/${OWNER}/${REPO_NAME}/releases/${RID}/assets?name=${QNAME}"
|
||||||
|
|||||||
Reference in New Issue
Block a user