Add rebase CI #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rebase against upstream | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| schedule: | |
| - cron: '15 3 * * *' | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| rebase: | |
| name: Rebase now! | |
| runs-on: ubuntu-latest | |
| env: | |
| BASE_BRANCH: release-ci | |
| UPSTREAM_REPO: https://github.com/haskell/cabal.git | |
| UPSTREAM_BRANCH: master | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.BASE_BRANCH }} | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - run: | | |
| set -eux | |
| base_branch=${{ env.BASE_BRANCH }} | |
| upstream_repo=${{ env.UPSTREAM_REPO }} | |
| upstream_branch=${{ env.UPSTREAM_BRANCH }} | |
| # print version for debugging | |
| git --version | |
| # required to apply patches | |
| git config user.email "[email protected]" | |
| git config user.name "GitHub CI" | |
| # create patchset from the diverging commits | |
| git remote add upstream "${upstream_repo}" | |
| git fetch upstream | |
| git fetch origin | |
| git status | |
| common_ancestor=$(git merge-base "${base_branch}" "upstream/${upstream_branch}") | |
| git format-patch "${common_ancestor}".."${base_branch}" | |
| # backup full repo | |
| git archive "${base_branch}" > backup.tar | |
| tar -rf backup.tar .git | |
| exit 1 | |
| # do the actual "rebase" and push | |
| if compgen -G "*.patch" > /dev/null; then | |
| git reset --hard "upstream/${upstream_branch}" | |
| git am *.patch | |
| git checkout -b master-rebased | |
| git push -f https://${{ secrets.REBASE_PAT }}@github.com/stable-haskell/cabal.git master-rebased | |
| fi | |
| shell: bash | |
| # create an issue with a link to the workflow run on failure | |
| - if: failure() | |
| run: | | |
| set -eux | |
| gh repo set-default stable-haskell/cabal | |
| for issue in $(gh issue list --label rebase-failure --json url -q '.[] | .url') ; do | |
| gh issue close "${issue}" | |
| done | |
| 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 }}" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| # we always want the original repo and the patches that were applied | |
| # for debugging and backup reasons | |
| - if: always() | |
| name: Upload backup | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| retention-days: 7 | |
| name: backup | |
| path: | | |
| ./backup.tar |