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