sync-main-to-dev #87
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: sync-main-to-dev | |
# author: @ralfhandl | |
# | |
# This workflow creates PRs to update the dev branch with the latest changes from main | |
# | |
# run this on push to main | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: {} | |
jobs: | |
sync-branch: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate access token | |
id: generate-token | |
uses: actions/create-github-app-token@v2 | |
with: | |
app-id: ${{ secrets.OAI_SPEC_PUBLISHER_APPID }} | |
private-key: ${{ secrets.OAI_SPEC_PUBLISHER_PRIVATE_KEY }} | |
- name: Checkout repository | |
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
token: ${{ steps.generate-token.outputs.token }} | |
- name: Create pull request | |
id: pull_request | |
shell: bash | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
SYNC="$BASE-sync-with-$HEAD" | |
git checkout -b $SYNC origin/$SYNC || git checkout -b $SYNC origin/$BASE | |
git merge origin/$HEAD -m "Merge $HEAD into $SYNC" | |
git checkout origin/$BASE src/* | |
git checkout origin/$BASE tests/* | |
git commit -m "Restored src/* and tests/*" || echo "" | |
git push -u origin $SYNC | |
EXISTS=$(gh pr list --base $BASE --head $SYNC \ | |
--json number --jq '.[] | .number') | |
if [ ! -z "$EXISTS" ]; then | |
echo "PR #$EXISTS already wants to merge $SYNC into $BASE" | |
exit 0 | |
fi | |
gh pr create --base $BASE --head $SYNC \ | |
--label "Housekeeping" \ | |
--title "$BASE: sync with $HEAD" \ | |
--body "Merge relevant changes from \`$HEAD\` into \`$BASE\`." | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
HEAD: main | |
BASE: dev |