Skip to content

Commit 7be88df

Browse files
committed
Show kubernetes resource diffs before merging release
1 parent 7172499 commit 7be88df

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,80 @@ on:
55
branches:
66
- releases/v1
77
types:
8+
- opened
9+
- synchronize
10+
- reopened
811
- closed
912

1013
env:
1114
# Required for action steebchen/kubectl
1215
KUBE_CONFIG_DATA: ${{ secrets.kubeconfig_data_prod }}
1316

1417
jobs:
18+
show-changes:
19+
if: github.event.pull_request.state != 'closed'
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: azure/setup-kubectl@v1
25+
with:
26+
version: v1.18.0
27+
28+
- name: Get resource diffs
29+
run: |
30+
set -e
31+
comment_file=/tmp/k8s_diff.txt
32+
app_manifest=k8s/app.yaml
33+
prod_manifest_dir=k8s.prod
34+
35+
test -e ~/.kube || mkdir ~/.kube
36+
cat <<EOF > ~/.kube/config
37+
$(printf '%s' "$KUBE_CONFIG_DATA" | base64 -d)
38+
EOF
39+
40+
app_diff=$(kubectl diff -f $app_manifest || true)
41+
if [ -n "$app_diff" ]; then
42+
app_diff_msg=$(cat <<EOF
43+
To be applied to prod from $app_manifest:
44+
\`\`\`
45+
$app_diff
46+
\`\`\`
47+
48+
EOF)
49+
fi
50+
51+
prod_diff=$(kubectl diff -Rf $prod_manifest_dir || true)
52+
if [ -n "$prod_diff" ]; then
53+
prod_diff_msg=$(cat <<EOF
54+
To be applied to prod from $prod_manifest_dir:
55+
```
56+
$prod_diff
57+
```
58+
59+
EOF)
60+
fi
61+
62+
cat <<EOF > $comment_file
63+
$app_diff_msg
64+
$prod_diff_msg
65+
EOF
66+
67+
- uses: actions/upload-artifact@v1
68+
with:
69+
name: comment
70+
path: /tmp/k8s_diff.txt
71+
- uses: actions/download-artifact@v1
72+
with:
73+
name: comment
74+
75+
- name: Publish resource diffs
76+
uses: machine-learning-apps/[email protected]
77+
env:
78+
GITHUB_TOKEN: ${{ github.token }}
79+
with:
80+
path: comment/k8s_diff.txt
81+
1582
deploy-prod:
1683
if: github.event.pull_request.merged
1784
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)