From b75b6be23f5483e2f13bfd9f45f1c1e84a86ca09 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 3 Aug 2023 17:56:09 -0400 Subject: [PATCH] #1443 Update GitHub Workflow Submodules --- .github/workflows/submodule-update.yml | 40 +++++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/workflows/submodule-update.yml b/.github/workflows/submodule-update.yml index f047a03f..61b4da3b 100644 --- a/.github/workflows/submodule-update.yml +++ b/.github/workflows/submodule-update.yml @@ -1,11 +1,10 @@ ---- name: Submodule Updates on: push: - branches: [ develop ] - # schedule: - # - cron: '0 12 * * *' + branches: [develop] + schedule: + - cron: '0 12 * * *' jobs: check_submodules: @@ -44,25 +43,44 @@ jobs: echo 'changes=false' >> $GITHUB_OUTPUT fi exit 0 - - - name: Create submodules changes branch + + - name: Create or Update submodules changes branch if: steps.check_for_changes.outputs.changes == 'true' run: | - git checkout -b "submodule-change/$GITHUB_RUN_ID" $CHECKOUT_BRANCH + git fetch origin "submodule-change/$GITHUB_RUN_ID" || git checkout -b "submodule-change/$GITHUB_RUN_ID" $CHECKOUT_BRANCH git commit -am "updating submodules" git push --set-upstream origin "submodule-change/$GITHUB_RUN_ID" - - name: Create pull request against target branch + - name: Create or Update pull request against target branch if: steps.check_for_changes.outputs.changes == 'true' uses: actions/github-script@v6 with: github-token: "${{ secrets.GITHUB_TOKEN }}" script: | - await github.rest.pulls.create({ + const { data: pulls } = await github.rest.pulls.list({ owner: '${{ github.repository_owner }}', repo: '${{ github.repository }}'.split('/')[1].trim(), head: 'submodule-change/${{ github.run_id }}', base: '${{ env.PR_AGAINST_BRANCH }}', - title: `[Auto-generated] Submodule Updates ${process.env.GITHUB_RUN_ID}`, - body: '${{ steps.check_for_changes.outputs.changes_text }}', + state: 'open', }); + if (pulls.length > 0) { + // If an open pull request exists, update it + const pull_number = pulls[0].number; + await github.rest.pulls.update({ + owner: '${{ github.repository_owner }}', + repo: '${{ github.repository }}'.split('/')[1].trim(), + pull_number, + body: '${{ steps.check_for_changes.outputs.changes_text }}', + }); + } else { + // If no open pull request exists, create a new one + await github.rest.pulls.create({ + owner: '${{ github.repository_owner }}', + repo: '${{ github.repository }}'.split('/')[1].trim(), + head: 'submodule-change/${{ github.run_id }}', + base: '${{ env.PR_AGAINST_BRANCH }}', + title: `[Auto-generated] Submodule Updates ${process.env.GITHUB_RUN_ID}`, + body: '${{ steps.check_for_changes.outputs.changes_text }}', + }); + }