|
| 1 | +name: sync-dev-to-vX.Y-dev |
| 2 | + |
| 3 | +# author: @ralfhandl |
| 4 | + |
| 5 | +# |
| 6 | +# This workflow creates PRs to update the vX.Y-dev branch with the latest changes from dev |
| 7 | +# |
| 8 | + |
| 9 | +# run this on push to dev |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - dev |
| 14 | + workflow_dispatch: {} |
| 15 | + |
| 16 | +jobs: |
| 17 | + sync-branches: |
| 18 | + if: github.repository == 'OAI/Arazzo-Specification' |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Generate access token |
| 22 | + id: generate-token |
| 23 | + uses: actions/create-github-app-token@v3 |
| 24 | + with: |
| 25 | + client-id: ${{ secrets.OAI_SPEC_PUBLISHER_APPID }} |
| 26 | + private-key: ${{ secrets.OAI_SPEC_PUBLISHER_PRIVATE_KEY }} |
| 27 | + |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v7 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + token: ${{ steps.generate-token.outputs.token }} |
| 33 | + |
| 34 | + - name: Create pull requests |
| 35 | + id: pull_requests |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + git config user.name "github-actions[bot]" |
| 39 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 40 | +
|
| 41 | + DEV_BRANCHES=$(git branch -r --list origin/v?.?-dev) |
| 42 | + for DEV_BRANCH in $DEV_BRANCHES; do |
| 43 | + BASE=${DEV_BRANCH:7} |
| 44 | + SYNC="$BASE-sync-with-$HEAD" |
| 45 | +
|
| 46 | + git checkout -b $SYNC origin/$SYNC || git checkout -b $SYNC origin/$BASE |
| 47 | + git merge origin/$HEAD -m "Merge $HEAD into $SYNC" |
| 48 | + git checkout origin/$BASE src/ |
| 49 | + git checkout origin/$BASE tests/schema/ |
| 50 | + git commit -m "Restored src/ and tests/schema/" || echo "" |
| 51 | + git push -u origin $SYNC |
| 52 | +
|
| 53 | + EXISTS=$(gh pr list --base $BASE --head $SYNC \ |
| 54 | + --json number --jq '.[] | .number') |
| 55 | + if [ ! -z "$EXISTS" ]; then |
| 56 | + echo "PR #$EXISTS already wants to merge $SYNC into $BASE" |
| 57 | + continue |
| 58 | + fi |
| 59 | +
|
| 60 | + PR=$(gh pr create --base $BASE --head $SYNC \ |
| 61 | + --label "Housekeeping" \ |
| 62 | + --title "$BASE: sync with $HEAD" \ |
| 63 | + --body "Merge relevant changes from \`$HEAD\` into \`$BASE\`.") |
| 64 | + echo "" |
| 65 | + echo "PR to sync $BASE with $HEAD: $PR" |
| 66 | + sleep 60 # allow status checks to be triggered |
| 67 | +
|
| 68 | + gh pr checks $PR --watch --required || continue |
| 69 | + gh pr merge $PR --merge --admin |
| 70 | + done |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ steps.generate-token.outputs.token }} |
| 73 | + HEAD: dev |
0 commit comments