Repository navigation
149 lines (132 loc) · 4.54 KB
/
Copy pathci-build.yml
File metadata and controls
149 lines (132 loc) · 4.54 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
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
types: [ opened, reopened, synchronize ]
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 (${{ matrix.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: repository-server-tunit
project: RepositoryServer.Tests/RepositoryServer.Tests.csproj
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 ${{ matrix.name }} tests
run: |
set -euo pipefail
dotnet test -c Release --project ${{ matrix.project }}
# 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 tagged manifest.
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: repository-server
dockerfile: docker/RepositoryServer.Dockerfile
platform:
- name: linux/amd64
runner: ubuntu-latest
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 this image's digest.
merge:
name: Merge (repository-server)
needs: [build, tests]
runs-on: ubuntu-latest
if: needs.build.outputs.push-image == 'true'
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.merge.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Merge repository-server
id: merge
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: repository-server
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}
# Deploys pin the manifest digest rather than a tag: no per-build tags are created, and
# re-running this job alone sends the same digest.
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-repository-server-prod
client-payload: |
{"digest": "${{ needs.merge.outputs.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 }}