Repository navigation
198 lines (176 loc) · 6.45 KB
/
Copy pathci-build.yml
File metadata and controls
198 lines (176 loc) · 6.45 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
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
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
workflow_call:
inputs:
latest:
description: 'Tag image as latest'
required: false
type: boolean
default: false
push:
description: 'Push image to registry (makes it push if it usually wouldnt)'
required: false
type: boolean
default: false
workflow_dispatch:
name: ci-build
env:
REGISTRY: ghcr.io
DOTNET_VERSION: 11.0.x
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
dotnet-version: '${{ env.DOTNET_VERSION }}'
- name: Run tests
run: |
set -euo pipefail
dotnet test -c Release --solution OpenShockBackend.slnx \
--results-directory "artifacts/test-results" \
-- \
--report-trx \
--report-trx-filename test-results.trx
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: test-results
path: artifacts/test-results
if-no-files-found: warn
# Each image builds on a runner matching its own architecture (no QEMU) and pushes an untagged
# image by digest. `merge` then stitches each image's digests into one multi-arch tag.
build:
name: Build (${{ matrix.image.name }} / ${{ matrix.platform.name }})
runs-on: ${{ matrix.platform.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
image:
- name: api
dockerfile: docker/API.Dockerfile
- name: live-control-gateway
dockerfile: docker/LiveControlGateway.Dockerfile
- name: cron
dockerfile: docker/Cron.Dockerfile
platform:
- name: linux/amd64
runner: ubuntu-latest
- name: linux/arm64
runner: ubuntu-24.04-arm
env:
PUSH_IMAGE: ${{ inputs.push || (github.ref_protected && github.event_name != 'pull_request') }}
outputs:
push-image: ${{ env.PUSH_IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Build ${{ matrix.image.name }}
uses: ./.github/actions/build-app
with:
dockerfile: ${{ matrix.image.dockerfile }}
image: ${{ matrix.image.name }}
platform: ${{ matrix.platform.name }}
push: ${{ env.PUSH_IMAGE }}
registry: ${{ env.REGISTRY }}
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
# Not a matrix: matrix jobs can't expose a per-entry output, and deploys need every image's digest.
merge:
name: Merge images
needs: [build]
runs-on: ubuntu-latest
if: needs.build.outputs.push-image == 'true'
permissions:
contents: read
packages: write
outputs:
api-digest: ${{ steps.api.outputs.digest }}
gateway-digest: ${{ steps.gateway.outputs.digest }}
cron-digest: ${{ steps.cron.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Merge api
id: api
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: api
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}
- name: Merge live-control-gateway
id: gateway
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: live-control-gateway
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}
- name: Merge cron
id: cron
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: cron
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}
# Deploys pin each image's manifest digest rather than a tag: no per-build tags are created,
# and re-running a deploy job alone sends the same digests.
deploy-prod-workflow:
runs-on: ubuntu-latest
needs: merge
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'master' }}
environment: production
steps:
- name: Send repository dispatch
uses: OpenShock/actions/repository-dispatch@21ca2d511bca92cf24fb502fa302f82700822584 # v1.1.1
with:
repo: openshock/kubernetes-cluster-gitops
event-type: update-backend-prod
client-payload: |
{"digests": {"api": "${{ needs.merge.outputs.api-digest }}", "live-control-gateway": "${{ needs.merge.outputs.gateway-digest }}", "cron": "${{ needs.merge.outputs.cron-digest }}"}}
token: ${{ secrets.GITOPS_PAT }}
deploy-staging:
runs-on: ubuntu-latest
needs: merge
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'develop' }}
environment: staging
steps:
- name: Send repository dispatch
uses: OpenShock/actions/repository-dispatch@21ca2d511bca92cf24fb502fa302f82700822584 # v1.1.1
with:
repo: openshock/kubernetes-cluster-gitops
event-type: update-backend-staging
client-payload: |
{"digests": {"api": "${{ needs.merge.outputs.api-digest }}", "live-control-gateway": "${{ needs.merge.outputs.gateway-digest }}", "cron": "${{ needs.merge.outputs.cron-digest }}"}}
token: ${{ secrets.GITOPS_PAT }}
deploy-dev:
runs-on: ubuntu-latest
needs: merge
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'develop' }}
environment: development
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: |
.github
- uses: ./.github/actions/watchtower-update
with:
url: ${{ vars.WATCHTOWER_URL }}
token: ${{ secrets.WATCHTOWER_TOKEN }}