-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (199 loc) · 6.11 KB
/
ci-orchestrator.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
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
name: CI orchestrator
on:
pull_request:
branches:
- main
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
checks: write
pull-requests: write
env:
PACKAGES_DIR: source
CORE_REGEX: bronze|silver|gold
CORE_PREFIX: core
NONCORE_PREFIX: bundle
jobs:
#
# License and Markdown Check
#
ci_base:
uses: Energinet-DataHub/.github/.github/workflows/ci-base.yml@v14
with:
skip_license_check: true
secrets:
dh3serviceaccount_privatekey: ${{ secrets.dh3serviceaccount_privatekey }}
#
# Compile Protobuf Contracts
#
ci_bronze_contracts:
name: Compile Protobuf Contracts
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if contract files has changed
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
is_changed:
- source/bronze/src/bronze/infrastructure/contracts/**
- name: Compile protobuf descriptor files
uses: ./.github/actions/compile-proto
if: ${{ steps.changes.outputs.is_changed == 'true' }}
#
# Build Package Matrix
#
ci_matrix:
name: Build Package Matrix
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.package_matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Discover Pyproject
uses: ./.github/actions/discover-pyproject
id: package_matrix
with:
path: ${{ env.PACKAGES_DIR }}
#
# Test Packages
#
ci_test:
name: Test Packages
runs-on: ubuntu-24.04
needs: ci_matrix
strategy:
matrix: ${{ fromJson(needs.ci_matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if ${{ matrix.inputs.name }} has changed
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
is_changed:
- ${{ matrix.inputs.path }}/**
- name: Test ${{ matrix.inputs.name }}
uses: ./.github/actions/uvtest
if: ${{ steps.changes.outputs.is_changed == 'true' }}
with:
name: ${{ matrix.inputs.name }}
path: ${{ matrix.inputs.path }}
pytest_addopts: --ignore=tests/container_tests
- name: Upload artifacts for ${{ matrix.inputs.name }}
uses: ./.github/actions/upload-release-artifacts
if: ${{ steps.changes.outputs.is_changed == 'true' }}
with:
name: ${{ matrix.inputs.name }}
path: ${{ matrix.inputs.path }}
core_regex: ${{ env.CORE_REGEX }}
core_prefix: ${{ env.CORE_PREFIX }}
noncore_prefix: ${{ env.NONCORE_PREFIX }}
#
# Prepare Release Matrix
#
ci_prepare_prerelease:
name: Prepare prerelease
runs-on: ubuntu-24.04
needs: ci_test
outputs:
matrix: ${{ steps.create_matrix.outputs.matrix }}
any_artifact: ${{ steps.list_artifacts.outputs.any_artifact }}
steps:
- name: Download Core Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ env.CORE_PREFIX }}-*
path: ${{ github.workspace }}/dist/${{ env.CORE_PREFIX }}/
merge-multiple: true
- name: Download Bundle Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ env.NONCORE_PREFIX }}-*
path: ${{ github.workspace }}/dist/
merge-multiple: true
- name: List Artifacts Contents
id: list_artifacts
run: |
if [ -d "${{ github.workspace }}/dist" ]; then
ls -alR "${{ github.workspace }}/dist"
echo "any_artifact=true" >> $GITHUB_OUTPUT
else
echo "No artifacts found"
echo "any_artifact=false" >> $GITHUB_OUTPUT
fi
- name: Create release matrix
shell: python
if: ${{ steps.list_artifacts.outputs.any_artifact == 'true' }}
id: create_matrix
run: |
from pathlib import Path
import json
import os
artifacts = []
for p in Path("${{ github.workspace }}/dist").iterdir():
if p.is_dir():
artifacts.append({"name": p.name, "path": str(p)})
print(json.dumps({"inputs": artifacts}, indent=2))
include_statement = json.dumps({"inputs": artifacts})
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"matrix={include_statement}", file=fh)
ci_create_prerelease:
name: Create prerelease
runs-on: ubuntu-24.04
needs: ci_prepare_prerelease
if: ${{ needs.ci_prepare_prerelease.outputs.any_artifact == 'true' }}
strategy:
matrix: ${{ fromJson(needs.ci_prepare_prerelease.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Core Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ env.CORE_PREFIX }}-*
path: ${{ github.workspace }}/dist/${{ env.CORE_PREFIX }}/
merge-multiple: true
- name: Download Bundle Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ env.NONCORE_PREFIX }}-*
path: ${{ github.workspace }}/dist/
merge-multiple: true
- name: Create prerelease for ${{ matrix.inputs.name }}
uses: ./.github/actions/create-prerelease
with:
name: ${{ matrix.inputs.name }}
path: ${{ matrix.inputs.path }}
issue-number: ${{ github.event.number }}
#
# Branch policy status check
#
allow_merge_ci_orchestrator:
runs-on: ubuntu-24.04
needs:
[
ci_base,
ci_bronze_contracts,
ci_matrix,
ci_test,
ci_prepare_prerelease,
ci_create_prerelease,
]
if: |
always()
steps:
- name: Verify if merge is allowed
run: |
echo "${{ toJSON(needs) }}"
if [[ ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} = true ]]; then
echo "Failed"
exit 1
fi