-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (95 loc) · 3.6 KB
/
commit-to-helm-chart.yml
File metadata and controls
109 lines (95 loc) · 3.6 KB
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
# Use APPLICATION_NAME if you have a single image tag to commit, or APPLICATIONS_LIST if multiple
name: Deploy
on:
workflow_call:
inputs:
APPLICATION_NAME:
required: false
type: string
APPLICATIONS_LIST:
required: false
type: string
APPLICATIONS_PREFIX:
required: false
type: string
ENVIRONMENT:
required: true
type: string
HELM_CHART_PATH:
required: true
type: string
INFRA_REPO:
required: true
type: string
INFRA_REPO_BRANCH:
required: true
type: string
REGISTRY_URL:
required: true
type: string
SUPPLIED_ENVS:
required: false
type: string
secrets:
INFRA_SSH_KEY:
required: true
jobs:
argocd:
runs-on: ubuntu-latest
steps:
- name: Check out application code
uses: actions/checkout@v4
- name: Git Commit - get commit author data
run: |-
echo "COMMIT_AUTHOR_NAME=$(git log --format='%an <%ae>' -n 1 HEAD | cut -d '<' -f 2 | cut -d '@' -f 1)" >> $GITHUB_ENV
echo "COMMIT_AUTHOR_EMAIL=$(git log --format='%an <%ae>' -n 1 HEAD | cut -d '<' -f 2 | cut -d '>' -f 1)" >> $GITHUB_ENV
echo "COMMIT_AUTHOR=$(git log --format='%an <%ae>' -n 1 HEAD)" >> $GITHUB_ENV
- name: Infrastructure repo checkout
uses: actions/checkout@v4
with:
repository: ${{ inputs.INFRA_REPO }}
ssh-key: ${{ secrets.INFRA_SSH_KEY }}
ref: ${{ inputs.INFRA_REPO_BRANCH }}
- name: Set new tag
if: ${{ inputs.APPLICATION_NAME != '' && inputs.APPLICATIONS_LIST == '' }}
run: |
yq -i ".standard-app.tag = \"$GITHUB_SHA\"" ${{ inputs.HELM_CHART_PATH }}/${{ inputs.APPLICATION_NAME }}/${{ inputs.ENVIRONMENT }}.values.yaml
- name: Set new tags
if: ${{ inputs.APPLICATION_NAME == '' && inputs.APPLICATIONS_LIST != '' }}
run: |
input=${{ inputs.APPLICATIONS_LIST }}
input="${input#[}"
input="${input%]}"
# Set IFS to comma
IFS=','
# Read the input into an array
read -ra apps <<< "$input"
# Iterate over the array and process each app
for app in "${apps[@]}"; do
echo "Setting tag for app: $app"
yq -i ".standard-app.tag = \"$GITHUB_SHA\"" ${{ inputs.HELM_CHART_PATH }}/${{ inputs.APPLICATIONS_PREFIX }}-$app/${{ inputs.ENVIRONMENT }}.values.yaml
done
# This is an optional step to update envs during deploy. For now this is used by Conduithealth to update API_VERSION env with the deployed commit SHA
- name: Set supplied envs
if: ${{ inputs.SUPPLIED_ENVS != '' }}
run: |
input=${{ inputs.SUPPLIED_ENVS }}
input="${input#[}"
input="${input%]}"
IFS=','
read -ra envs <<< "$input"
for env in "${envs[@]}"; do
key=$(echo "$env" | cut -d '=' -f 1)
value=$(echo "$env" | cut -d '=' -f 2-)
echo "Setting .standard-app.env.$key = $value"
yq -i ".standard-app.env.\"$key\" = \"$value\"" ${{ inputs.HELM_CHART_PATH }}/${{ inputs.APPLICATION_NAME }}/${{ inputs.ENVIRONMENT }}.values.yaml
done
- name: Commit and push
shell: bash
run: |-
git config user.name ${{ env.COMMIT_AUTHOR_NAME }}
git config user.email ${{ env.COMMIT_AUTHOR_EMAIL }}
git add .
git commit -m "Deploy $GITHUB_SHA
Author: ${{ env.COMMIT_AUTHOR }}"
git push origin ${{ inputs.INFRA_REPO_BRANCH }}