-
Notifications
You must be signed in to change notification settings - Fork 2
96 lines (83 loc) · 2.87 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
name: CI
on:
push:
paths-ignore:
- '**.md'
env:
IMAGE: ghcr.io/giganticminecraft/seichi-game-data-server
jobs:
app-lint-and-test:
name: Lint and test application
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
# TODO: read from rust-toolchain.toml
toolchain: "1.62.1"
profile: "default"
# > selecting a toolchain either by action or manual `rustup` calls should happen
# > before the plugin, as it uses the current rustc version as its cache key
# https://github.com/Swatinem/rust-cache/tree/cb2cf0cc7c5198d3364b9630e2c3d457f160790c#example-usage
- uses: Swatinem/rust-cache@v2
with:
working-directory: server
# buf CLIがビルドに必要
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# GitHubのUIにエラー/警告を表示してくれるので actions-rs/cargo を利用している
- name: Cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path server/Cargo.toml --all -- --check
- name: Cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --manifest-path server/Cargo.toml
- name: Cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path server/Cargo.toml --all-features
build-image:
name: Build docker image (and publish on master)
needs: [ app-lint-and-test ]
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE }}
tags: |
type=sha,prefix=sha-,suffix=,format=short
type=schedule,pattern={{date 'YYYYMMDD'}}
- name: Build (and push if on master)
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./server
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
# すべてのビルドステージのすべてのレイヤーをキャッシュして欲しいのでmode=max
cache-to: type=gha,mode=max