-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (141 loc) · 4.84 KB
/
rust-ci.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
name: rust-ci
on:
push:
paths:
- '.github/workflows/rust-ci.yml'
- '.sqlx/**'
- 'Cargo.lock'
- 'Cargo.toml'
- 'Makefile.toml'
- 'crates/**'
- 'migrations/**'
- 'rust-toolchain.toml'
- 'rustfmt.toml'
pull_request:
workflow_dispatch:
env:
CARGO_MAKE_RUN_CODECOV: true
CARGO_TERM_COLOR: always
IMAGE_NAME_CLI: carlomicieli/trenako-cli
IMAGE_NAME_MIGRATIONS: carlomicieli/trenako-migrations
IMAGE_NAME_SERVER: carlomicieli/trenako-server
LOCAL_REGISTRY: localhost:5000
LOGGING__FORMAT: compact
LOGGING__LEVEL: info
REGISTRY: ghcr.io
SQLX_OFFLINE: true
jobs:
checks:
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup the rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo make
run: cargo install [email protected]
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
continue-on-error: false
- name: Toolchain info
run: |
rustc --version
cargo --version --verbose
cargo make --version
- name: Run cargo check
run: cargo make check
- name: Check formatting with rustfmt
run: cargo make fmt-check
- name: Linting with Clippy
run: cargo make clippy
- name: Run the unit tests
run: cargo make unit-test
- name: Run the integration tests
run: cargo make integration-test
docker:
runs-on: ubuntu-22.04
needs: checks
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
permissions:
contents: read
packages: write
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for the server Docker image
id: meta-server
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME_SERVER }}
${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME_SERVER }}
tags: |
# set latest tag for default branch
# type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=raw,value={{date 'YYYYMMDDHHmm'}}-{{sha}}
- name: Extract metadata (tags, labels) for the migrations Docker image
id: meta-migrations
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME_MIGRATIONS }}
${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME_MIGRATIONS }}
tags: |
# set latest tag for default branch
# type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=raw,value={{date 'YYYYMMDDHHmm'}}-{{sha}}
- name: Extract metadata (tags, labels) for the cli Docker image
id: meta-cli
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME_CLI }}
${{ env.LOCAL_REGISTRY }}/${{ env.IMAGE_NAME_CLI }}
tags: |
# set latest tag for default branch
# type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=raw,value={{date 'YYYYMMDDHHmm'}}-{{sha}}
- name: Build and export to Docker (server)
uses: docker/build-push-action@v5
with:
context: .
file: docker/server.dockerfile
load: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}
- name: Build and export to Docker (migrations)
uses: docker/build-push-action@v5
with:
context: .
file: docker/migrations.dockerfile
load: true
tags: ${{ steps.meta-migrations.outputs.tags }}
labels: ${{ steps.meta-migrations.outputs.labels }}
- name: Build and export to Docker (cli)
uses: docker/build-push-action@v5
with:
context: .
file: docker/cli.dockerfile
load: true
tags: ${{ steps.meta-cli.outputs.tags }}
labels: ${{ steps.meta-cli.outputs.labels }}
- name: List docker images
run: docker image ls