-
Notifications
You must be signed in to change notification settings - Fork 58
93 lines (82 loc) · 3.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: "Update Submodule"
permissions:
contents: write
on:
workflow_dispatch:
inputs:
repo:
description: "Submodule to update"
required: true
branch:
description: "Branch of the submodule to update"
required: true
commit:
description: "Commit of the submodule to check out"
required: false
jobs:
sync:
name: "Update submodules"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Generate a token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.TEMPORAL_CICD_APP_ID }}
private_key: ${{ secrets.TEMPORAL_CICD_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
persist-credentials: true
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Calc target branches
id: target_branches
env:
LOCAL_BRANCH: ${{ github.event.inputs.branch }}
SUBMODULE_BRANCH: ${{ github.event.inputs.branch }}
run: |
if [[ $LOCAL_BRANCH == master ]]; then LOCAL_BRANCH=main; fi
echo "local_branch=${LOCAL_BRANCH}" >> $GITHUB_OUTPUT
echo "submodule_branch=${SUBMODULE_BRANCH}" >> $GITHUB_OUTPUT
- name: Create and switch branch
env:
BRANCH: ${{ steps.target_branches.outputs.local_branch }}
run: |
git switch "$BRANCH" || git switch -c "$BRANCH"
- name: Update Submodule branch
env:
SUBMODULE: ${{ github.event.inputs.repo }}
BRANCH: ${{ steps.target_branches.outputs.submodule_branch }}
run: |
if ! git config --file=.gitmodules --get submodule."$SUBMODULE".url >/dev/null; then
echo "unknown submodule $SUBMODULE"
exit 1
fi
git config --file=.gitmodules submodule."$SUBMODULE".branch "$BRANCH"
git submodule update --init --recursive --remote "$SUBMODULE"
- name: Check out requested commit
if: github.event.inputs.commit
env:
SUBMODULE: ${{ github.event.inputs.repo }}
COMMIT: ${{ github.event.inputs.commit }}
run: |
# We know the submodule exists by this point
cd $(git config --file=.gitmodules --get submodule."$SUBMODULE".path) && git checkout "$COMMIT"
- name: Commit update
env:
CURRENT_REPO: ${{ github.repository }}
TOKEN: ${{ steps.generate_token.outputs.token }}
SUBMODULE: ${{ github.event.inputs.repo }}
BRANCH: ${{ steps.target_branches.outputs.local_branch }}
run: |
git config --local user.name 'Temporal Data (cicd)'
git config --local user.email '[email protected]'
git remote set-url origin "https://x-access-token:[email protected]/$CURRENT_REPO"
git add .
git commit -m "Update $SUBMODULE submodule for branch $BRANCH"
git push origin "$BRANCH"