Nightly stack sync #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Nightly stack sync | |
| on: | |
| schedule: | |
| # Run every night at 02:00 UTC | |
| - cron: '0 2 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| name: Regenerate stacks and open PR if drifted | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout dev branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: dev | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.x' | |
| - name: Install Python deps | |
| run: pip install -r tools/requirements.txt | |
| - name: Install yq | |
| run: | | |
| YQ_VERSION="v4.44.3" | |
| sudo wget -qO /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" | |
| sudo chmod +x /usr/local/bin/yq | |
| yq --version | |
| - name: Validate YAML with yq | |
| run: | | |
| set -euo pipefail | |
| while IFS= read -r file; do | |
| yq e '.' "$file" >/dev/null | |
| done < <(find .github/workflows stacks -type f \( -name '*.yml' -o -name '*.yaml' \) | sort) | |
| - name: Regenerate stacks | |
| run: python3 tools/generate_stacks.py | |
| - name: Check for drift | |
| id: drift | |
| run: | | |
| if git diff --quiet stacks/; then | |
| echo "drifted=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "drifted=true" >> "$GITHUB_OUTPUT" | |
| git diff --stat stacks/ | |
| fi | |
| - name: Open or update PR for drifted stacks | |
| if: steps.drift.outputs.drifted == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| branch="chore/nightly-stack-sync-$(date +%Y%m%d)" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "$branch" | |
| git add stacks/ | |
| git commit -m "chore(stacks): nightly regeneration from compose sources [skip ci]" | |
| git push origin "$branch" | |
| pr_body=$'Automated PR: stacks/ drifted from compose sources. Generated by the nightly-stack-sync workflow.\n\nRun ./stackctl.sh sync locally to reproduce the diff.' | |
| gh pr create \ | |
| --base dev \ | |
| --head "$branch" \ | |
| --title "chore(stacks): nightly stack regeneration $(date +%Y-%m-%d)" \ | |
| --body "$pr_body" \ | |
| || echo "PR already exists or could not be created" |