136 lines
4.2 KiB
YAML
136 lines
4.2 KiB
YAML
name: Build Release ZIP
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: debian-12
|
|
|
|
steps:
|
|
- name: Tools installieren
|
|
run: |
|
|
set -e
|
|
apt-get update
|
|
apt-get install -y git zip curl jq rsync
|
|
|
|
- name: Variablen setzen
|
|
run: |
|
|
set -e
|
|
echo "REPO=${{ gitea.repository }}" >> "$GITHUB_ENV"
|
|
echo "TAG=${{ gitea.ref_name }}" >> "$GITHUB_ENV"
|
|
echo "SERVER_URL=https://git.local.unique-studios.de" >> "$GITHUB_ENV"
|
|
echo "API_BASE=https://git.local.unique-studios.de/api/v1" >> "$GITHUB_ENV"
|
|
|
|
- name: Repo klonen
|
|
run: |
|
|
set -e
|
|
rm -rf /tmp/repo /tmp/build /tmp/release.json /tmp/assets.json
|
|
|
|
git clone "https://oauth2:${{ secrets.PAT_TOKEN }}@git.local.unique-studios.de/${REPO}.git" /tmp/repo
|
|
|
|
- name: ZIP mit Addon-Ordner bauen
|
|
run: |
|
|
set -e
|
|
|
|
REPO_NAME="${REPO##*/}"
|
|
|
|
mkdir -p "/tmp/build/${REPO_NAME}"
|
|
|
|
rsync -a \
|
|
--exclude='.git' \
|
|
--exclude='.gitea' \
|
|
/tmp/repo/ "/tmp/build/${REPO_NAME}/"
|
|
|
|
cd /tmp/build
|
|
zip -r "/tmp/${REPO_NAME}-${TAG}.zip" "${REPO_NAME}"
|
|
ls -lh "/tmp/${REPO_NAME}-${TAG}.zip"
|
|
|
|
- name: Release anlegen oder laden
|
|
run: |
|
|
set -e
|
|
|
|
API="${API_BASE}/repos/${REPO}"
|
|
REPO_NAME="${REPO##*/}"
|
|
|
|
echo "Server: ${SERVER_URL}"
|
|
echo "Repo: ${REPO}"
|
|
echo "Tag: ${TAG}"
|
|
|
|
HTTP_CODE=$(curl -s -o /tmp/release.json -w "%{http_code}" \
|
|
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
|
|
-H "Accept: application/json" \
|
|
"${API}/releases/tags/${TAG}")
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
echo "Release existiert bereits."
|
|
elif [ "$HTTP_CODE" = "404" ]; then
|
|
echo "Release wird erstellt."
|
|
curl --fail -s \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
|
|
-H "Accept: application/json" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"name\": \"${REPO_NAME} ${TAG}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" \
|
|
"${API}/releases" > /tmp/release.json
|
|
else
|
|
echo "Unerwarteter HTTP-Code beim Laden des Releases: ${HTTP_CODE}"
|
|
cat /tmp/release.json || true
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release-Daten:"
|
|
jq '.id, .tag_name, .html_url' /tmp/release.json
|
|
|
|
- name: Vorhandenes Asset mit gleichem Namen löschen
|
|
run: |
|
|
set -e
|
|
|
|
RELEASE_ID=$(jq -r '.id' /tmp/release.json)
|
|
REPO_NAME="${REPO##*/}"
|
|
FILE_NAME="${REPO_NAME}-${TAG}.zip"
|
|
ASSET_API="${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets"
|
|
|
|
curl --fail -s \
|
|
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
|
|
-H "Accept: application/json" \
|
|
"${ASSET_API}" > /tmp/assets.json
|
|
|
|
ASSET_ID=$(jq -r ".[] | select(.name == \"${FILE_NAME}\") | .id" /tmp/assets.json | head -n1)
|
|
|
|
if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
|
|
echo "Vorhandenes Asset gefunden: ${ASSET_ID} -> wird gelöscht"
|
|
curl --fail -s \
|
|
-X DELETE \
|
|
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
|
|
-H "Accept: application/json" \
|
|
"${ASSET_API}/${ASSET_ID}"
|
|
else
|
|
echo "Kein vorhandenes Asset mit gleichem Namen gefunden."
|
|
fi
|
|
|
|
- name: ZIP an Release anhängen
|
|
run: |
|
|
set -e
|
|
|
|
RELEASE_ID=$(jq -r '.id' /tmp/release.json)
|
|
REPO_NAME="${REPO##*/}"
|
|
FILE="/tmp/${REPO_NAME}-${TAG}.zip"
|
|
FILE_NAME="$(basename "$FILE")"
|
|
UPLOAD_URL="${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILE_NAME}"
|
|
|
|
echo "Upload URL: ${UPLOAD_URL}"
|
|
|
|
curl --fail -v \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
|
|
-H "Accept: application/json" \
|
|
-F "attachment=@${FILE}" \
|
|
"${UPLOAD_URL}" |