-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (103 loc) · 4.32 KB
/
update-submodules.yaml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Bump component submodules to latest main
on:
workflow_dispatch:
inputs:
bump-app:
description: Bump the app submodule
type: boolean
default: true
bump-tenant-manager:
description: Bump the tenant manager submodule
type: boolean
default: true
workflow_call:
inputs:
bump-app:
description: Bump the app submodule
type: boolean
default: true
bump-tenant-manager:
description: Bump the tenant manager submodule
type: boolean
default: true
jobs:
update_submodules:
runs-on: ubuntu-latest
steps:
- name: Sanity check
if: github.ref != 'refs/heads/main'
run: |
echo "This workflow updates only the main branch."
exit 1
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: false
persist-credentials: false
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.TENZIR_AUTOBUMPER_APP_ID }}
private-key: ${{ secrets.TENZIR_AUTOBUMPER_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.TENZIR_BOT_GPG_SIGNING_KEY }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Prepare git push
env:
GITHUB_APP_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
git config --global user.name 'tenzir-bot'
git config --global user.email 'engineering@tenzir.com'
git remote set-url origin https://x-access-token:$GITHUB_APP_TOKEN@github.com/tenzir/platform.git
- name: Configure ssh-agent for app submodule
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.TENZIR_APP_DEPLOY_KEY }}
- name: Update app submodule
if: ${{ inputs.bump-app }}
run: |
git submodule update --init components/app
current_sha=$(git -C components/app rev-parse HEAD)
current_sha_short=$(git -C components/app rev-parse --short HEAD)
upstream_sha=$(git -C components/app rev-parse origin/main)
upstream_sha_short=$(git -C components/app rev-parse --short origin/main)
if [ ${current_sha} != ${upstream_sha} ]; then
# Collect all files in the `changelog` directory that
# were added since the last bump.
names=$(git -C components/app diff --name-status HEAD origin/main -- changelog/ | grep '^A' | awk '{print $2}')
echo -e "Bump app component from ${current_sha_short} to ${upstream_sha_short}\n\nChanges:\n" > commitmsg
for name in ${names}; do
cat components/app/${name} >> commitmsg
done
git -C components/app checkout main
git add components/app
git commit -F commitmsg
git push -u origin main:main
fi
- name: Configure ssh-agent for tenant-manager submodule
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.TENZIR_EVENT_HORIZON_DEPLOY_KEY }}
- name: Update tenant-manager submodule
if: ${{ inputs.bump-tenant-manager }}
run: |
git submodule update --init components/tenant-manager
current_sha=$(git -C components/tenant-manager rev-parse main)
current_sha_short=$(git -C components/app rev-parse --short HEAD)
upstream_sha=$(git -C components/tenant-manager rev-parse origin/main)
upstream_sha_short=$(git -C components/app rev-parse --short origin/main)
if [ ${current_sha} != ${upstream_sha} ]; then
names=$(git -C components/tenant-manager diff --name-status HEAD origin/main -- changelog/ | grep '^A' | awk '{print $2}')
echo -e "Bump tenant-manager component from ${current_sha_short} to ${upstream_sha_short}\n\nChanges:\n" > commitmsg
for name in ${names}; do
cat components/tenant-manager/${name} >> commitmsg
done
git -C components/tenant-manager rebase origin/main
git add components/tenant-manager
git commit -F commitmsg
git push -u origin main:main
fi