-
Notifications
You must be signed in to change notification settings - Fork 16
178 lines (168 loc) · 4.99 KB
/
rust.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
name: Rust
on:
push:
branches: ["master"]
tags:
- "v*"
pull_request:
branches: ["master"]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
BINARY_NAME: mlc
RUSTFLAGS: "-Dwarnings"
jobs:
test_own_readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run
run: cargo run -- ./README.md -d
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- uses: actions-rust-lang/rustfmt@v1
- run: cargo clippy --all-targets --all-features
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo test --verbose
build_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: musl-tools # provides musl-gcc
version: 1.0
- name: "Get the Rust toolchain"
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl
components: rustfmt, clippy
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release --verbose --target=x86_64-unknown-linux-musl
- uses: actions/upload-artifact@v4
with:
name: linux
path: ./target/x86_64-unknown-linux-musl/release/${{ env.BINARY_NAME }}
build_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo build --verbose --release
- uses: actions/upload-artifact@v4
with:
name: windows
path: ./target/release/${{ env.BINARY_NAME }}.exe
build_osx:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: aarch64-apple-darwin
- name: Build
run: |
cargo build --verbose --release --target aarch64-apple-darwin
ls ./target
- uses: actions/upload-artifact@v4
with:
name: apple-darwin
path: target/aarch64-apple-darwin/release/${{ env.BINARY_NAME }}
release_docker:
runs-on: ubuntu-latest
needs: [build_osx, build_windows, build_linux, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: linux
path: ./target/release
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set env
run: |
version=${GITHUB_REF#refs/*/}
version=${version:1}
echo "RELEASE_VERSION=$version" >> $GITHUB_ENV
- run: echo Push docker image $RELEASE_VERSION
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PW }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: becheran/mlc:latest,becheran/mlc:${{ env.RELEASE_VERSION }}
release:
runs-on: ubuntu-latest
needs: [release_docker]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v4
with:
name: linux
path: mlc-x86_64-linux
- uses: actions/download-artifact@v4
with:
name: windows
path: mlc-x86_64-windows
- uses: actions/download-artifact@v4
with:
name: apple-darwin
path: mlc-x86_64-apple-darwin
- name: Rename files
run: |
ls
ls mlc-x86_64-linux
ls mlc-x86_64-apple-darwin
ls mlc-x86_64-windows
mv ./mlc-x86_64-linux/mlc mlc
rm -rd ./mlc-x86_64-linux
mv ./mlc mlc-x86_64-linux
mv ./mlc-x86_64-apple-darwin/mlc mlc
rm -rd ./mlc-x86_64-apple-darwin
mv ./mlc mlc-x86_64-apple-darwin
mv ./mlc-x86_64-windows/mlc.exe mlc-x86_64-windows.exe
rm -rd ./mlc-x86_64-windows
ls
- name: GitHub Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
mlc-x86_64-linux
mlc-x86_64-apple-darwin
mlc-x86_64-windows.exe