-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (104 loc) · 3.78 KB
/
publish-templates.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
name: Publish IaC Templates
on:
push:
branches: [ "main" ]
paths-ignore:
- "**.md"
workflow_dispatch:
env:
RED: \033[0;31m
GREEN: \033[0;32m
ORANGE: \033[0;33m
NC: \033[0m
TICK: \xE2\x9C\x94
CROSS: \xE2\x9C\x98
jobs:
validate-structure:
strategy:
fail-fast: false
matrix:
cloud: [aws]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./${{ matrix.cloud }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Show directory structure
run: tree -a .
- name: Test directory structure
run: |
for MODULE in *; do
if [[ -d "${MODULE}" ]]; then
(
cd "${MODULE}"
echo -e "${{ env.GREEN }}Validating ${MODULE}${{ env.NC }}"
for MAJOR_VERSION in *; do
echo -e "${{ env.GREEN }}> ${MAJOR_VERSION}${{ env.NC }}"
if [[ ! -d "${MAJOR_VERSION}" ]]; then
echo -e '${{ env.RED }}Error: Should be a directory.${{ env.NC }}'
exit 1
fi
if [[ ! "${MAJOR_VERSION}" =~ ^v[0-9]+$ ]]; then
echo -e '${{ env.RED }}Error: Name should be a major version (v[0-9])${{ env.NC }}'
exit 1
fi
VERSION_FILE="${MAJOR_VERSION}/.version"
if [[ ! -f "${VERSION_FILE}" ]]; then
echo -e '${{ env.RED }}Error: .version file does not exist.${{ env.NC }}'
exit 1
fi
VERSION=$(cat "${VERSION_FILE}")
if [[ ! "${VERSION}" =~ ^${MAJOR_VERSION}\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${{ env.RED }}Error: Version is incorrect, expected ${MAJOR_VERSION}.X.X${{ env.NC }}"
exit 1
fi
echo -e '${{ env.GREEN }}${{ env.TICK }}${{ env.NC }}'
done
)
fi
done
aws-publish:
needs: validate-structure
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: ./aws
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Publish templates to S3
run: |
for MODULE in *; do
if [[ -d "${MODULE}" ]]; then
(
cd "${MODULE}"
echo -e "${{ env.GREEN }}Updating ${MODULE}${{ env.NC }}"
for MAJOR_VERSION in *; do
VERSION_FILE="${MAJOR_VERSION}/.version"
VERSION=$(cat "${VERSION_FILE}")
echo -e "${{ env.GREEN }}> ${MODULE}@${VERSION}${{ env.NC }}"
S3_URI="s3://${{ vars.S3_BUCKET_NAME }}/${MODULE}/${VERSION//.//}/"
if aws s3 ls "${S3_URI}"; then
echo -e "${{ env.ORANGE }}Version already published${{ env.NC }}"
elif (( $? == 1 )); then
echo -e "${{ env.GREEN }}Publishing new version${{ env.NC }}"
aws s3 sync "${MAJOR_VERSION}" "${S3_URI}" --acl public-read
echo -e '${{ env.GREEN }}${{ env.TICK }}${{ env.NC }}'
else
echo -e '${{ env.RED }}${{ env.CROSS }} Failed to list bucket${{ env.NC }}'
exit 1
fi
done
)
fi
done