Submodule Updates #591
This file contains 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: Submodule Updates | |
on: | |
push: | |
branches: [develop] | |
schedule: | |
- cron: '0 12 * * *' | |
jobs: | |
check_submodules: | |
name: Pull Request for updated submodules | |
runs-on: ubuntu-latest | |
env: | |
PARENT_REPOSITORY: 'EDCD/EDMarketConnector' | |
CHECKOUT_BRANCH: 'develop' | |
PR_AGAINST_BRANCH: 'develop' | |
OWNER: 'EDCD' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: '${{ env.CHECKOUT_BRANCH }}' | |
submodules: true | |
- name: Update submodules | |
shell: bash | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git submodule update --remote | |
- name: Check for changes | |
id: check_for_changes | |
continue-on-error: true | |
run: | | |
changes=$(git status --porcelain) | |
git status --porcelain | |
if [ -n "${changes}" ]; | |
then | |
echo 'changes=true' >> $GITHUB_OUTPUT | |
echo "changes_text=${changes}" >> $GITHUB_OUTPUT | |
else | |
echo 'changes=false' >> $GITHUB_OUTPUT | |
fi | |
exit 0 | |
- name: Create or Update submodules changes branch | |
if: steps.check_for_changes.outputs.changes == 'true' | |
run: | | |
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 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: | | |
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 }}', | |
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 }}', | |
}); | |
} |