From fcc06f4c5213a959b927b67c5b6d1ad3b14f8217 Mon Sep 17 00:00:00 2001 From: Andrew O'Brien Date: Wed, 18 Sep 2024 23:29:25 -0500 Subject: [PATCH 1/2] add yml for auto-updating submods, first pass --- .github/workflows/sync_submodules.yml | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/sync_submodules.yml diff --git a/.github/workflows/sync_submodules.yml b/.github/workflows/sync_submodules.yml new file mode 100644 index 0000000..848333b --- /dev/null +++ b/.github/workflows/sync_submodules.yml @@ -0,0 +1,34 @@ +name: Update Submodules + +on: + workflow_dispatch: # Allow manual triggering + schedule: + - cron: '10 0 * * *' # Execute at midnight every day + +jobs: + update_submodule: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: true # Make sure to check out the sub-module + + - name: Update submodule + run: | + git submodule update --init --recursive + git submodule update --remote --recursive + + - name: Check if changes were made and commit if found + id: check_and_push_changes + run: | + if [ -z "$(git status --porcelain)" ]; then + echo "No changes were made." + else + echo "Changes found in a submodule." # This can be further abstracted to give specific submod name, possibly. + git config --global user.email "cloudscythelabs@gmail.com" + git config --global user.name "Cloud Scythe Labs" + git add . + git commit -m 'Update submodule' + git push + fi From a3d9c52296d1dde6b8391db5ba41a825082d49fa Mon Sep 17 00:00:00 2001 From: Andrew O'Brien Date: Thu, 19 Sep 2024 22:13:29 -0500 Subject: [PATCH 2/2] add branch check and pull request logic --- .github/workflows/sync_submodules.yml | 50 +++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync_submodules.yml b/.github/workflows/sync_submodules.yml index 848333b..c117cac 100644 --- a/.github/workflows/sync_submodules.yml +++ b/.github/workflows/sync_submodules.yml @@ -3,11 +3,37 @@ name: Update Submodules on: workflow_dispatch: # Allow manual triggering schedule: - - cron: '10 0 * * *' # Execute at midnight every day + - cron: '0 0 * * *' # Execute at midnight every day jobs: + check_update_submodule_branch: + runs-on: ubuntu-latest + outputs: + submodule_branch_exists: ${{ steps.check_update_submodule_branch.outputs.submodule_branch_exists }} + steps: + - name: Checkout respository + uses: actions/checkout@v4 + + - name: Check if update-submodule branch exists + id: check_update_submodule_branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + branch_name="update-submodules" + api_url="https://api.github.com/repos/Cloud-Scythe-Labs/reascript-rs/branches/${branch_name}" + response=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITHUB_TOKEN" "$api_url") + if [[ "$response" == "200" ]]; then + echo "Branch $branch_name already exists" + echo "::set-output name=submodule_branch_exists::true" + else + echo "Branch $branch_name does not exist" + echo "::set-output name=submodule_branch_exists::false" + fi + update_submodule: runs-on: ubuntu-latest + needs: check_update_submodule_branch + if: ${{ needs.check_update_submodule_branch.outputs.submodule_branch_exists == 'false' }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -20,15 +46,27 @@ jobs: git submodule update --remote --recursive - name: Check if changes were made and commit if found - id: check_and_push_changes + id: check_and_commit_changes run: | if [ -z "$(git status --porcelain)" ]; then echo "No changes were made." + exit 0 else - echo "Changes found in a submodule." # This can be further abstracted to give specific submod name, possibly. git config --global user.email "cloudscythelabs@gmail.com" git config --global user.name "Cloud Scythe Labs" + git remote set-url origin "https://x-access-token:${{ secrets.REASCRIPT_PULL_REQUEST }}@github.com/Cloud-Scythe-Labs/reascript-rs.git" + git checkout -b update-submodules git add . - git commit -m 'Update submodule' - git push - fi + git commit -m "Update Submodules" + git push origin update-submodules + pull_request_res=$(curl -X POST -H "Authorization: token ${{ secrets.REASCRIPT_PULL_REQUEST }}" \ + -d '{ + "title": "Update Submodules", + "body": "automated update of the reaper submodules.", + "head": "update-submodules", + "base": "master" + }' \ + https://api.github.com/repos/Cloud-Scythe-Labs/reascript-rs/pulls) + if [[ "$pull_request_res" =~ "nothing to commit" ]]; then + exit 0 + fi