-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (54 loc) · 2.09 KB
/
update_submodules.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 }}