Skip to content

update-submodule

update-submodule #767

name: Update Submodules
on:
repository_dispatch:
types: [update-submodule]
jobs:
update_submodule:
runs-on: ubuntu-latest
steps:
- name: Log Payload
run: |
echo "Received Payload:"
echo "================="
echo "Submodule: ${{ github.event.client_payload.submodule }}"
echo "Environment: ${{ github.event.client_payload.environment }}"
echo "Commit: ${{ github.event.client_payload.commit }}"
- name: Checkout Repo
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
ref: main
- name: Identify the submodule to update
id: submodule
run: |
echo "SUBMODULE=${{ github.event.client_payload.submodule }}" >> $GITHUB_ENV
echo "COMMIT=${{ github.event.client_payload.commit }}" >> $GITHUB_ENV
# If the environment payload is production, we are going to main branch, else we are going to develop branch
if [[ ${{ github.event.client_payload.environment }} == "production" ]]; then
echo "TARGET_BRANCH=main" >> $GITHUB_ENV
else
echo "TARGET_BRANCH=staging" >> $GITHUB_ENV
fi
- name: Update submodule
run: |
# Checkout the target branch in the platform repo
git checkout ${TARGET_BRANCH}
# Setup the configuration for the git user
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
# Update the submodule
git submodule update --remote -- ${SUBMODULE}
# Enter the submodule
cd ${SUBMODULE}
# Checkout submodule to commit hash
git checkout ${COMMIT}
cd -
# Add the submodule changes
git add ${SUBMODULE}
# Commit the submodule changes
git commit -m "Updated ${SUBMODULE} submodule to commit ${COMMIT} on branch ${TARGET_BRANCH}"
# Push the submodule changes
git push origin ${TARGET_BRANCH}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}