-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
133 lines (123 loc) · 4.26 KB
/
action.yaml
File metadata and controls
133 lines (123 loc) · 4.26 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Deploy action
description: 'set node version and node sha before committing changes and deploy version'
inputs:
PAT:
description: 'PAT from repo'
required: true
NAMESPACE:
description: 'Namespace'
required: true
default: ''
NAME:
description: 'Name'
required: false
default: ''
SERVICES:
description: 'Services'
required: false
default: ''
version:
description: 'build.outputs.version'
required: true
default: ''
env:
description: 'build.outputs.env'
required: true
default: 'stage'
SLACK_TOKEN:
description: 'slack token'
required: false
default: ''
SLACK_CHANNEL:
description: 'slack channel'
required: false
default: ''
runs:
using: 'composite'
steps:
- uses: actions/checkout@v6
with:
repository: entrecode/ec.argocd
token: ${{ inputs.PAT }}
ref: main
- name: run yq eval node
run: |
if [[ -n ${SERVICES} ]]; then
IFS="," read -r -a SRV <<< "${SERVICES}"
for I in "${SRV[@]}"; do
IFS=":" read -r SERVICE YQ_PATH <<< "${I}"
YQ_PATH=${YQ_PATH:-.node}
VERSION=${YQ_PATH}.version GITSHA=${YQ_PATH}.gitsha yq eval -i 'eval(strenv(VERSION)) = "${{ inputs.version }}" | eval(strenv(GITSHA)) = "${{ github.sha }}"' apps/${{ inputs.env }}/${{ inputs.NAMESPACE }}/${SERVICE}/version.yaml
done
fi
if [[ -n ${NAME} ]]; then
yq eval -i '.node.version = "${{ inputs.version }}" | .node.gitsha = "${{ github.sha }}"' apps/${{ inputs.env }}/${{ inputs.NAMESPACE }}/${{ inputs.NAME }}/version.yaml
fi
shell: bash
env:
SERVICES: ${{ inputs.SERVICES }}
NAME: ${{ inputs.NAME }}
- name: Commit changes
run: |
export GITHUB_EVENT_PUSHER_NAME=${{ github.event.pusher.name }}
export GITHUB_EVENT_PUSHER_EMAIL=${{ github.event.pusher.email }}
git config --global user.name "${GITHUB_EVENT_PUSHER_NAME:-${GITHUB_ACTOR:-github-actions[bot]}}"
git config --global user.email "${GITHUB_EVENT_PUSHER_EMAIL:-41898282+github-actions[bot]}@users.noreply.github.com}"
if [[ -n ${NAME} ]]; then
MESSAGE+="[${{ inputs.env }}/${{ inputs.NAMESPACE }}/${NAME}] Deploy ${{ inputs.version }}"
MESSAGE+=$'\n'
fi
if [[ -n ${SERVICES} ]]; then
IFS="," read -r -a SRV <<< "${SERVICES}"
for I in "${SRV[@]}"; do
IFS=":" read -r SERVICE YQ_PATH <<< "${I}"
MESSAGE+="[${{ inputs.env }}/${{ inputs.NAMESPACE }}/${SERVICE}] Deploy ${{ inputs.version }}"
MESSAGE+=$'\n'
done
fi
if ! git diff --quiet; then
git commit -am "${MESSAGE}"
else
echo "No changes – Commit is skipped."
exit 0
fi
git pull --rebase
git push
shell: bash
env:
SERVICES: ${{ inputs.SERVICES }}
NAME: ${{ inputs.NAME }}
- name: Hector slack Notifications with name as input
if: inputs.NAMESPACE == 'hector' && inputs.env == 'prod' && inputs.SLACK_TOKEN != '' && inputs.SLACK_CHANNEL != '' && inputs.NAME != '' && inputs.SERVICES == ''
uses: slackapi/slack-github-action@v3
with:
method: chat.postMessage
token: ${{ inputs.SLACK_TOKEN }}
payload: |
channel: ${{ inputs.SLACK_CHANNEL }}
attachments:
- color: "28a745"
fields:
- value: "Neue Version ${{ inputs.version }} von ${{ inputs.NAME }} ausgerollt"
- name: Set Service Name
if: inputs.NAME == '' && inputs.SERVICES != ''
run: |
if [[ -n ${SERVICES} ]]; then
IFS="," read -r -a SRV <<< "${SERVICES}"
echo "SERVICE_NAME=${SRV[0]}" >> $GITHUB_ENV
fi
shell: bash
env:
SERVICES: ${{ inputs.SERVICES }}
- name: Hector slack Notifications with services as input
if: inputs.NAMESPACE == 'hector' && inputs.env == 'prod' && inputs.SLACK_TOKEN != '' && inputs.SLACK_CHANNEL != '' && inputs.NAME == '' && inputs.SERVICES != ''
uses: slackapi/slack-github-action@v3
with:
method: chat.postMessage
token: ${{ inputs.SLACK_TOKEN }}
payload: |
channel: ${{ inputs.SLACK_CHANNEL }}
attachments:
- color: "28a745"
fields:
- value: "Neue Version ${{ inputs.version }} von ${{ env.SERVICE_NAME }} ausgerollt"