Skip to content

Commit dae1a55

Browse files
committed
Add release script for app-interface
1 parent dc866fc commit dae1a55

File tree

6 files changed

+352
-44
lines changed

6 files changed

+352
-44
lines changed

.github/workflows/tag_release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ on:
44
branches:
55
- prod-hccm
66
- prod-ros
7+
env:
8+
BRANCH: ${{ github.base_ref }}
9+
710
jobs:
811
tag_release:
912
runs-on: ubuntu-latest
1013
steps:
1114
- uses: actions/checkout@v5
1215
with:
13-
ref: ${{ github.head_ref || github.ref_name }}
16+
ref: ${{ env.BRANCH }}
1417
- run: |
1518
git fetch --prune --unshallow
1619
- name: Tag this release
@@ -32,6 +35,6 @@ jobs:
3235
TAG="r.$DATE.$MINOR_VERSION"
3336
git config --local user.email "[email protected]"
3437
git config --local user.name "Cost Management Release Action"
35-
git log $(git tag --list | tail -1)..prod-stable | git tag -a $TAG -F -
38+
git log $(git tag --list | tail -1)..${{ env.BRANCH }} | git tag -a $TAG -F -
3639
git push origin $TAG
3740
shell: bash

apps/koku-ui-hccm/RELEASE.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ This doc describes how to release Koku UI to each staging environment. Note that
66

77
The release script creates a PR with a unique SHA, used for a namespace \`ref\` in the app-interface repo. The script also ensures that code is always pulled from the correct branches. For example, we always:
88

9-
1. Pull from master when pushing to prod-hccm
9+
1. Pull from master when pushing to stage-hccm
10+
2. Pull from stage-hccm when pushing to prod-hccm
1011

1112
Note: Pushing to master automatically deploys to the stage.
1213

1314
Please allow the PR to build successfully and merge before running the script again.
1415

16+
### Release to stage-hccm
17+
18+
```
19+
sh ../../scripts/release-branch.sh -s
20+
```
21+
1522
### Release to prod-hccm
1623

1724
```
18-
sh scripts/release-branch.sh -p
25+
sh ../../scripts/release-branch.sh -p
1926
```
2027

2128
## Deployment
@@ -27,7 +34,12 @@ Use the latest commit of each branch to update namespaces \`ref\` in the app-int
2734
```
2835
- name: koku-ui-hccm
2936
...
30-
# Prod Stable Deployment
37+
# Stage Deployment
38+
- namespace:
39+
$ref: /services/insights/frontend-operator/namespaces/stage-frontends.yml
40+
ref: 68ce48592f5222029f27f6fb708698013d2f0a58 // Replace with latest SHA for stage-hccm branch
41+
...
42+
# Prod Deployment
3143
- namespace:
3244
$ref: /services/insights/frontend-operator/namespaces/prod-frontends.yml
3345
ref: c7f6c75fd1e895afbc05a2a6d26835fa16a0edfa // Replace with latest SHA for prod-hccm branch

apps/koku-ui-ros/RELEASE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Please allow the PR to build successfully and merge before running the script ag
1414
### Release to stage-ros
1515

1616
```
17-
sh scripts/release-branch.sh -s
17+
sh ../../scripts/release-branch.sh -q
1818
```
1919

2020
### Release to prod-ros
2121

2222
```
23-
sh scripts/release-branch.sh -r
23+
sh ../../scripts/release-branch.sh -r
2424
```
2525

