Skip to content

Add rebase CI

Add rebase CI #22

Workflow file for this run

name: Rebase against upstream
on:
pull_request:
branches:
- master
schedule:
- cron: '15 3 * * *'
permissions:
contents: 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: |
cat > .github/rebase-error-issue.md <<EOF
---
title: Rebase failed on {{ date | date('dddd, MMMM Do') }}
---
{{ env.WORKFLOW_URL }}
EOF
- if: failure()
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
with:
filename: .github/rebase-error-issue.md
# 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
.github/rebase-error-issue.md