-
Notifications
You must be signed in to change notification settings - Fork 2
178 lines (156 loc) · 4.8 KB
/
ci.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
name: CI
on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version
id: set-version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION=$(git rev-parse HEAD)
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
test:
name: Test on ${{ matrix.os.name }}
runs-on: ${{ matrix.os.runner }}
strategy:
matrix:
os:
- name: Linux
runner: ubuntu-latest
- name: Windows
runner: windows-latest
- name: macOS
runner: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Lint
run: make lint
- name: Build
run: make build
- name: Test
run: make test
publish-container-images:
name: Publish container images
runs-on: ubuntu-latest
needs: [prepare, test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/hathora/ci
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=sha
flavor: |
latest=auto
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/bake-action@v4
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: default
push: ${{ github.event_name != 'pull_request' }}
set: |
default.args.BUILD_VERSION=${{ needs.prepare.outputs.version }}
publish-binaries:
name: Publish binary for ${{ matrix.platform.os }} ${{ matrix.arch }}
needs: [prepare, test]
strategy:
matrix:
platform:
[
{ os: "linux", runner: "ubuntu-latest" },
{ os: "darwin", runner: "macos-latest" },
{ os: "windows", runner: "windows-latest" },
]
arch: [amd64, arm64]
runs-on: ${{ matrix.platform.runner }}
env:
HAS_SECRET: ${{ secrets.SIGNING_CERTIFICATE_PFX }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build binaries
env:
TARGETOS: ${{ matrix.platform.os }}
TARGETARCH: ${{ matrix.arch }}
BUILD_VERSION: ${{ needs.prepare.outputs.version }}
BINARY_SUFFIX: ${{ matrix.platform.os == 'windows' && '.exe' || '' }}
run: make build
- name: Sign the Windows binary
if: env.HAS_SECRET && github.repository_owner == 'hathora' && matrix.platform.os == 'windows'
run: |
$decodedCertificate = [System.Convert]::FromBase64String("${{ secrets.SIGNING_CERTIFICATE_PFX }}")
[System.IO.File]::WriteAllBytes("certificate.pfx", $decodedCertificate)
& "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe" sign /debug /fd sha256 /f certificate.pfx /u 1.3.6.1.5.5.7.3.2 "bin\hathora-windows-${{ matrix.arch }}.exe"
del certificate.pfx
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: hathora-${{ matrix.platform.os }}-${{ matrix.arch }}${{ matrix.platform.os == 'windows' && '.exe' || '' }}
path: bin/hathora-*
release:
name: Release
runs-on: ubuntu-latest
needs: [publish-container-images, publish-binaries]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: bin
pattern: hathora-*
merge-multiple: true
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: bin/*
generate_release_notes: true