Repository navigation
176 lines (156 loc) · 5.39 KB
/
Copy pathci-build.yml
File metadata and controls
176 lines (156 loc) · 5.39 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
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@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.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 }}
merge:
name: Merge (${{ matrix.image }})
needs: [build]
runs-on: ubuntu-latest
if: needs.build.outputs.push-image == 'true'
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
image: [api, live-control-gateway, cron]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Merge ${{ matrix.image }}
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: ${{ matrix.image }}
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}
# Deploys reference the commit SHA tag. It is derived from the commit alone, so re-running a
# single job produces the same tag instead of pointing at an image that was never built.
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: |
{"tag": "${{ github.sha }}"}
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: |
{"tag": "${{ github.sha }}"}
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 }}