2626
## Deployment
@@ -32,12 +32,12 @@ Use the latest commit of each branch to update namespaces \`ref\` in the app-int
3232
```
3333
- name: koku-ui-ros
3434
...
35-
# Stage Stable Deployment
35+
# Stage Deployment
3636
- namespace:
3737
$ref: /services/insights/frontend-operator/namespaces/stage-frontends.yml
3838
ref: 68ce48592f5222029f27f6fb708698013d2f0a58 // Replace with latest SHA for stage-ros branch
3939
...
40-
# Prod Stable Deployment
40+
# Prod Deployment
4141
- namespace:
4242
$ref: /services/insights/frontend-operator/namespaces/prod-frontends.yml
4343
ref: 77deb707f31b40414e8b13afe23d39e7091fd067 // Replace with latest SHA for prod-ros branch

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
"install:pkgs:links": "npm run install:pkgs && npm install --install-links",
2525
"lint": "npm exec --workspaces -- npm run lint",
2626
"test": "npm exec --workspaces -- npm run test --",
27-
"release:hccm:prod": "sh scripts/release-branch.sh -p",
28-
"release:ros:prod": "sh scripts/release-branch.sh -r",
29-
"release:ros:stage": "sh scripts/release-branch.sh -s",
27+
"release:app-interface:all": "sh scripts/release-app-interface.sh -a",
28+
"release:app-interface:hccm": "sh scripts/release-app-interface.sh -p",
29+
"release:app-interface:ros": "sh scripts/release-app-interface.sh -r",
30+
"release:stage:hccm": "sh scripts/release-branch.sh -s",
31+
"release:stage:ros": "sh scripts/release-branch.sh -q",
32+
"release:prod:hccm": "sh scripts/release-branch.sh -p",
33+
"release:prod:ros": "sh scripts/release-branch.sh -r",
3034
"start:hccm": "npm run -w @koku-ui/koku-ui-hccm start",
3135
"start:ros": "npm run -w @koku-ui/koku-ui-ros start",
3236
"start:onprem": "npm run -w @koku-ui/koku-ui-onprem start"

