-
Notifications
You must be signed in to change notification settings - Fork 13
178 lines (166 loc) · 5.85 KB
/
docker_build.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
name: Build-Publish
on:
push:
branches:
release:
types: [released]
jobs:
build-publish:
name: "Atlantis-${{ matrix.ATLANTIS }} [ ${{ matrix.TF_TG }} ]"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ATLANTIS:
- 0.29.0
TF_TG:
# Terraform 1.9.x
- 'TF-1.9.5 TG-0.63.8'
# Terraform 1.8.x
- 'TF-1.8.5 TG-0.63.8'
# Terraform 1.7.x
- 'TF-1.7.5 TG-0.63.8'
# Terraform 1.6.x
- 'TF-1.6.6 TG-0.63.8'
# Terraform 1.5.x
- 'TF-1.5.7 TG-0.63.8'
# Terraform 1.4.x
- 'TF-1.4.7 TG-0.63.8'
# Terraform 1.3.x
- 'TF-1.3.10 TG-0.63.8'
# Terraform 1.2.x
- 'TF-1.2.9 TG-0.63.8'
# Terraform 1.1.x
- 'TF-1.1.9 TG-0.63.8'
# Terraform 1.0.x
- 'TF-1.0.11 TG-0.63.8'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set Variables
id: vars
run: |
TERRAFORM="$( echo "${TF_TG}" | awk '{print $1}' | sed 's/TF-//g' )"
TERRAGRUNT="$( echo "${TF_TG}" | awk '{print $2}' | sed 's/TG-//g' )"
# Extract git tag or git branch
if echo "${GITHUB_REF}" | grep -q "refs/tags/"; then
SLUG="${GITHUB_REF/refs\/tags\//}"
fi
if echo "${GITHUB_REF}" | grep -q "refs/heads/"; then
SLUG="${GITHUB_REF/refs\/heads\//}"
if echo "${SLUG}" | grep -q '^dependabot\/'; then
SLUG="${SLUG/dependabot\/github_actions\/actions\//dependabot-}"
fi
fi
# Build Docker image tag
if [ "${SLUG}" = "master" ]; then
TAG="${ATLANTIS}-${TERRAFORM}-${TERRAGRUNT}"
else
TAG="${ATLANTIS}-${TERRAFORM}-${TERRAGRUNT}-${SLUG}"
fi
# Output for debugging
echo "ATLANTIS=${ATLANTIS}"
echo "TERRAFORM=${TERRAFORM}"
echo "TERRAGRUNT=${TERRAGRUNT}"
echo "SLUG=${SLUG}"
echo "TAG=${TAG}"
# Store GitHub Action env vars
echo "ATLANTIS=${ATLANTIS}" >> "${GITHUB_ENV}"
echo "TERRAFORM=${TERRAFORM}" >> "${GITHUB_ENV}"
echo "TERRAGRUNT=${TERRAGRUNT}" >> "${GITHUB_ENV}"
echo "TAG=${TAG}" >> "${GITHUB_ENV}"
env:
ATLANTIS: ${{ matrix.ATLANTIS }}
TF_TG: ${{ matrix.TF_TG }}
- name: Build
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build ATLANTIS=${ATLANTIS} TERRAFORM=${TERRAFORM} TERRAGRUNT=${TERRAGRUNT}
env:
RETRIES: 20
- name: Test
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make test ATLANTIS=${ATLANTIS} TERRAFORM=${TERRAFORM} TERRAGRUNT=${TERRAGRUNT}
env:
RETRIES: 20
- name: Tag
run: |
make tag TAG=${TAG}
docker images
if: ${{ github.actor != 'dependabot[bot]' }}
- name: Login
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make login DOCKER_USER=${{ secrets.DOCKER_USERNAME }} DOCKER_PASS=${{ secrets.DOCKER_PASSWORD }}
env:
RETRIES: 20
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
(github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
||
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
||
(github.event_name == 'release' && github.event.action == 'released')
)
- name: Push
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make push TAG=${TAG}
env:
RETRIES: 20
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
(github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
||
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
||
(github.event_name == 'release' && github.event.action == 'released')
)