ci: handle existing release in workflow
This commit is contained in:
parent
6d01888c85
commit
ef0cec7f9f
1 changed files with 11 additions and 2 deletions
|
|
@ -74,17 +74,26 @@ jobs:
|
||||||
VERSION=${{ github.ref_name }}
|
VERSION=${{ github.ref_name }}
|
||||||
API="${FORGEJO_URL}/api/v1/repos/seth/Caddyview"
|
API="${FORGEJO_URL}/api/v1/repos/seth/Caddyview"
|
||||||
|
|
||||||
|
# Try to create release; if it already exists, fetch the existing one.
|
||||||
RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-X POST \
|
-X POST \
|
||||||
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
|
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
|
||||||
"${API}/releases")
|
"${API}/releases")
|
||||||
|
|
||||||
echo "Release response: ${RELEASE_JSON}"
|
echo "Create release response: ${RELEASE_JSON}"
|
||||||
RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
|
||||||
if [ -z "${RELEASE_ID}" ]; then
|
if [ -z "${RELEASE_ID}" ]; then
|
||||||
echo "Failed to create release"
|
echo "Release may already exist, fetching existing release..."
|
||||||
|
EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
"${API}/releases/tags/${VERSION}")
|
||||||
|
echo "Existing release response: ${EXISTING}"
|
||||||
|
RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ]; then
|
||||||
|
echo "Failed to create or fetch release"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue