-
Notifications
You must be signed in to change notification settings - Fork 23
237 lines (205 loc) · 8.33 KB
/
update-versions-self-host.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
---
name: Update Versions - Self Host
on:
workflow_dispatch:
env:
_BRANCH: main
jobs:
setup:
name: Setup
runs-on: ubuntu-22.04
outputs:
core_version: ${{ steps.get-core.outputs.version }}
core_version_update: ${{ steps.core-update.outputs.update }}
web_version: ${{ steps.get-web.outputs.version }}
web_version_update: ${{ steps.web-update.outputs.update }}
steps:
- name: Checkout Branch
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: main
- name: Get Latest Core Version
id: get-core
uses: bitwarden/gh-actions/get-release-version@main
with:
repository: bitwarden/server
trim: true
- name: Check if Core Version needs updating
id: core-update
env:
LATEST_CORE_VERSION: ${{ steps.get-core.outputs.version }}
run: |
CORE_VERSION=$(sed -r -n '/define "bitwarden.coreVersionDefault"/!b;n;'\
's/\{\{- "([0-9]+\.[0-9]+\.[0-9]+)" -\}\}/\1/p' helpers.tpl)
echo "Core Version: $CORE_VERSION"
echo "Latest Core Version: $LATEST_CORE_VERSION"
if [ "$CORE_VERSION" != "$LATEST_CORE_VERSION" ]; then
echo "Needs Core update!"
echo "update=1" >> $GITHUB_OUTPUT
else
echo "update=0" >> $GITHUB_OUTPUT
fi
working-directory: charts/self-host/templates
- name: Get Latest Web Version
id: get-web
uses: bitwarden/gh-actions/get-release-version@main
with:
repository: bitwarden/clients
monorepo: true
monorepo-project: web
trim: true
- name: Check if Web Version needs updating
id: web-update
env:
LATEST_WEB_VERSION: ${{ steps.get-web.outputs.version }}
run: |
WEB_VERSION=$(sed -r -n '/define "bitwarden.webVersionDefault"/!b;n;'\
's/\{\{- "([0-9]+\.[0-9]+\.[0-9]+)" -\}\}/\1/p' helpers.tpl)
echo "Web Version: $WEB_VERSION"
echo "Latest Web Version: $LATEST_WEB_VERSION"
if [ "$WEB_VERSION" != "$LATEST_WEB_VERSION" ]; then
echo "Needs Web update!"
echo "update=1" >> $GITHUB_OUTPUT
else
echo "update=0" >> $GITHUB_OUTPUT
fi
working-directory: charts/self-host/templates
- name: Verify if image versions are on Docker Hub
id: verify-versions
env:
COREVERSION: ${{ steps.get-core.outputs.version }}
WEBVERSION: ${{ steps.get-web.outputs.version }}
run: |
echo "Checking..."
coreimages=( "admin" "api" "attachments" "events" "icons" "identity" "notifications" "scim" "sso" "mssqlmigratorutility" )
test_image() {
image=$1
version=$2
tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/bitwarden/$image/tags/"|jq '."results"[]["name"]' | grep $version | cat)
if [[ -z "$tag" ]]; then
echo "$image - $version - NOT FOUND!"
echo "Stopping..."
exit 1
else
echo "$image - $tag - FOUND"
fi
}
echo "Core Images ($COREVERSION)..."
for key in "${!coreimages[@]}"
do
image=${coreimages[$key]}
test_image $image $COREVERSION
done
echo "Web Image ($WEBVERSION)..."
test_image "web" $WEBVERSION
update-versions:
name: "Update Versions"
if: |
needs.setup.outputs.core_version_update == 1 ||
needs.setup.outputs.web_version_update == 1
runs-on: ubuntu-22.04
needs: setup
environment: Production
permissions:
contents: write
pull-requests: write
steps:
- name: Log in to Azure - CI subscription
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
with:
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@main
with:
keyvault: "bitwarden-ci"
secrets: "github-gpg-private-key,
github-gpg-private-key-passphrase,
github-pat-bitwarden-devops-bot-repo-scope"
- name: Checkout Branch
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: main
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
with:
gpg_private_key: ${{ steps.retrieve-secrets.outputs.github-gpg-private-key }}
passphrase: ${{ steps.retrieve-secrets.outputs.github-gpg-private-key-passphrase }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Set up Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "bitwarden-devops-bot"
- name: Create version branch
id: create-branch
run: |
NAME=version_bump_${{ github.ref_name }}_$(date +"%Y-%m-%d")
git switch -c $NAME
echo "name=$NAME" >> $GITHUB_OUTPUT
- name: Update Core Version
env:
VERSION: ${{ needs.setup.outputs.core_version }}
run: sed -i '/define "bitwarden.coreVersionDefault"/!b;n;c{{- "'$VERSION'" -}}' helpers.tpl
working-directory: charts/self-host/templates
- name: Update Web Version
env:
VERSION: ${{ needs.setup.outputs.web_version }}
run: sed -i '/define "bitwarden.webVersionDefault"/!b;n;c{{- "'$VERSION'" -}}' helpers.tpl
working-directory: charts/self-host/templates
- name: Update Chart appVersion
env:
VERSION: ${{ needs.setup.outputs.core_version }}
run: "sed -i -e 's/appVersion:.*/appVersion: '$VERSION'/' Chart.yaml"
working-directory: charts/self-host
- name: Check if version changed
id: version-changed
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changes_to_commit=TRUE" >> $GITHUB_OUTPUT
else
echo "changes_to_commit=FALSE" >> $GITHUB_OUTPUT
echo "No changes to commit!";
fi
- name: Commit files
if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }}
run: git commit -m "Updated core and web versions" -a
- name: Push changes
if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }}
env:
PR_BRANCH: ${{ steps.create-branch.outputs.name }}
run: git push -u origin $PR_BRANCH
- name: Create versions PR
if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }}
env:
GH_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}
PR_BRANCH: ${{ steps.create-branch.outputs.name }}
TITLE: "Update core and web versions"
run: |
PR_URL=$(gh pr create --title "$TITLE" \
--base "$BASE_BRANCH" \
--head "$PR_BRANCH" \
--label "automated pr" \
--body "
## Type of change
- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [X] Other
## Objective
Automated version updates to core and web versions in charts/self-host/templates/helpers.tpl.
Automated version update to appVersion in charts/self-host/Chart.yaml")
echo "pr_number=${PR_URL##*/}" >> $GITHUB_OUTPUT
- name: Approve PR
if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.create-pr.outputs.pr_number }}
run: gh pr review $PR_NUMBER --approve
- name: Merge PR
if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }}
env:
GH_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}
PR_NUMBER: ${{ steps.create-pr.outputs.pr_number }}
run: gh pr merge $PR_NUMBER --squash --auto --delete-branch