scripts/release-app-interface.sh

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
#!/bin/sh
2+
3+
default()
4+
{
5+
PATH=/usr/bin:/usr/sbin:${PATH}
6+
export PATH
7+
8+
SCRIPT=`basename $0`
9+
SCRIPT_DIR=`dirname $0`
10+
SCRIPT_DIR=`cd $SCRIPT_DIR; pwd`
11+
TMP_DIR="/tmp/$SCRIPT.$$"
12+
13+
GITLAB_USER=`whoami`
14+
MAIN_BRANCH="main"
15+
HCCM_STAGE_BRANCH="main"
16+
HCCM_PROD_BRANCH="prod-hccm"
17+
ROS_STAGE_BRANCH="stage-ros"
18+
ROS_PROD_BRANCH="prod-ros"
19+
TARGET_BRANCH="master"
20+
TARGET_PROJECT="service/app-interface"
21+
22+
APP_INTERFACE_DIR="$TMP_DIR/app-interface"
23+
APP_INTERFACE_REPO="[email protected]:service/app-interface.git"
24+
APP_INTERFACE_FORK="[email protected]:$GITLAB_USER/app-interface.git"
25+
KOKU_UI_DIR="$TMP_DIR/koku-ui"
26+
KOKU_UI_REPO="[email protected]:project-koku/koku-ui.git"
27+
28+
KOKU_UI_HCCM=koku-ui-hccm
29+
KOKU_UI_ROS=koku-ui-ros
30+
31+
PROD_FRONTENDS=/services/insights/frontend-operator/namespaces/prod-frontends.yml
32+
STAGE_FRONTENDS=/services/insights/frontend-operator/namespaces/stage-frontends.yml
33+
STAGE_MULTICLUSTER_FRONTENDS=/services/insights/frontend-operator/namespaces/stage-multicluster-frontends.yml
34+
35+
DESC_FILE="$TMP_DIR/desc"
36+
DEPLOY_CLOWDER_FILE="$APP_INTERFACE_DIR/data/services/insights/hccm/deploy-clowder.yml"
37+
}
38+
39+
usage()
40+
{
41+
cat <<- EEOOFF
42+
43+
This script will update app-interface with the latest SHA refs from the koku-ui branches below
44+
and either create an MR (default) or push to the origin.
45+
46+
$HCCM_STAGE_BRANCH
47+
$HCCM_PROD_BRANCH
48+
49+
$ROS_PROD_BRANCH
50+
$ROS_STAGE_BRANCH
51+
52+
sh [-x] $SCRIPT [-h|u] -<a|p|r>
53+
54+
OPTIONS:
55+
h Display this message
56+
a Update SHA refs from $HCCM_PROD_BRANCH and $ROS_STAGE_BRANCH to $TARGET_BRANCH
57+
p Update SHA refs from $HCCM_PROD_BRANCH to $TARGET_BRANCH
58+
r Update SHA refs from $ROS_PROD_BRANCH to $TARGET_BRANCH
59+
u Push to upstream
60+
61+
Note: This script lacks permission to push directly upstream, so commits will be pushed to this fork:
62+
$APP_INTERFACE_FORK
63+
64+
EEOOFF
65+
}
66+
67+
cloneAppInterface()
68+
{
69+
mkdir -p $TMP_DIR
70+
cd $TMP_DIR
71+
72+
if [ ! -d "$APP_INTERFACE_DIR" ]; then
73+
git clone $APP_INTERFACE_REPO
74+
fi
75+
}
76+
77+
cloneKokuUI()
78+
{
79+
mkdir -p $TMP_DIR
80+
cd $TMP_DIR
81+
82+
if [ ! -d "$KOKU_UI_DIR" ]; then
83+
git clone $KOKU_UI_REPO
84+
fi
85+
}
86+
87+
createPullRequestDesc()
88+
{
89+
cat <<- EEOOFF > $DESC_FILE
90+
Update Cost Management UI deployments
91+
92+
#### What:
93+
Update Cost Management UI deployments to latest commit
94+
95+
#### Why:
96+
To promote new features, latest bug fixes, and dependency updates
97+
98+
#### Tickets:
99+
N/A
100+
101+
#### Validation:
102+
QE has verified all queued issues
103+
EEOOFF
104+
}
105+
106+
# Use gh in a non-interactive way -- see https://github.com/cli/cli/issues/1718
107+
mergeRequest()
108+
{
109+
DESC=`sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/<br>/g' $DESC_FILE`
110+
SOURCE_BRANCH="cost-management_release.$$"
111+
TITLE="Update Cost Management UI deployments"
112+
113+
cd $APP_INTERFACE_DIR
114+
git remote rename origin upstream
115+
git remote add origin $APP_INTERFACE_FORK
116+
117+
git branch -m $SOURCE_BRANCH
118+
git commit -m "$TITLE" $DEPLOY_CLOWDER_FILE
119+
120+
echo "\n*** Pushing $SOURCE_BRANCH..."
121+
git push \
122+
-o merge_request.create \
123+
-o merge_request.title="$TITLE" \
124+
-o merge_request.description="$DESC" \
125+
-o merge_request.target_project=$TARGET_PROJECT \
126+
-o merge_request.target=$TARGET_BRANCH origin $SOURCE_BRANCH
127+
}
128+
129+
push()
130+
{
131+
echo ""
132+
read -p "*** You are pushing to the $TARGET_BRANCH branch. Continue?" YN
133+
134+
case $YN in
135+
[Yy]* ) echo "\n*** Pushing $TARGET_BRANCH..."; git push -u origin $TARGET_BRANCH;;
136+
[Nn]* ) exit 0;;
137+
* ) echo "Please answer yes or no."; push;;
138+
esac
139+
}
140+
141+
# Get SHA for given namespace ref
142+
#
143+
# Note that the deply-clowder.yml file may contain multiple namespace refs. However, koku-ui-hccm should be defined
144+
# before koku-ui-ros
145+
#
146+
# $1: Which SHA to return; koku-ui-hccm or koku-ui-ros
147+
# $2: The namespace ref
148+
#
149+
getAppInterfaceSHA()
150+
{
151+
RESULT=
152+
SHA=
153+
NAMESPACE_REFS=`grep -n "\$ref: $2" $DEPLOY_CLOWDER_FILE | sed 's| ||g'`
154+
155+
for NAMESPACE_REF in `echo "$NAMESPACE_REFS"`
156+
do
157+
NAMESPACE_LINE=`echo $NAMESPACE_REF | awk -F: '{print $1}'`
158+
COMMIT_LINE=`echo "$NAMESPACE_LINE + 1" | bc`
159+
COMMIT_REF=`head -n $COMMIT_LINE $DEPLOY_CLOWDER_FILE | tail -n 1 | sed 's| ||g'`
160+
SHA="$SHA `echo $COMMIT_REF | awk -F: '{print $2}'`"
161+
done
162+
163+
if [ $1 = $KOKU_UI_HCCM ]; then
164+
RESULT=`echo "$SHA" | awk -F' ' '{print $1}' | sed 's| ||g'`
165+
elif [ $1 = $KOKU_UI_ROS ]; then
166+
RESULT=`echo "$SHA" | awk -F' ' '{print $2}' | sed 's| ||g'`
167+
fi
168+
}
169+
170+
initAppInterfaceSHA()
171+
{
172+
getAppInterfaceSHA $KOKU_UI_HCCM $STAGE_FRONTENDS
173+
HCCM_STAGE_FRONTENDS_SHA="$RESULT"
174+
175+
getAppInterfaceSHA $KOKU_UI_HCCM $STAGE_MULTICLUSTER_FRONTENDS
176+
HCCM_STAGE_MULTICLUSTER_FRONTENDS_SHA="$RESULT"
177+
178+
getAppInterfaceSHA $KOKU_UI_HCCM $PROD_FRONTENDS
179+
HCCM_PROD_FRONTENDS_SHA="$RESULT"
180+
181+
getAppInterfaceSHA $KOKU_UI_ROS $STAGE_FRONTENDS
182+
ROS_STAGE_FRONTENDS_SHA="$RESULT"
183+
184+
getAppInterfaceSHA $KOKU_UI_ROS $STAGE_MULTICLUSTER_FRONTENDS
185+
ROS_STAGE_MULTICLUSTER_FRONTENDS_SHA="$RESULT"
186+
187+
getAppInterfaceSHA $KOKU_UI_ROS $PROD_FRONTENDS
188+
ROS_PROD_FRONTENDS_SHA="$RESULT"
189+
190+
echo "Existing SHA refs..."
191+
echo "koku-ui-hccm stage: $HCCM_STAGE_FRONTENDS_SHA"
192+
echo "koku-ui-hccm stage multicluster: $HCCM_STAGE_MULTICLUSTER_FRONTENDS_SHA"
193+
echo "koku-ui-hccm prod: $HCCM_PROD_FRONTENDS_SHA"
194+
echo "koku-ui-ros stage: $ROS_STAGE_FRONTENDS_SHA"
195+
echo "koku-ui-ros stage multicluster: $ROS_STAGE_MULTICLUSTER_FRONTENDS_SHA"
196+
echo "koku-ui-ros prod: $ROS_PROD_FRONTENDS_SHA"
197+
}
198+
199+
initKokuUISHA()
200+
{
201+
cd $KOKU_UI_DIR
202+
203+
HCCM_STAGE_SHA=`git rev-parse origin/$HCCM_STAGE_BRANCH`
204+
HCCM_PROD_SHA=`git rev-parse origin/$HCCM_PROD_BRANCH`
205+
ROS_STAGE_SHA=`git rev-parse origin/$ROS_STAGE_BRANCH`
206+
ROS_PROD_SHA=`git rev-parse origin/$ROS_PROD_BRANCH`
207+
208+
echo "Latest SHA refs..."
209+
echo "koku-ui-hccm stage: $HCCM_STAGE_SHA"
210+
echo "koku-ui-hccm prod: $HCCM_PROD_SHA"
211+
echo "koku-ui-ros stage: $ROS_STAGE_SHA"
212+
echo "koku-ui-ros prod: $ROS_PROD_SHA"
213+
}
214+
215+
updateDeploySHA()
216+
{
217+
if [ "$UPDATE_SHA_HCCM" = true ]; then
218+
sed "s|$HCCM_PROD_FRONTENDS_SHA|$HCCM_PROD_SHA|" $DEPLOY_CLOWDER_FILE > ${DEPLOY_CLOWDER_FILE}.tmp
219+
mv ${DEPLOY_CLOWDER_FILE}.tmp $DEPLOY_CLOWDER_FILE
220+
221+
if [ "$HCCM_STAGE_FRONTENDS_SHA" != "$MAIN_BRANCH" ]; then
222+
sed "s|$HCCM_STAGE_FRONTENDS_SHA|$HCCM_STAGE_SHA|" $DEPLOY_CLOWDER_FILE > ${DEPLOY_CLOWDER_FILE}.tmp
223+
mv ${DEPLOY_CLOWDER_FILE}.tmp $DEPLOY_CLOWDER_FILE
224+
fi
225+
if [ "$HCCM_STAGE_MULTICLUSTER_FRONTENDS_SHA" != "$MAIN_BRANCH" ]; then
226+
sed "s|$HCCM_STAGE_MULTICLUSTER_FRONTENDS_SHA|$HCCM_STAGE_SHA|" $DEPLOY_CLOWDER_FILE > ${DEPLOY_CLOWDER_FILE}.tmp
227+
mv ${DEPLOY_CLOWDER_FILE}.tmp $DEPLOY_CLOWDER_FILE
228+
fi
229+
fi
230+
231+
if [ "$UPDATE_SHA_ROS" = true ]; then
232+
sed "s|$ROS_PROD_FRONTENDS_SHA|$ROS_PROD_SHA|" $DEPLOY_CLOWDER_FILE |
233+
sed "s|$ROS_STAGE_FRONTENDS_SHA|$ROS_STAGE_SHA|" |
234+
sed "s|$ROS_STAGE_MULTICLUSTER_FRONTENDS_SHA|$ROS_STAGE_SHA|" > ${DEPLOY_CLOWDER_FILE}.tmp
235+
mv ${DEPLOY_CLOWDER_FILE}.tmp $DEPLOY_CLOWDER_FILE
236+
fi
237+
}
238+
239+
# main()
240+
{
241+
default
242+
243+
while getopts hapru c; do
244+
case $c in
245+
a) UPDATE_SHA_HCCM=true
246+
UPDATE_SHA_ROS=true;;
247+
p) UPDATE_SHA_HCCM=true;;
248+
r) UPDATE_SHA_ROS=true;;
249+
u) PUSH=true;;
250+
h) usage; exit 0;;
251+
\?) usage; exit 1;;
252+
esac
253+
done
254+
255+
if [ -z "$UPDATE_SHA_HCCM" -a -z "$UPDATE_SHA_ROS" ]; then
256+
usage
257+
exit 1
258+
fi
259+
260+
echo "\n*** Releasing $TARGET_BRANCH...\n"
261+
262+
cloneAppInterface
263+
cloneKokuUI
264+
265+
initAppInterfaceSHA
266+
initKokuUISHA
267+
268+
updateDeploySHA
269+
270+
if [ "$?" -eq 0 ]; then
271+
if [ -n "$PUSH" ]; then
272+
push
273+
else
274+
createPullRequestDesc
275+
mergeRequest
276+
fi
277+
else
278+
echo "\n*** Cannot not push. No changes or check for conflicts"
279+
fi
280+
281+
rm -rf $TMP_DIR
282+
}

0 commit comments

Comments
 (0)