Feat: Fügt Erstellung von Preview-Release und Upload von Assets im Dev-Workflow hinzu
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: Dev Build & Publish
|
name: Dev Build, Publish & Preview Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-publish:
|
build-and-publish:
|
||||||
name: Build and Publish Packages (Testing)
|
name: Build, Publish Packages (Testing) & Create Preview Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
@@ -75,3 +75,77 @@ jobs:
|
|||||||
--upload-file "$pkg" \
|
--upload-file "$pkg" \
|
||||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/arch/testing/upload"
|
"${GITEA_URL}/api/packages/${REPO_OWNER}/arch/testing/upload"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
- name: Create Gitea Preview Release and Upload Assets
|
||||||
|
env:
|
||||||
|
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
||||||
|
REPO: ${{ gitea.repository || github.repository }}
|
||||||
|
TOKEN: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
||||||
|
run: |
|
||||||
|
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
|
||||||
|
TAG_NAME="v${VERSION}-preview"
|
||||||
|
RELEASE_TITLE="Preview Release ${TAG_NAME}"
|
||||||
|
RELEASE_NOTES="Automatisches Preview-Release für docker-update ${VERSION} (Branch: dev)."
|
||||||
|
|
||||||
|
echo "Erstelle oder hole Preview-Release für Tag ${TAG_NAME} in ${REPO}..."
|
||||||
|
|
||||||
|
GET_RESP=$(curl -s -w "\n%{http_code}" \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}")
|
||||||
|
HTTP_CODE=$(echo "$GET_RESP" | tail -n1)
|
||||||
|
BODY=$(echo "$GET_RESP" | sed '$d')
|
||||||
|
|
||||||
|
RELEASE_ID=""
|
||||||
|
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||||
|
RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||||
|
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
|
||||||
|
else
|
||||||
|
echo "Erstelle neues Preview-Release ${TAG_NAME}..."
|
||||||
|
CREATE_PAYLOAD=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG_NAME}",
|
||||||
|
"target_commitish": "dev",
|
||||||
|
"name": "${RELEASE_TITLE}",
|
||||||
|
"body": "${RELEASE_NOTES}",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": true
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
CREATE_RESP=$(curl -f -s -S -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$CREATE_PAYLOAD" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases")
|
||||||
|
RELEASE_ID=$(echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||||
|
echo "Neues Preview-Release erstellt (ID: ${RELEASE_ID})."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Fehler: Release-ID konnte nicht ermittelt werden!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
EXISTING_ASSETS_JSON=$(curl -s \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" || echo "[]")
|
||||||
|
|
||||||
|
for file in target/debian/*.deb target/generate-rpm/*.rpm target/arch/*.pkg.tar.zst; do
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
filename="$(basename "$file")"
|
||||||
|
echo "Lade Release-Asset hoch: $filename"
|
||||||
|
|
||||||
|
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | grep -B2 "\"name\":\"${filename}\"" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2 || true)
|
||||||
|
if [ -n "$ASSET_ID" ]; then
|
||||||
|
echo "Lösche altes Asset mit ID ${ASSET_ID}..."
|
||||||
|
curl -s -X DELETE \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl -f -s -S -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-F "attachment=@${file}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${filename}"
|
||||||
|
echo "Asset ${filename} erfolgreich hochgeladen."
|
||||||
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user