-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (67 loc) · 2.53 KB
/
k8s-prepare.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
name: 'K8s: Prepare k8s-manifests Deploy PR'
on:
push:
branches: [ releases/k8s-manifests ]
env:
BRANCH_RELEASE: releases/k8s-manifests
BRANCH_DEPLOY: deploys/k8s-manifests
jobs:
k8s-prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ env.BRANCH_RELEASE }}
- name: Configure .kube/config
run: |
test -e ~/.kube || mkdir ~/.kube
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
- name: Install kubectl-neat-diff
run: |
sudo wget https://github.com/sh0rez/kubectl-neat-diff/releases/download/v0.1.0/kubectl-neat-diff-linux-amd64 -O /usr/local/bin/kubectl-neat-diff
sudo chmod +x /usr/local/bin/kubectl-neat-diff
echo "KUBECTL_EXTERNAL_DIFF=kubectl-neat-diff" >> $GITHUB_ENV
- name: Generate diff
run: |
(
find . \
-maxdepth 1 \
-type d \
-not -name '.*' \
-print0 \
| sort -z \
| xargs -r0 -n 1 kubectl diff -Rf || true
) > /tmp/kube.diff
- name: Create/update pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# build PR description body
diff_size=$(stat -c%s /tmp/kube.diff)
pr_head_describe="$(git describe --always --tag)"
pr_body="$(cat <<EOF
Deploy ${BRANCH_RELEASE} ${pr_head_describe}
\`kubectl diff\` reports that applying ${pr_head_describe} will change:
\`\`\`diff
$(if (( diff_size > 50000)); then echo 'diff too big; review locally'; else cat /tmp/kube.diff; fi)
\`\`\`
EOF
)"
# generate initial commit for base if needed
if ! git ls-remote --exit-code --heads origin "${BRANCH_DEPLOY}"; then
git fetch origin --unshallow
_first_projected_commit=$(git rev-list --max-parents=0 --first-parent HEAD)
git push origin "${_first_projected_commit}:refs/heads/${BRANCH_DEPLOY}"
fi
# check for existing PR
_existing_pr_number=$(hub pr list -h "${BRANCH_RELEASE}" -f '%I')
if [ -n "${_existing_pr_number}" ]; then
echo "Updating PR #${_existing_pr_number}"
hub issue update "${_existing_pr_number}" -F <(echo "${pr_body}")
else
echo "Opening PR"
hub pull-request -b "${BRANCH_DEPLOY}" -h "${BRANCH_RELEASE}" -F <(echo "${pr_body}") > /tmp/pr.json
fi
# - uses: mxschmitt/action-tmate@v3
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}