|
17 | 17 | run: |
18 | 18 | shell: bash -l {0} |
19 | 19 | runs-on: ubuntu-latest |
| 20 | + # Only the upstream repo runs the automatic API update |
| 21 | + if: | |
| 22 | + !github.event.repository.fork || github.event_name == 'workflow_dispatch' |
20 | 23 |
|
21 | 24 | steps: |
22 | 25 | - uses: actions/checkout@v4 |
@@ -48,37 +51,34 @@ jobs: |
48 | 51 | echo UPDATE_NEEDED is "${UPDATE_NEEDED}" |
49 | 52 | echo API version is "${API_VERSION}" |
50 | 53 | continue-on-error: true |
51 | | - - name: Create PR body text |
| 54 | + - name: Create or Update Pull Request |
| 55 | + # Manually disable to make sure it can rerun |
52 | 56 | if: env.UPDATE_NEEDED == 'true' |
53 | | - run: | |
54 | | - touch pr_body.txt |
55 | | - echo "## Automated JSON API Update" >> pr_body.txt |
56 | | - echo "Hello! This is an automatic pull request to merge the new JSON API version **${API_VERSION}** into the master branch." >> pr_body.txt |
57 | | - echo "### Details" >> pr_body.txt |
58 | | - echo "- **Workflow Trigger**: This update is triggered by the **Update JSON API (recurring job)** workflow." >> pr_body.txt |
59 | | - echo "- **Reason for Update**: A new JSON schema version was generated that differs from the existing one in the repository." >> pr_body.txt |
60 | | - echo "### Notes" >> pr_body.txt |
61 | | - echo "- If you notice any issues or have questions regarding this update, please contact @alchem0x2a or other maintainers of the repository." >> pr_body.txt |
62 | | - echo "Thank you for keeping the SPARC-X-API project up-to-date! 🚀" >> pr_body.txt |
63 | | - cat pr_body.txt |
64 | | - - name: Create Pull Request |
65 | | - # Do not create PR from another PR |
66 | | - if: (env.UPDATE_NEEDED == 'true') && (github.event_name != 'pull_request') |
67 | | - run: | |
68 | | - git config --global user.email "alchem0x2a@gmail.com" |
69 | | - git config --global user.name "Github Action Bot" |
70 | | - echo "New version is ${API_VERSION}" |
71 | | - BRANCH_NAME="update-api-${GITHUB_RUN_ID}" |
72 | | - echo "Checking new branch ${BRANCH_NAME}" |
73 | | - git checkout -b $BRANCH_NAME |
74 | | - mv parameters.json sparc/sparc_json_api/ |
75 | | - git add sparc/sparc_json_api/parameters.json |
76 | | - git commit -m "Add new json api version ${API_VERSION}" |
77 | | - git push --force --set-upstream origin ${BRANCH_NAME} |
| 57 | + uses: peter-evans/create-pull-request@v7 |
| 58 | + with: |
| 59 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + commit-message: | |
| 61 | + Update JSON API to version ${{ env.API_VERSION }} |
| 62 | +
|
| 63 | + The commit is created by a scheduled CI job. |
| 64 | + "" |
| 65 | + branch: update-api-${{ env.API_VERSION }} |
| 66 | + title: "[Automated] Update JSON API to version ${{ env.API_VERSION }}" |
| 67 | + body: | |
| 68 | + ## Automated JSON API Update |
| 69 | +
|
| 70 | + Hello! This is an automatic pull request to merge the new JSON API to version **${{ env.API_VERSION }}**. |
| 71 | +
|
| 72 | + ### Details |
| 73 | + - **Workflow Trigger:** Update JSON API (recurring job). |
| 74 | + - **Reason for Update:** A new JSON schema version was generated that differs from the existing one in the repository. |
| 75 | +
|
| 76 | + ### Notes |
| 77 | + - If you notice any issues or have questions regarding this update, please reach out to the maintainers. |
78 | 78 |
|
79 | | - gh pr create --base master \ |
80 | | - --title "[PR Bot] New JSON API version ${API_VERSION}" \ |
81 | | - --body-file pr_body.txt \ |
82 | | - -R ${{ github.repository_owner }}/SPARC-X-API |
83 | | - env: |
84 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + # Eliminate unnecessary PRs if not closed |
| 80 | + delete-branch: true |
| 81 | + # Prevent PRs on forks |
| 82 | + base: master |
| 83 | + delete-branch: true |
| 84 | + base: master |
0 commit comments