-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (207 loc) · 7.21 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
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: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features -- --nocapture
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy -- -D warnings
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install mdBook
run: cargo install mdbook
- name: Setup mdBook
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
run: cargo doc --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: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo publish --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
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --target x86_64-unknown-linux-gnu
- name: Package
run: |
cd target/x86_64-unknown-linux-gnu/release
BINARY_NAME="server_forge"
ARCHIVE_NAME="server_forge-x86_64-unknown-linux-gnu.tar.gz"
tar czvf "../../../$ARCHIVE_NAME" "$BINARY_NAME"
- name: Upload binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./server_forge-x86_64-unknown-linux-gnu.tar.gz
asset_name: server_forge-x86_64-unknown-linux-gnu.tar.gz
asset_content_type: application/gzip
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: server_forge-x86_64-unknown-linux-gnu
path: server_forge-x86_64-unknown-linux-gnu.tar.gz
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: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo publish
env:
CARGO_REGISTRY_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: Install dependencies
run: sudo apt-get update && sudo apt-get install -y rpm
- name: Set version
run: echo "VERSION=${GITHUB_REF_NAME#refs/tags/v}" >> $GITHUB_ENV
- name: Download release artifact
uses: actions/download-artifact@v3
with:
name: server_forge-x86_64-unknown-linux-gnu
path: ./
- name: Extract release artifact
run: tar -xzvf server_forge-x86_64-unknown-linux-gnu.tar.gz
- name: Create DEB package
run: |
# Get the version from the environment file
VERSION="${{ env.VERSION }}"
mkdir -p serverforge_${VERSION}_amd64/DEBIAN
echo "Package: serverforge
Version: ${VERSION}
Architecture: amd64
Maintainer: Chidozie C. Okafor <chidosiky2015@gmail.com>
Description: ServerForge - A robust server setup and maintenance tool" > serverforge_${VERSION}_amd64/DEBIAN/control
mkdir -p serverforge_${VERSION}_amd64/usr/local/bin
cp server_forge serverforge_${VERSION}_amd64/usr/local/bin/
dpkg-deb --build serverforge_${VERSION}_amd64
- name: Create RPM package
run: |
# Get the version from the environment file
VERSION="${{ env.VERSION }}"
mkdir -p ~/rpmbuild/{SPECS,SOURCES,BUILD,RPMS,SRPMS}
cp server_forge ~/rpmbuild/SOURCES/
echo "Name: serverforge
Version: ${VERSION}
Release: 1
Summary: ServerForge - A robust server setup and maintenance tool
License: MIT
%description
ServerForge is a robust server setup and maintenance tool.
%install
mkdir -p %{buildroot}/usr/local/bin
cp %{_sourcedir}/server_forge %{buildroot}/usr/local/bin/
%files
/usr/local/bin/server_forge
%clean
rm -rf %{buildroot}" > ~/rpmbuild/SPECS/serverforge.spec
rpmbuild -ba ~/rpmbuild/SPECS/serverforge.spec
- name: Upload DEB package
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./serverforge_${{ env.VERSION }}_amd64.deb
asset_name: serverforge_${{ env.VERSION }}_amd64.deb
asset_content_type: application/octet-stream
- name: Upload RPM package
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ~/rpmbuild/RPMS/x86_64/serverforge-${{ env.VERSION }}-1.x86_64.rpm
asset_name: serverforge-${{ env.VERSION }}-1.x86_64.rpm
asset_content_type: application/octet-stream