forked from AG_QGIS/Plugin_Test_Action
170 lines
6.8 KiB
YAML
170 lines
6.8 KiB
YAML
name: Release Plugin
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: alpine-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Install dependencies
|
|
run: apk add --no-cache zip curl
|
|
|
|
- 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.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"${{ vars.GITEA_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.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/zip" \
|
|
"${{ vars.GITEA_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: |
|
|
BLOCK=" <pyqgis_plugin name=\"${{ steps.cfg.outputs.name }}\" version=\"${{ steps.info.outputs.version }}\">\n"
|
|
BLOCK+=" <description>${{ steps.cfg.outputs.description }}</description>\n"
|
|
BLOCK+=" <qgisMinimumVersion>${{ steps.cfg.outputs.qgis_min }}</qgisMinimumVersion>\n"
|
|
BLOCK+=" <qgisMaximumVersion>${{ steps.cfg.outputs.qgis_max }}</qgisMaximumVersion>\n"
|
|
BLOCK+=" <author>${{ steps.cfg.outputs.author }}</author>\n"
|
|
BLOCK+=" <email>${{ steps.cfg.outputs.email }}</email>\n"
|
|
BLOCK+=" <homepage>${{ steps.cfg.outputs.homepage }}</homepage>\n"
|
|
BLOCK+=" <tracker>${{ steps.cfg.outputs.tracker }}</tracker>\n"
|
|
BLOCK+=" <repository>${{ steps.cfg.outputs.repository }}</repository>\n"
|
|
BLOCK+=" <download_url>${{ steps.upload_asset.outputs.download_url }}</download_url>\n"
|
|
BLOCK+=" <experimental>${{ steps.cfg.outputs.experimental }}</experimental>\n"
|
|
BLOCK+=" <deprecated>${{ steps.cfg.outputs.deprecated }}</deprecated>\n"
|
|
BLOCK+=" </pyqgis_plugin>"
|
|
|
|
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.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"${{ vars.GITEA_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 }}\"
|
|
}
|
|
}" |