-
Notifications
You must be signed in to change notification settings - Fork 2
265 lines (265 loc) · 10.2 KB
/
deploy.yaml
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Deploy FDS
on:
workflow_dispatch:
push:
branches:
- '[0-9]+.[0-9]+.[0-9]+'
- 'nightly-[0-9]+.[0-9]+.[0-9]+-[0-9]+'
- '!main'
- '!test/**'
jobs:
prepare-build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
outputs:
IMAGE_NAME: ${{ steps.image-selector.outputs.IMAGE_NAME }}
TAG: ${{ steps.tag-selector.outputs.TAG }}
WORKFLOW_ID: ${{ steps.workflow-selector.outputs.WORKFLOW_ID }}
IS_LATEST: ${{ steps.latest-selector.outputs.IS_LATEST }}
steps:
- name: Extract image name
id: image-selector
run: |
if [[ $GITHUB_REF_NAME = nightly* ]]
then
IMAGE_NAME=fds-nightly
else
IMAGE_NAME=fds
fi
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: Select Tag
id: tag-selector
run: |
TAG=$(echo ${GITHUB_REF_NAME#nightly-} | grep -oEi [0-9]+\.[0-9]+\.[0-9]+)
echo "TAG=${TAG}" >> $GITHUB_ENV
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
- name: Extract Workflow ID
id: workflow-selector
run: |
if [[ ${{ env.IMAGE_NAME }} = *nightly ]]
then
echo "WORKFLOW_ID=deploy.nightly.yaml" >> $GITHUB_OUTPUT
else
echo "WORKFLOW_ID=deploy.yaml" >> $GITHUB_OUTPUT
fi
- name: Check if new build version is latest
id: latest-selector
continue-on-error: true
run: |
if [[ ${{ contains(github.ref_name, 'nightly') }} == true ]]
then
echo "IS_LATEST=false" >> $GITHUB_OUTPUT
else
REGEX=[0-9]+\.[0-9]+\.[0-9]+
LATEST_VERSION=0.0.0
echo "IS_LATEST=true" >> $GITHUB_OUTPUT
VERSIONS=$(curl --silent "https://api.github.com/users/${{ github.repository_owner }}/packages/container/${{ env.IMAGE_NAME }}/versions" --stderr - \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" | \
grep -E "[[:space:]]+\"${REGEX}\"" | grep -oEi ${REGEX})
for VERSION in $VERSIONS; do
[ "$VERSION" \> "$LATEST_VERSION" ] && LATEST_VERSION=$VERSION
done
if [ "${{ env.TAG }}" \< "${LATEST_VERSION}" ]
then
echo "IS_LATEST=false" >> $GITHUB_OUTPUT
fi
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Cleanup test branches
continue-on-error: true
run: |
REGEX_RELEASE="test/(nightly\-)?[0-9]+\.[0-9]+\.[0-9]+(\-[0-9]+)?"
BRANCHES=$(curl --silent -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/branches" --stderr - | grep -oEi ${REGEX_RELEASE})
for BRANCH in ${BRANCHES}; do
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git push origin --delete ${BRANCH}
done
- name: Merge branch into main
if: ${{ !contains(github.ref_name, 'nightly') }}
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git fetch --unshallow
git switch main
REGEX=[0-9]+\.[0-9]+\.[0-9]+
DOCKERFILE_VERSION=$(grep -oEI /FDS-?${REGEX}/ Dockerfile | grep -oEI ${REGEX})
if [ "${{ github.ref_name }}" \> "${DOCKERFILE_VERSION}" ]
then
git merge origin/${{ github.ref_name }}
git push
fi
docker-hub_build-and-push:
needs: [prepare-build]
if: ${{ !contains(github.ref_name, 'nightly') }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract image and tags
run: |
IMAGE=${{ github.repository_owner }}/${{ needs.prepare-build.outputs.IMAGE_NAME }}
echo "IMAGE=${IMAGE}" >> $GITHUB_ENV
if [[ ${{ needs.prepare-build.outputs.IS_LATEST }} == true ]]
then
echo "TAGS=${IMAGE}:${{ needs.prepare-build.outputs.TAG }},${IMAGE}:latest" >> $GITHUB_ENV
else
echo "TAGS=${IMAGE}:${{ needs.prepare-build.outputs.TAG }}" >> $GITHUB_ENV
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.TAGS }}
labels: ${{ steps.meta.outputs.labels }}
ghcr-io_build-and-push:
needs: [prepare-build]
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image and tags
run: |
IMAGE=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ needs.prepare-build.outputs.IMAGE_NAME }}
echo "IMAGE=${IMAGE}" >> $GITHUB_ENV
if [[ ${{ needs.prepare-build.outputs.IS_LATEST }} == true ]]
then
echo "TAGS=${IMAGE}:${{ needs.prepare-build.outputs.TAG }},${IMAGE}:latest" >> $GITHUB_ENV
else
echo "TAGS=${IMAGE}:${{ needs.prepare-build.outputs.TAG }}" >> $GITHUB_ENV
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.TAGS }}
labels: ${{ steps.meta.outputs.labels }}
trigger-batchfds-workflow:
needs: [prepare-build, ghcr-io_build-and-push]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check BatchFDS compatibility
env:
MIN_VERSION: 6.7.1
run: |
version_greater_equal() {
printf '%s\n%s\n' "$2" "$1" | sort --check=quiet --version-sort
}
if version_greater_equal ${{ needs.prepare-build.outputs.TAG }} ${MIN_VERSION}; then
echo "BUILD_BatchFDS=true" >> $GITHUB_ENV
else
echo "BUILD_BatchFDS=false" >> $GITHUB_ENV
fi
- name: Trigger BatchFDS build
if: env.BUILD_BatchFDS == 'true'
env:
TOKEN: ${{ secrets.DISPATCH_WORKFLOWS_PUBLIC_BCL_TOKEN }}
ORG: openbcl
REPO: batchfds
run: |
curl -L -X POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${TOKEN}" \
https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${{ needs.prepare-build.outputs.WORKFLOW_ID }}/dispatches \
-d "{\"ref\":\"main\",\"inputs\": {\"tag\": \"${{ needs.prepare-build.outputs.TAG }}\"}}"
trigger-cocafds-workflow:
needs: [prepare-build, ghcr-io_build-and-push]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check CoCaFDS compatibility
env:
MIN_VERSION: 6.7.5
run: |
version_greater_equal() {
printf '%s\n%s\n' "$2" "$1" | sort --check=quiet --version-sort
}
if version_greater_equal ${{ needs.prepare-build.outputs.TAG }} ${MIN_VERSION}; then
echo "BUILD_CoCaFDS=true" >> $GITHUB_ENV
else
echo "BUILD_CoCaFDS=false" >> $GITHUB_ENV
fi
- name: Trigger BUILD_CoCaFDS build
if: env.BUILD_CoCaFDS == 'true'
env:
TOKEN: ${{ secrets.DISPATCH_WORKFLOWS_PRIVATE_BCL_TOKEN }}
ORG: brandschutzconsult
REPO: cocafds
run: |
curl -L -X POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${TOKEN}" \
https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${{ needs.prepare-build.outputs.WORKFLOW_ID }}/dispatches \
-d "{\"ref\":\"main\",\"inputs\": {\"tag\": \"${{ needs.prepare-build.outputs.TAG }}\"}}"
trigger-propti-workflow:
needs: [prepare-build, ghcr-io_build-and-push]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check Propti compatibility
env:
MIN_VERSION: 6.7.4
run: |
version_greater_equal() {
printf '%s\n%s\n' "$2" "$1" | sort --check=quiet --version-sort
}
if version_greater_equal ${{ needs.prepare-build.outputs.TAG }} ${MIN_VERSION}; then
echo "BUILD_Propti=true" >> $GITHUB_ENV
else
echo "BUILD_Propti=false" >> $GITHUB_ENV
fi
- name: Trigger BUILD_Propti build
if: env.BUILD_Propti == 'true'
env:
TOKEN: ${{ secrets.DISPATCH_WORKFLOWS_PROPTI_TRISTAN_HEHNEN }}
ORG: FireDynamics
REPO: propti
run: |
curl -L -X POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${TOKEN}" \
https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${{ needs.prepare-build.outputs.WORKFLOW_ID }}/dispatches \
-d "{\"ref\":\"master\",\"inputs\": {\"tag\": \"${{ needs.prepare-build.outputs.TAG }}\"}}"