|
| 1 | +name: Rebase against upstream |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + issues: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + rebase: |
| 13 | + name: Rebase now! |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + BASE_BRANCH: master |
| 17 | + UPSTREAM_REPO: https://github.com/haskell/cabal.git |
| 18 | + UPSTREAM_BRANCH: master |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: ${{ env.BASE_BRANCH }} |
| 24 | + fetch-depth: 0 |
| 25 | + persist-credentials: false |
| 26 | + |
| 27 | + - run: | |
| 28 | + set -eux |
| 29 | +
|
| 30 | + base_branch=${{ env.BASE_BRANCH }} |
| 31 | + upstream_repo=${{ env.UPSTREAM_REPO }} |
| 32 | + upstream_branch=${{ env.UPSTREAM_BRANCH }} |
| 33 | +
|
| 34 | + # print version for debugging |
| 35 | + git --version |
| 36 | +
|
| 37 | + # required to apply patches |
| 38 | + git config user.email "[email protected]" |
| 39 | + git config user.name "GitHub CI" |
| 40 | +
|
| 41 | + # create patchset from the diverging commits |
| 42 | + git remote add upstream "${upstream_repo}" |
| 43 | + git fetch upstream |
| 44 | + git fetch origin |
| 45 | + git status |
| 46 | + common_ancestor=$(git merge-base "${base_branch}" "upstream/${upstream_branch}") |
| 47 | + git format-patch "${common_ancestor}".."${base_branch}" |
| 48 | +
|
| 49 | + # backup full repo |
| 50 | + echo "${common_ancestor}" > BASE_COMMIT |
| 51 | + git archive "${base_branch}" > backup.tar |
| 52 | + tar -rf backup.tar .git *.patch BASE_COMMIT |
| 53 | +
|
| 54 | + # do the actual "rebase" and push |
| 55 | + if compgen -G "*.patch" > /dev/null; then |
| 56 | + git reset --hard "upstream/${upstream_branch}" |
| 57 | + git am *.patch |
| 58 | + git push -f https://${{ secrets.REBASE_PAT }}@github.com/${{ github.repository }}.git "${base_branch}" |
| 59 | + fi |
| 60 | + shell: bash |
| 61 | +
|
| 62 | + # create an issue with a link to the workflow run on failure |
| 63 | + - if: failure() |
| 64 | + run: | |
| 65 | + set -eux |
| 66 | + gh repo set-default stable-haskell/cabal |
| 67 | + for issue in $(gh issue list --label rebase-failure --json url -q '.[] | .url') ; do |
| 68 | + gh issue close "${issue}" |
| 69 | + done |
| 70 | + gh issue create --title "Rebase failed on $(date -u +"%Y-%m-%d")" --label rebase-failure --body "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ github.token }} |
| 73 | + |
| 74 | + # we always want the original repo and the patches that were applied |
| 75 | + # for debugging and backup reasons |
| 76 | + - if: always() |
| 77 | + name: Upload backup |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + if-no-files-found: error |
| 81 | + retention-days: 7 |
| 82 | + name: backup |
| 83 | + path: | |
| 84 | + ./backup.tar |
0 commit comments