120 lines
3.8 KiB
YAML
120 lines
3.8 KiB
YAML
name: Build & Release Plugin
|
||
|
||
on:
|
||
workflow_dispatch:
|
||
inputs:
|
||
release_notes:
|
||
description: 'Optionele release-opmerkingen'
|
||
required: false
|
||
push:
|
||
branches:
|
||
- main
|
||
- master
|
||
paths:
|
||
- 'siti-stock-plugin.php'
|
||
- 'includes/**'
|
||
- 'assets/**'
|
||
- 'README.md'
|
||
- '.github/workflows/release.yml'
|
||
|
||
jobs:
|
||
release:
|
||
runs-on: ubuntu-latest
|
||
permissions:
|
||
contents: write
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Fetch tags
|
||
run: git fetch --tags origin
|
||
|
||
- name: Determine plugin version
|
||
id: meta
|
||
run: |
|
||
VERSION=$(grep -E "^\\s*\\*\\s*Version:" -m 1 siti-stock-plugin.php | sed -E 's/.*Version:\\s*//')
|
||
VERSION=$(echo "$VERSION" | tr -d '\\r')
|
||
if [ -z "$VERSION" ]; then
|
||
echo "::error::Kon pluginversie niet bepalen."
|
||
exit 1
|
||
fi
|
||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Check if tag exists
|
||
id: tagcheck
|
||
run: |
|
||
TAG="v${{ steps.meta.outputs.version }}"
|
||
if git show-ref --tags --verify --quiet "refs/tags/$TAG"; then
|
||
echo "exists=true" >> "$GITHUB_OUTPUT"
|
||
else
|
||
echo "exists=false" >> "$GITHUB_OUTPUT"
|
||
fi
|
||
|
||
- name: Maak of update git-tag
|
||
if: steps.tagcheck.outputs.exists == 'false'
|
||
run: |
|
||
TAG="v${{ steps.meta.outputs.version }}"
|
||
git config user.name "github-actions[bot]"
|
||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||
git tag "$TAG" "$GITHUB_SHA"
|
||
git push origin "$TAG"
|
||
|
||
- name: Tag bestaat al – workflow afronden
|
||
if: steps.tagcheck.outputs.exists == 'true'
|
||
run: |
|
||
echo "Tag v${{ steps.meta.outputs.version }} bestaat al. Release wordt overgeslagen."
|
||
|
||
- name: Build distributie-zip
|
||
if: steps.tagcheck.outputs.exists == 'false'
|
||
id: package
|
||
run: |
|
||
VERSION="${{ steps.meta.outputs.version }}"
|
||
SLUG="siti-stock-plugin"
|
||
BUILD_ROOT="$RUNNER_TEMP/build"
|
||
DEST_DIR="$BUILD_ROOT/$SLUG"
|
||
mkdir -p "$DEST_DIR"
|
||
|
||
rsync -a ./ "$DEST_DIR" \
|
||
--exclude '.git/' \
|
||
--exclude '.github/' \
|
||
--exclude 'docker/' \
|
||
--exclude 'docs/' \
|
||
--exclude 'dist/' \
|
||
--exclude 'docker-compose.yml' \
|
||
--exclude 'PLAN.md'
|
||
|
||
mkdir -p dist
|
||
ZIP_PATH="dist/${SLUG}-${VERSION}.zip"
|
||
(cd "$BUILD_ROOT" && zip -r "$GITHUB_WORKSPACE/$ZIP_PATH" "$SLUG")
|
||
|
||
echo "asset_path=$ZIP_PATH" >> "$GITHUB_OUTPUT"
|
||
echo "asset_name=${SLUG}-${VERSION}.zip" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Stel release-body samen
|
||
if: steps.tagcheck.outputs.exists == 'false'
|
||
id: releasebody
|
||
run: |
|
||
if [ -n "$RELEASE_NOTES" ]; then
|
||
echo "text=$RELEASE_NOTES" >> "$GITHUB_OUTPUT"
|
||
else
|
||
echo "text=Automatische release op basis van versie ${{ steps.meta.outputs.version }}." >> "$GITHUB_OUTPUT"
|
||
fi
|
||
env:
|
||
RELEASE_NOTES: ${{ github.event.inputs.release_notes }}
|
||
|
||
- name: Maak GitHub release
|
||
if: steps.tagcheck.outputs.exists == 'false'
|
||
uses: ncipollo/release-action@v1
|
||
with:
|
||
tag: v${{ steps.meta.outputs.version }}
|
||
commit: ${{ github.sha }}
|
||
name: Siti Stock Plugin v${{ steps.meta.outputs.version }}
|
||
body: ${{ steps.releasebody.outputs.text }}
|
||
artifacts: ${{ steps.package.outputs.asset_path }}
|
||
generateReleaseNotes: true
|
||
token: ${{ secrets.GITHUB_TOKEN }}
|
||
allowUpdates: true
|
||
updateOnlyUnreleased: true
|