fix: correct Gitea Actions release workflow
- Use gitea.ref/server_url/repository context vars instead of GitHub env vars - Move API_URL and REPO into env: block so context expressions are evaluated - Pass gitea.ref via env: for version extraction (GITEA_REF) - Replace grep/cut JSON parsing with jq throughout - Fix tag creation body: use 'target' key instead of 'message' - Add set -euo pipefail and diagnostic echo output to both run blocks - Add null check on jq-parsed RELEASE_ID in publish-release
This commit is contained in:
@@ -8,7 +8,7 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
tag: ${{ steps.version.outputs.tag }}
|
||||
@@ -31,9 +31,11 @@ jobs:
|
||||
|
||||
- name: Get version
|
||||
id: version
|
||||
env:
|
||||
GITEA_REF: ${{ gitea.ref }}
|
||||
run: |
|
||||
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
echo "version=${GITEA_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
echo "tag=${GITEA_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
@@ -56,29 +58,37 @@ jobs:
|
||||
- name: Upsert rolling 'release' tag with latest update.json
|
||||
env:
|
||||
GITEA_TOKEN: ${{ gitea.token }}
|
||||
API_URL: ${{ gitea.server_url }}/api/v1
|
||||
REPO: ${{ gitea.repository }}
|
||||
VERSION: ${{ needs.build.outputs.version }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="release"
|
||||
REPO="${GITHUB_REPOSITORY}"
|
||||
API_URL="${GITEA_SERVER_URL}/api/v1"
|
||||
VERSION="${{ needs.build.outputs.version }}"
|
||||
|
||||
echo "=== Configuration ==="
|
||||
echo "API_URL: ${API_URL}"
|
||||
echo "REPO: ${REPO}"
|
||||
echo "VERSION: ${VERSION}"
|
||||
|
||||
# Check if the rolling release already exists
|
||||
EXISTING=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||
"${API_URL}/repos/${REPO}/releases/tags/${TAG}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}")
|
||||
|
||||
echo "Existing release check: HTTP ${EXISTING}"
|
||||
|
||||
if [ "${EXISTING}" = "200" ]; then
|
||||
# Fetch the release ID
|
||||
RELEASE_ID=$(curl -s "${API_URL}/repos/${REPO}/releases/tags/${TAG}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
| jq -r '.id')
|
||||
|
||||
echo "Found existing 'release' release (ID: ${RELEASE_ID}). Replacing assets..."
|
||||
|
||||
# Delete all existing assets so we can upload fresh ones
|
||||
ASSETS=$(curl -s "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}")
|
||||
echo "${ASSETS}" | grep -o '"id":[0-9]*' | cut -d: -f2 | while read ASSET_ID; do
|
||||
echo "${ASSETS}" | jq -r '.[].id' | while read -r ASSET_ID; do
|
||||
echo "Deleting asset ${ASSET_ID}..."
|
||||
curl -s -X DELETE "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}"
|
||||
@@ -98,7 +108,7 @@ jobs:
|
||||
curl -s -X POST "${API_URL}/repos/${REPO}/tags" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\": \"${TAG}\", \"message\": \"Rolling release tag for update.json hosting\"}" || true
|
||||
-d "{\"tag_name\": \"${TAG}\", \"target\": \"main\"}" || true
|
||||
|
||||
RELEASE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
@@ -111,9 +121,9 @@ jobs:
|
||||
\"prerelease\": false
|
||||
}")
|
||||
|
||||
RELEASE_ID=$(echo "${RELEASE}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
RELEASE_ID=$(echo "${RELEASE}" | jq -r '.id')
|
||||
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||
echo "Failed to create rolling release. Response: ${RELEASE}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -148,11 +158,18 @@ jobs:
|
||||
- name: Create versioned release and upload assets
|
||||
env:
|
||||
GITEA_TOKEN: ${{ gitea.token }}
|
||||
API_URL: ${{ gitea.server_url }}/api/v1
|
||||
REPO: ${{ gitea.repository }}
|
||||
VERSION: ${{ needs.build.outputs.version }}
|
||||
TAG: ${{ needs.build.outputs.tag }}
|
||||
run: |
|
||||
VERSION="${{ needs.build.outputs.version }}"
|
||||
TAG="${{ needs.build.outputs.tag }}"
|
||||
REPO="${GITHUB_REPOSITORY}"
|
||||
API_URL="${GITEA_SERVER_URL}/api/v1"
|
||||
set -euo pipefail
|
||||
|
||||
echo "=== Configuration ==="
|
||||
echo "API_URL: ${API_URL}"
|
||||
echo "REPO: ${REPO}"
|
||||
echo "VERSION: ${VERSION}"
|
||||
echo "TAG: ${TAG}"
|
||||
|
||||
# Create the versioned release
|
||||
RELEASE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
||||
@@ -166,9 +183,9 @@ jobs:
|
||||
\"prerelease\": false
|
||||
}")
|
||||
|
||||
RELEASE_ID=$(echo "${RELEASE}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
RELEASE_ID=$(echo "${RELEASE}" | jq -r '.id')
|
||||
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||
echo "Failed to create release. Response: ${RELEASE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user