|
| 1 | +name: propagate |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + propagate: |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + branch: [modal, hetzner] |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Generate token |
| 19 | + id: create_token |
| 20 | + uses: tibdex/github-app-token@v2 |
| 21 | + with: |
| 22 | + app_id: ${{ secrets.APP_ID }} |
| 23 | + private_key: ${{ secrets.PRIVATE_KEY }} |
| 24 | + |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + token: ${{ steps.create_token.outputs.token }} |
| 30 | + |
| 31 | + - name: Attempt merge and push, or open PR on conflict |
| 32 | + env: |
| 33 | + GH_TOKEN: ${{ steps.create_token.outputs.token }} |
| 34 | + BRANCH: ${{ matrix.branch }} |
| 35 | + run: | |
| 36 | + git config user.name "github-actions[bot]" |
| 37 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 38 | +
|
| 39 | + git checkout "$BRANCH" |
| 40 | +
|
| 41 | + if git merge origin/main --no-edit; then |
| 42 | + echo "Merge succeeded, pushing to $BRANCH" |
| 43 | + git push origin "$BRANCH" |
| 44 | + else |
| 45 | + echo "Merge conflict detected, opening PR" |
| 46 | + git merge --abort |
| 47 | +
|
| 48 | + # Create a temporary branch for the PR |
| 49 | + TEMP_BRANCH="auto-merge/main-to-${BRANCH}-$(date +%Y%m%d%H%M%S)" |
| 50 | + git checkout -b "$TEMP_BRANCH" origin/main |
| 51 | +
|
| 52 | + git push origin "$TEMP_BRANCH" |
| 53 | +
|
| 54 | + gh pr create \ |
| 55 | + --base "$BRANCH" \ |
| 56 | + --head "$TEMP_BRANCH" \ |
| 57 | + --title "Propagate main to ${BRANCH}" \ |
| 58 | + --body "$(cat <<'PREOF' |
| 59 | + ## Summary |
| 60 | + - Auto-generated PR to propagate changes from `main` to the deployment branch |
| 61 | + - Opened because an automatic merge had conflicts that need manual resolution |
| 62 | +
|
| 63 | + 🤖 Generated by the propagate workflow |
| 64 | + PREOF |
| 65 | + )" |
| 66 | + fi |
0 commit comments