45 lines
1.6 KiB
YAML
45 lines
1.6 KiB
YAML
name: Portainer Stack Update
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
update_stack:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Detect changed compose files
|
|
id: changed
|
|
run: |
|
|
# Get only changed docker-compose.yml files in top-level folders
|
|
git diff --name-only ${{ github.event.before }} ${{ github.sha }}
|
|
CHANGED_COMPOSE_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '^[^/]+/docker-compose\.yml$' | cut -d '/' -f1 | sort -u || true)
|
|
echo "::notice title=Changed Files::$CHANGED_COMPOSE_DIRS"
|
|
echo "CHANGED_COMPOSE_DIRS=$CHANGED_COMPOSE_DIRS" >> $GITHUB_ENV
|
|
|
|
- name: Update relevant stacks in Portainer
|
|
if: env.CHANGED_COMPOSE_DIRS != ''
|
|
run: |
|
|
echo "::notice title=Found Changed yml::Reading stack mapping"
|
|
STACK_MAP=$(cat .stack-map.json)
|
|
|
|
for dir in $CHANGED_COMPOSE_DIRS; do
|
|
echo "::notice title=Checking directory::$dir"
|
|
STACK_ID=$(echo "$STACK_MAP" | jq -r --arg d "$dir" '.[$d]')
|
|
|
|
if [ "$STACK_ID" != "null" ]; then
|
|
echo "::notice title=Updating Portainer stack::$dir (ID: $STACK_ID)..."
|
|
curl -v -X POST "http://portainer.szabolcsi.dev/api/stacks/webhooks/$STACK_ID"
|
|
else
|
|
echo "::notice title=No stack ID found for::$dir, skipping."
|
|
fi
|
|
done
|
|
env:
|
|
CHANGED_COMPOSE_DIRS: ${{ env.CHANGED_COMPOSE_DIRS }}
|