|
| 1 | +name: Nightly stack sync |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run every night at 02:00 UTC |
| 6 | + - cron: '0 2 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync: |
| 15 | + name: Regenerate stacks and open PR if drifted |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout dev branch |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + ref: dev |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.x' |
| 28 | + |
| 29 | + - name: Install PyYAML |
| 30 | + run: pip install PyYAML |
| 31 | + |
| 32 | + - name: Regenerate stacks |
| 33 | + run: python3 tools/generate_stacks.py |
| 34 | + |
| 35 | + - name: Check for drift |
| 36 | + id: drift |
| 37 | + run: | |
| 38 | + if git diff --quiet stacks/; then |
| 39 | + echo "drifted=false" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "drifted=true" >> "$GITHUB_OUTPUT" |
| 42 | + git diff --stat stacks/ |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Open or update PR for drifted stacks |
| 46 | + if: steps.drift.outputs.drifted == 'true' |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + run: | |
| 50 | + branch="chore/nightly-stack-sync-$(date +%Y%m%d)" |
| 51 | + git config user.name "github-actions[bot]" |
| 52 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | + git checkout -b "$branch" |
| 54 | + git add stacks/ |
| 55 | + git commit -m "chore(stacks): nightly regeneration from compose sources [skip ci]" |
| 56 | + git push origin "$branch" |
| 57 | + gh pr create \ |
| 58 | + --base dev \ |
| 59 | + --head "$branch" \ |
| 60 | + --title "chore(stacks): nightly stack regeneration $(date +%Y-%m-%d)" \ |
| 61 | + --body "Automated PR: stacks/ drifted from compose sources. Generated by the nightly-stack-sync workflow. |
| 62 | +
|
| 63 | +Run \`./stackctl.sh sync\` locally to reproduce the diff." \ |
| 64 | + || echo "PR already exists or could not be created" |
0 commit comments