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