-
Notifications
You must be signed in to change notification settings - Fork 2
54 lines (48 loc) · 2.07 KB
/
deploy.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
name: Deploy on push
on:
push:
defaults:
run:
shell: bash
# We use a PAT
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
# because the GITHUB_TOKEN has only access to the Combostrap Organisation
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
jobs:
check-commits:
runs-on: ubuntu-latest
steps:
- name: Check out the site repository
uses: actions/checkout@v3
- name: Get the last commit hash on main
run: |
set -Eeuo pipefail
echo "LAST_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Check out the deploy repository
uses: actions/checkout@v3
with:
repository: gerardnico/kube-argocd
path: kube-argocd
token: ${{ secrets.ARGOCD_GITHUB_TOKEN }}
- name: Update commit in Kubernetes deployment manifest
env:
GITHUB_TOKEN: ${{ secrets.ARGOCD_GITHUB_TOKEN }}
run: |
echo "Patch Deployment with the last commit ($LAST_COMMIT)"
set -Eeuo pipefail
cd kube-argocd || (echo 'Fail Cd' && exit 1)
# Patch with the last commit the app deployment
kubectl patch --local -f com-combostrap/com-combostrap-deployment.yml -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"com-combostrap\",\"env\":[{\"name\":\"DOKU_DOCKER_GIT_SITE_COMMIT\",\"$LAST_COMMIT\":\"new\"}]}]}}}}"
# Do we have changes?
CHANGES_COUNT=$(git diff --name-only | wc -l)
if [ "$CHANGES_COUNT" == '0' ]; then
echo "No changes should not happen on push"
exit 1;
fi
echo "Deployment file has changed, pushing it"
git config --global user.email "[email protected]"
git config --global user.name "Nico"
git add com-combostrap/com-combostrap-deployment.yml
git commit -m "Updated commit in com-combostrap-deployment.yml (GitHub Workflow)"
git push origin main
echo "Done"