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 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 CHANGED_COMPOSE_DIRS=$CHANGED_COMPOSE_DIRS" >> $GITHUB_ENV - name: Update relevant stacks in Portainer if: env.CHANGED_COMPOSE_DIRS != '' run: | echo "::notice Reading stack mapping..." STACK_MAP=$(cat .stack-map.json) for dir in $CHANGED_COMPOSE_DIRS; do echo "::notice Checking directory: $dir" STACK_ID=$(echo "$STACK_MAP" | jq -r --arg d "$dir" '.[$d]') if [ "$STACK_ID" != "null" ]; then echo "::notice Updating Portainer stack $dir (ID: $STACK_ID)..." curl -X POST "http://portainer.szabolcsi.dev/api/stacks/webhooks/$STACK_ID" else echo "::notice No stack ID found for $dir, skipping." fi done env: CHANGED_COMPOSE_DIRS: ${{ env.CHANGED_COMPOSE_DIRS }}