Files
vcc-tools/.github/workflows/release.yml
2026-04-06 18:39:24 +02:00

90 lines
3.7 KiB
YAML

name: VCC Release Automation
on:
push:
tags:
- "v*" # Startet z.B. bei v1.0.3
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # Garantiert Rechte für Releases und Code-Pushes
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract Metadata
id: metadata
run: |
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
echo "pkg_name=$(jq -r .name package.json)" >> $GITHUB_OUTPUT
echo "display_name=$(jq -r .displayName package.json)" >> $GITHUB_OUTPUT
echo "description=$(jq -r .description package.json)" >> $GITHUB_OUTPUT
- name: Create VCC Package Zip
run: |
mkdir -p staging
cp package.json README.md staging/
cp -r Editor/ staging/
cp Editor.meta package.json.meta README.md.meta staging/ 2>/dev/null || true
cd staging
zip -r ../${{ steps.metadata.outputs.pkg_name }}-${{ github.ref_name }}.zip *
cd ..
echo "--- ZIP INHALT PRÜFUNG ---"
unzip -l ${{ steps.metadata.outputs.pkg_name }}-${{ github.ref_name }}.zip
- name: Upload GitHub Release Asset
uses: softprops/action-gh-release@v2
with:
files: ${{ steps.metadata.outputs.pkg_name }}-${{ github.ref_name }}.zip
- name: Update VCC Index
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Prüfen, ob der gh-pages Branch auf dem Server existiert
if git ls-remote --heads origin gh-pages | grep -q gh-pages; then
git checkout gh-pages
else
# Wenn nicht: Erstelle ihn als komplett leeren (orphan) Branch
git checkout --orphan gh-pages
git rm -rf . # Löscht alle Main-Dateien aus diesem Branch
fi
# Basis-Struktur der index.json erstellen, falls sie noch nicht existiert
if [ ! -f index.json ]; then
echo '{"name":"mrunknownde VCC Tools","id":"de.mrunknownde.vccrepo","url":"https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/index.json","author":"mrunknownde","packages":{}}' > index.json
fi
# URL zur gerade hochgeladenen ZIP-Datei im Release generieren
ZIP_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ steps.metadata.outputs.pkg_name }}-${{ github.ref_name }}.zip"
# Neue Version per jq sauber in die index.json injizieren
jq --arg ver "${{ steps.metadata.outputs.version }}" \
--arg name "${{ steps.metadata.outputs.pkg_name }}" \
--arg disp "${{ steps.metadata.outputs.display_name }}" \
--arg desc "${{ steps.metadata.outputs.description }}" \
--arg url "$ZIP_URL" \
'.packages[$name].versions[$ver] = {
"name": $name,
"version": $ver,
"displayName": $disp,
"description": $desc,
"unity": "2022.3",
"url": $url
}' index.json > temp.json && mv temp.json index.json
# Änderungen stagen
git add index.json
# Nur committen und pushen, wenn sich die JSON wirklich verändert hat (verhindert Action-Crash)
if ! git diff --cached --quiet; then
git commit -m "Auto-update VCC index.json for ${{ github.ref_name }}"
git push origin gh-pages
else
echo "Keine Änderungen an der index.json festgestellt. Überspringe Push."
fi