-
Notifications
You must be signed in to change notification settings - Fork 0
265 lines (245 loc) · 7.78 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Rust CI/CD
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [created]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --test main -- --nocapture
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install mdBook
run: cargo install mdbook
- name: Setup mdBook if not exists
run: |
if [ ! -d "docs" ]; then
mkdir docs
cd docs
mdbook init
echo "# ServerForge" > src/chapter_1.md
echo "# Summary" > src/SUMMARY.md
echo "" >> src/SUMMARY.md
echo "- [Chapter 1](./chapter_1.md)" >> src/SUMMARY.md
fi
- name: Build API docs
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-deps --all-features
- name: Build mdBook docs
run: mdbook build docs
- name: Combine docs
run: |
mkdir -p ./public
cp -r ./target/doc ./public/api
cp -r ./docs/book ./public/guide
echo '<meta http-equiv="refresh" content="0; url=serverforge/index.html">' > ./public/index.html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.TOKEN }}
publish_dir: ./public
force_orphan: true
publish-dry-run:
name: Publish Dry Run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: publish
args: --dry-run
release:
name: Release
needs: [ check, fmt, docs, publish-dry-run ]
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
strategy:
matrix:
target: [ x86_64-unknown-linux-gnu ]
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
cd target/${{ matrix.target }}/release
echo "Contents of release directory:"
ls -la
BINARY_NAME="server_forge"
if [[ ! -f "$BINARY_NAME" && ! -f "${BINARY_NAME}.exe" ]]; then
echo "Error: Expected binary $BINARY_NAME not found"
exit 1
fi
echo "Found binary: $BINARY_NAME"
ARCHIVE_NAME="server_forge-${{ matrix.target }}"
case ${{ matrix.target }} in
x86_64-pc-windows-msvc)
7z a "../../../${ARCHIVE_NAME}.zip" "${BINARY_NAME}.exe"
;;
*)
tar czvf "../../../${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME"
;;
esac
echo "Created archive: ${ARCHIVE_NAME}"
cd ../../..
ls -la "${ARCHIVE_NAME}"*
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.TOKEN }}
file: server_forge-${{ matrix.target }}.*
asset_name: server_forge-${{ matrix.target }}
tag: ${{ github.ref }}
overwrite: true
publish-crates-io:
name: Publish to crates.io
needs: [release]
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CRATES_IO_TOKEN }}
linux-packages:
name: Create Linux Packages
needs: [release]
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create DEB package
run: |
mkdir -p serverforge_${{ github.ref_name }}_amd64/DEBIAN
echo "Package: serverforge
Version: ${{ github.ref_name }}
Architecture: amd64
Maintainer: Chidozie C. Okafor <chidosiky2015@gmail.com>
Description: ServerForge - A robust server setup and maintenance tool" > serverforge_${{ github.ref_name }}_amd64/DEBIAN/control
mkdir -p serverforge_${{ github.ref_name }}_amd64/usr/local/bin
cp target/x86_64-unknown-linux-gnu/release/serverforge serverforge_${{ github.ref_name }}_amd64/usr/local/bin/
dpkg-deb --build serverforge_${{ github.ref_name }}_amd64
- name: Create RPM package
run: |
mkdir -p ~/rpmbuild/{SPECS,SOURCES}
cp target/x86_64-unknown-linux-gnu/release/serverforge ~/rpmbuild/SOURCES/
echo "Name: serverforge
Version: ${{ github.ref_name }}
Release: 1
Summary: ServerForge - A robust server setup and maintenance tool
License: MIT
%description
ServerForge is a robust server setup and maintenance tool.
%files
/usr/local/bin/serverforge
%install
mkdir -p %{buildroot}/usr/local/bin
cp %{_sourcedir}/serverforge %{buildroot}/usr/local/bin/
%clean
rm -rf %{buildroot}" > ~/rpmbuild/SPECS/serverforge.spec
rpmbuild -ba ~/rpmbuild/SPECS/serverforge.spec
- name: Upload Linux packages
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: |
./serverforge_${{ github.ref_name }}_amd64.deb
~/rpmbuild/RPMS/x86_64/serverforge-${{ github.ref_name }}-1.x86_64.rpm
asset_name: |
serverforge_${{ github.ref_name }}_amd64.deb
serverforge-${{ github.ref_name }}-1.x86_64.rpm
asset_content_type: application/octet-stream