Upstream sync #92
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: Pull Request into Fork from Upstream Repo on Push | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| create_pull_request: | |
| if: github.repository == 'grycap/oscar-dashboard' | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.UPDATE_DEMO }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Check if PR exists | |
| id: check_pr | |
| run: | | |
| PR_DATA=$(gh api -X GET repos/grycap/oscar-dashboard-demo/pulls \ | |
| -f head_repo=grycap/oscar-dashboard \ | |
| -f base=main \ | |
| -f head=main) | |
| PR_EXISTS=$(echo "$PR_DATA" | jq '. | length') | |
| echo "PR_EXISTS=$PR_EXISTS" >> $GITHUB_ENV | |
| if [ "$PR_EXISTS" != '0' ]; then | |
| PR_NUMBER=$(echo "$PR_DATA" | jq '.[0].number') | |
| echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
| else | |
| echo "PR_NUMBER=0" >> $GITHUB_ENV | |
| fi | |
| - name: Create Pull Request (if none exists) | |
| if: env.PR_EXISTS == '0' | |
| run: | | |
| PR_NUMBER=$(gh api -X POST repos/grycap/oscar-dashboard-demo/pulls \ | |
| -f head_repo=grycap/oscar-dashboard \ | |
| -f title='Merge upstream main into fork main' \ | |
| -f body='Created by GitHub Actions' \ | |
| -f base=main \ | |
| -f head=main | jq '.number') | |
| echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
| - name: Merge Pull Request (if exists) | |
| if: env.PR_NUMBER != '0' | |
| run: | | |
| gh api -X PUT repos/grycap/oscar-dashboard-demo/pulls/${{env.PR_NUMBER}}/merge \ | |
| -f "commit_title=Upstream sync" \ | |
| -f "merge_method=merge" |