forked from Solo-Web-Works/Projects-Portfolio
Call Gitea REST API directly for releases (Gitea Actions compat)
This commit is contained in:
@@ -69,12 +69,64 @@ jobs:
|
|||||||
path: dist/projects-portfolio-*.zip
|
path: dist/projects-portfolio-*.zip
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: Create GitHub release
|
- name: Create release
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
TAG: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
gh release create "$GITHUB_REF_NAME" \
|
if [ -z "${GITEA_TOKEN:-}" ]; then
|
||||||
--title "$GITHUB_REF_NAME" \
|
echo "::error::GITEA_TOKEN secret is not set. Create a personal access token in Gitea with 'write:repository' scope and add it as a repository secret named GITEA_TOKEN." >&2
|
||||||
--generate-notes \
|
exit 1
|
||||||
dist/projects-portfolio-*.zip
|
fi
|
||||||
|
|
||||||
|
API="https://git.keithsolomon.net/api/v1"
|
||||||
|
|
||||||
|
# Build the JSON payload with python (no jq dependency).
|
||||||
|
payload=$(TAG="$TAG" python3 -c '
|
||||||
|
import json, os, sys
|
||||||
|
tag = os.environ["TAG"]
|
||||||
|
body = (
|
||||||
|
"Automated release.\n\n"
|
||||||
|
"Built from commit " + os.environ.get("GITHUB_SHA", "unknown") + ".\n\n"
|
||||||
|
"See the workflow run for the artifact."
|
||||||
|
)
|
||||||
|
print(json.dumps({
|
||||||
|
"tag_name": tag,
|
||||||
|
"name": tag,
|
||||||
|
"body": body,
|
||||||
|
"draft": False,
|
||||||
|
"prerelease": False,
|
||||||
|
}))
|
||||||
|
')
|
||||||
|
|
||||||
|
# 1. Create the release (Gitea doesn't auto-generate notes).
|
||||||
|
release_json=$(curl -fsS -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload" \
|
||||||
|
"${API}/repos/${REPO}/releases")
|
||||||
|
|
||||||
|
# 2. Extract the release id (Gitea returns the full release object).
|
||||||
|
release_id=$(TAG="$TAG" python3 -c '
|
||||||
|
import json, sys
|
||||||
|
data = json.loads(sys.stdin.read())
|
||||||
|
print(data.get("id", ""))
|
||||||
|
' <<<"$release_json")
|
||||||
|
|
||||||
|
if [ -z "$release_id" ]; then
|
||||||
|
echo "::error::Failed to create release. Response: $release_json" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Created release id=$release_id"
|
||||||
|
|
||||||
|
# 3. Upload the zip as a release asset.
|
||||||
|
zip_path=( dist/projects-portfolio-*.zip )
|
||||||
|
zip_path="${zip_path[0]}"
|
||||||
|
curl -fsS -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/zip" \
|
||||||
|
--data-binary "@${zip_path}" \
|
||||||
|
"${API}/repos/${REPO}/releases/${release_id}/assets?name=$(basename "$zip_path")"
|
||||||
|
echo "Uploaded asset: $(basename "$zip_path")"
|
||||||
|
|||||||
Reference in New Issue
Block a user