forked from AG_QGIS/Plugin_Test_Action
182 lines
7.3 KiB
YAML
182 lines
7.3 KiB
YAML
name: Release Plugin
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: alpine-latest
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
|
|
steps:
|
|
- name: Install dependencies
|
|
run: |
|
|
apk add --no-cache git zip curl jq rsync
|
|
git config --global http.sslVerify false
|
|
|
|
- name: Checkout
|
|
run: |
|
|
git clone --depth 1 --branch ${{ github.ref_name }} https://x-access-token:${{ gitea.token }}@${{ vars.RELEASE_URL }}/${{ github.repository }}.git .
|
|
|
|
- name: Determine version and channel
|
|
id: info
|
|
run: |
|
|
TAG="${{ github.ref_name }}"
|
|
VERSION="${TAG#v}"
|
|
|
|
if [[ "$TAG" =~ -dev ]]; then
|
|
CHANNEL="dev"
|
|
elif [[ "$TAG" =~ -beta ]]; then
|
|
CHANNEL="beta"
|
|
else
|
|
CHANNEL="stable"
|
|
fi
|
|
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "channel=${CHANNEL}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Read plugin.cfg
|
|
id: cfg
|
|
run: |
|
|
CFG=".plugin/plugin.cfg"
|
|
|
|
get_value() {
|
|
grep -i "^$1" "$CFG" | head -1 | cut -d= -f2- | tr -d '\r' | xargs
|
|
}
|
|
|
|
echo "zip_folder=$(get_value zip_folder)" >> $GITHUB_OUTPUT
|
|
echo "name=$(get_value name)" >> $GITHUB_OUTPUT
|
|
echo "qgis_min=$(get_value qgisMinimumVersion)" >> $GITHUB_OUTPUT
|
|
echo "qgis_max=$(get_value qgisMaximumVersion)" >> $GITHUB_OUTPUT
|
|
echo "description=$(get_value description)" >> $GITHUB_OUTPUT
|
|
echo "author=$(get_value author)" >> $GITHUB_OUTPUT
|
|
echo "email=$(get_value email)" >> $GITHUB_OUTPUT
|
|
echo "homepage=$(get_value homepage)" >> $GITHUB_OUTPUT
|
|
echo "tracker=$(get_value tracker)" >> $GITHUB_OUTPUT
|
|
echo "repository=$(get_value repository)" >> $GITHUB_OUTPUT
|
|
echo "experimental=$(get_value experimental)" >> $GITHUB_OUTPUT
|
|
echo "deprecated=$(get_value deprecated)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Generate metadata.txt
|
|
run: |
|
|
VERSION="${{ steps.info.outputs.version }}"
|
|
CHANGELOG=$(cat .plugin/changelog.txt)
|
|
|
|
cat > metadata.txt << EOF
|
|
[general]
|
|
name=${{ steps.cfg.outputs.name }}
|
|
version=${VERSION}
|
|
qgisMinimumVersion=${{ steps.cfg.outputs.qgis_min }}
|
|
qgisMaximumVersion=${{ steps.cfg.outputs.qgis_max }}
|
|
description=${{ steps.cfg.outputs.description }}
|
|
author=${{ steps.cfg.outputs.author }}
|
|
email=${{ steps.cfg.outputs.email }}
|
|
homepage=${{ steps.cfg.outputs.homepage }}
|
|
tracker=${{ steps.cfg.outputs.tracker }}
|
|
repository=${{ steps.cfg.outputs.repository }}
|
|
experimental=${{ steps.cfg.outputs.experimental }}
|
|
deprecated=${{ steps.cfg.outputs.deprecated }}
|
|
changelog=${VERSION}
|
|
$(cat .plugin/changelog.txt)
|
|
EOF
|
|
|
|
- name: Build plugin ZIP
|
|
run: |
|
|
REPO_NAME="${{ github.event.repository.name }}"
|
|
ZIP_FOLDER="${{ steps.cfg.outputs.zip_folder }}"
|
|
VERSION="${{ steps.info.outputs.version }}"
|
|
ZIP_NAME="${REPO_NAME}-${VERSION}.zip"
|
|
|
|
# Temporären Ordner mit zip_folder-Namen anlegen
|
|
mkdir -p dist/${ZIP_FOLDER}
|
|
|
|
# Alle Plugin-Dateien hineinkopieren (ohne .gitea, .plugin, dist)
|
|
rsync -a \
|
|
--exclude='.gitea' \
|
|
--exclude='.plugin' \
|
|
--exclude='.git' \
|
|
--exclude='dist' \
|
|
./ dist/${ZIP_FOLDER}/
|
|
|
|
# ZIP bauen
|
|
cd dist
|
|
zip -r ${ZIP_NAME} ${ZIP_FOLDER}/ \
|
|
-x "*.pyc" -x "*/__pycache__/*"
|
|
cd ..
|
|
|
|
echo "ZIP_NAME=${ZIP_NAME}" >> $GITHUB_ENV
|
|
|
|
- name: Create Gitea Release
|
|
id: create_release
|
|
run: |
|
|
VERSION="${{ steps.info.outputs.version }}"
|
|
IS_PRERELEASE=true
|
|
[[ "${{ steps.info.outputs.channel }}" == "stable" ]] && IS_PRERELEASE=false
|
|
|
|
RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"https://${{ vars.RELEASE_URL }}/api/v1/repos/${{ github.repository }}/releases" \
|
|
-d "{
|
|
\"tag_name\": \"${{ github.ref_name }}\",
|
|
\"name\": \"Release ${VERSION}\",
|
|
\"prerelease\": ${IS_PRERELEASE}
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Upload ZIP asset
|
|
id: upload_asset
|
|
run: |
|
|
RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
-H "Content-Type: application/zip" \
|
|
"https://${{ vars.RELEASE_URL }}/api/v1/repos/${{ github.repository }}/releases/${{ steps.create_release.outputs.release_id }}/assets?name=${ZIP_NAME}" \
|
|
--data-binary @dist/${ZIP_NAME})
|
|
|
|
DOWNLOAD_URL=$(echo "$RESPONSE" | grep -o '"browser_download_url":"[^"]*' | cut -d'"' -f4)
|
|
echo "download_url=${DOWNLOAD_URL}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build XML block
|
|
id: xmlblock
|
|
run: |
|
|
NAME="${{ steps.cfg.outputs.name }}"
|
|
VERSION="${{ steps.info.outputs.version }}"
|
|
|
|
BLOCK=$(printf ' <pyqgis_plugin name="%s" version="%s">\n <description>%s</description>\n <qgisMinimumVersion>%s</qgisMinimumVersion>\n <qgisMaximumVersion>%s</qgisMaximumVersion>\n <author>%s</author>\n <email>%s</email>\n <homepage>%s</homepage>\n <tracker>%s</tracker>\n <repository>%s</repository>\n <download_url>%s</download_url>\n <experimental>%s</experimental>\n <deprecated>%s</deprecated>\n </pyqgis_plugin>' \
|
|
"$NAME" \
|
|
"$VERSION" \
|
|
"${{ steps.cfg.outputs.description }}" \
|
|
"${{ steps.cfg.outputs.qgis_min }}" \
|
|
"${{ steps.cfg.outputs.qgis_max }}" \
|
|
"${{ steps.cfg.outputs.author }}" \
|
|
"${{ steps.cfg.outputs.email }}" \
|
|
"${{ steps.cfg.outputs.homepage }}" \
|
|
"${{ steps.cfg.outputs.tracker }}" \
|
|
"${{ steps.cfg.outputs.repository }}" \
|
|
"${{ steps.download_url.outputs.download_url }}" \
|
|
"${{ steps.cfg.outputs.experimental }}" \
|
|
"${{ steps.cfg.outputs.deprecated }}")
|
|
|
|
BLOCK_ESCAPED=$(printf '%s' "$BLOCK" | sed 's/"/\\"/g')
|
|
echo "block=${BLOCK_ESCAPED}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Dispatch to Repository
|
|
run: |
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"https://${{ vars.RELEASE_URL }}/api/v1/repos/${{ github.repository_owner }}/Repository/dispatches" \
|
|
-d "{
|
|
\"type\": \"plugin-released\",
|
|
\"payload\": {
|
|
\"plugin\": \"${{ steps.cfg.outputs.name }}\",
|
|
\"channel\": \"${{ steps.info.outputs.channel }}\",
|
|
\"xml_block\": \"${{ steps.xmlblock.outputs.block }}\"
|
|
}
|
|
}" |