From 57c0c2ba3d93a1f1b155890f360625acc43d83bf Mon Sep 17 00:00:00 2001 From: Torsten Date: Sat, 25 Apr 2026 15:36:33 +0000 Subject: [PATCH] Dateien nach ".gitea/workflows" hochladen --- .gitea/workflows/release-from-tag.yml | 136 ++++++++++++++++++++++++++ .gitea/workflows/tag-from-toc.yml | 66 +++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 .gitea/workflows/release-from-tag.yml create mode 100644 .gitea/workflows/tag-from-toc.yml diff --git a/.gitea/workflows/release-from-tag.yml b/.gitea/workflows/release-from-tag.yml new file mode 100644 index 0000000..4b38fd1 --- /dev/null +++ b/.gitea/workflows/release-from-tag.yml @@ -0,0 +1,136 @@ +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}" \ No newline at end of file diff --git a/.gitea/workflows/tag-from-toc.yml b/.gitea/workflows/tag-from-toc.yml new file mode 100644 index 0000000..92493ec --- /dev/null +++ b/.gitea/workflows/tag-from-toc.yml @@ -0,0 +1,66 @@ +name: Tag from TOC Version + +on: + push: + branches: + - main + +jobs: + tag: + runs-on: debian-12 + + steps: + - name: Tools installieren + run: | + apt-get update + apt-get install -y git grep sed + + - name: Repo klonen + run: | + rm -rf /tmp/repo + git clone http://oauth2:${{ secrets.PAT_TOKEN }}@10.10.2.140:3000/Torsten/HailMaryGuildTools.git /tmp/repo + + - name: Version aus TOC lesen + run: | + set -e + cd /tmp/repo + + TOC_FILE="HailMaryGuildTools.toc" + + if [ ! -f "$TOC_FILE" ]; then + echo "TOC-Datei nicht gefunden: $TOC_FILE" + exit 1 + fi + + VERSION=$(grep '^## Version:' "$TOC_FILE" | sed 's/^## Version:[[:space:]]*//') + + if [ -z "$VERSION" ]; then + echo "Keine Version in $TOC_FILE gefunden" + exit 1 + fi + + TAG="v$VERSION" + + echo "Gefundene Version: $VERSION" + echo "Neues Tag wäre: $TAG" + + echo "$TAG" > /tmp/release_tag.txt + + - name: Tag nur erstellen, wenn noch nicht vorhanden + run: | + set -e + cd /tmp/repo + + git fetch --tags + TAG=$(cat /tmp/release_tag.txt) + + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "Tag $TAG existiert bereits, nichts zu tun." + exit 0 + fi + + git config user.name "Gitea Actions" + git config user.email "actions@local" + + git tag "$TAG" + git push origin "$TAG" \ No newline at end of file