-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (186 loc) · 6.38 KB
/
build-test-release.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
name: Main
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request: {}
env:
APP_NAME: samling
IMAGE_NAME: samling
BUILD_CACHE_IMAGE_NAME: samling-cache
jobs:
clippy:
name: Check for common code mistakes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run clippy
continue-on-error: true
run: cargo clippy -- -D warnings
fmt:
name: Check code format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run rustfmt
continue-on-error: true
run: cargo fmt --all -- --check
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --release
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: jacobsvante/cargo-deny-action@v1
build-docker-image:
name: Build Docker image
runs-on: ubuntu-latest
if: ${{ github.repository == 'hyperkliv/samling' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ secrets.DOCKERHUB_USER }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: |
type=registry,ref=${{ secrets.DOCKERHUB_USER }}/${{ env.BUILD_CACHE_IMAGE_NAME }}:${{ github.ref_name }}
type=registry,ref=${{ secrets.DOCKERHUB_USER }}/${{ env.BUILD_CACHE_IMAGE_NAME }}:main
cache-to: |
type=registry,ref=${{ secrets.DOCKERHUB_USER }}/${{ env.BUILD_CACHE_IMAGE_NAME }}:${{ github.ref_name }},compression=zstd,mode=max
test-docker-image:
name: Test Docker image
runs-on: ubuntu-latest
needs: [build-docker-image]
if: ${{ github.repository == 'hyperkliv/samling' }}
steps:
- name: Log in to Docker Hub registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Create network
run: docker network create test
- name: Start postgres container
run: |
docker run \
--name postgres \
--network test \
--rm \
--detach \
--env POSTGRES_DB=samling \
--env POSTGRES_USER=samling \
--env POSTGRES_PASSWORD=samling \
--hostname postgres \
postgres:14.5-alpine3.16
until docker exec postgres pg_isready; do sleep 0.5; done
- name: Start samling container
run: |
docker run \
--publish 8080:8080 \
--network test \
--rm \
--detach \
--env LOG_LEVEL=info \
--env SECRET=abc123 \
--env DB_NAME=samling \
--env DB_HOST=postgres \
--env DB_USER=samling \
--env DB_PASSWORD=samling \
--env DB_AUTO_MIGRATE=true \
--env CLOUDFLARE_ACCOUNT_ID=abc \
--env CLOUDFLARE_TOKEN=123 \
${{ secrets.DOCKERHUB_USER }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
sleep 1
- name: Check /api/readyz response
run: |
curl http://127.0.0.1:8080/api/readyz > output.json
jq . output.json
[[ $(jq .ok output.json) == true ]]
- name: Notify hyperkliv/www-samling-io
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
repository: hyperkliv/www-samling-io
event-type: new-samling-docker-image
client-payload: '{"sha": "${{ github.sha }}"}'
version-tag-docker-image:
name: Add version tags to Docker image
needs: [test-docker-image]
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: read
repository-projects: read
if: ${{ github.repository == 'hyperkliv/samling' && github.ref_type == 'tag' }}
steps:
- name: Get the version
id: version
run: echo version=${GITHUB_REF_NAME/v/} >> $GITHUB_OUTPUT
shell: bash
- uses: jacobsvante/[email protected]
if: ${{ steps.version.outputs.version != '' }}
with:
version: ${{ steps.version.outputs.version }}
image: ${{ secrets.DOCKERHUB_USER }}/${{ env.IMAGE_NAME }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Notify hyperkliv/www-samling-io
uses: peter-evans/repository-dispatch@v2
if: ${{ steps.version.outputs.version != '' }}
with:
token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
repository: hyperkliv/www-samling-io
event-type: new-samling-docker-image
client-payload: '{"sha": "${{ github.sha }}", "version": "${{ steps.version.outputs.version }}" }'
release-please:
needs: [clippy, cargo-deny, test]
runs-on: ubuntu-latest
if: ${{ github.repository == 'hyperkliv/samling' && github.ref == 'refs/heads/main' }}
permissions:
contents: write
pull-requests: write
steps:
- uses: googleapis/release-please-action@v4
id: release
- name: Tag major and minor versions in Git
if: ${{ steps.release.outputs.release_created }}
uses: jacobsvante/[email protected]
with:
major: ${{ steps.release.outputs.major }}
minor: ${{ steps.release.outputs.minor }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
if: ${{ github.repository == 'hyperkliv/samling' && github.ref_type == 'tag' }}
permissions:
contents: write
pull-requests: write
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo publish