Skip to content

Commit 41a9c1d

Browse files
committed
Add CI/CD workflows for testing and releases
1 parent c8c79fc commit 41a9c1d

File tree

2 files changed

+236
-0
lines changed

2 files changed

+236
-0
lines changed

.github/workflows/ci.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
rust: [stable, beta]
20+
exclude:
21+
# Only test beta on one OS to speed up CI
22+
- os: macos-latest
23+
rust: beta
24+
- os: windows-latest
25+
rust: beta
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Install Rust toolchain
32+
uses: dtolnay/rust-toolchain@master
33+
with:
34+
toolchain: ${{ matrix.rust }}
35+
components: rustfmt, clippy
36+
37+
- name: Cache cargo registry
38+
uses: actions/cache@v4
39+
with:
40+
path: |
41+
~/.cargo/bin/
42+
~/.cargo/registry/index/
43+
~/.cargo/registry/cache/
44+
~/.cargo/git/db/
45+
target/
46+
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-cargo-${{ matrix.rust }}-
49+
50+
- name: Run tests
51+
run: cargo test --verbose
52+
53+
- name: Check formatting
54+
run: cargo fmt --all -- --check
55+
56+
- name: Run clippy
57+
run: cargo clippy --all-targets --all-features -- -D warnings
58+
59+
build:
60+
name: Build
61+
runs-on: ${{ matrix.os }}
62+
strategy:
63+
matrix:
64+
os: [ubuntu-latest, macos-latest, windows-latest]
65+
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v4
69+
70+
- name: Install Rust toolchain
71+
uses: dtolnay/rust-toolchain@master
72+
with:
73+
toolchain: stable
74+
75+
- name: Cache cargo registry
76+
uses: actions/cache@v4
77+
with:
78+
path: |
79+
~/.cargo/bin/
80+
~/.cargo/registry/index/
81+
~/.cargo/registry/cache/
82+
~/.cargo/git/db/
83+
target/
84+
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
85+
restore-keys: |
86+
${{ runner.os }}-cargo-build-
87+
88+
- name: Build release
89+
run: cargo build --release --verbose
90+
91+
- name: Upload artifacts
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: ${{ matrix.os }}-binary
95+
path: target/release/sshdb${{ matrix.os == 'windows-latest' && '.exe' || '' }}
96+
retention-days: 1
97+

.github/workflows/release.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
release:
13+
name: Release ${{ matrix.target }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- os: ubuntu-latest
20+
target: x86_64-unknown-linux-gnu
21+
artifact_name: sshdb-linux-x86_64
22+
asset_name: sshdb-linux-x86_64.tar.gz
23+
- os: macos-latest
24+
target: x86_64-apple-darwin
25+
artifact_name: sshdb-macos-x86_64
26+
asset_name: sshdb-macos-x86_64.tar.gz
27+
- os: macos-14
28+
target: aarch64-apple-darwin
29+
artifact_name: sshdb-macos-aarch64
30+
asset_name: sshdb-macos-aarch64.tar.gz
31+
- os: windows-latest
32+
target: x86_64-pc-windows-msvc
33+
artifact_name: sshdb-windows-x86_64
34+
asset_name: sshdb-windows-x86_64.zip
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Install Rust toolchain
41+
uses: dtolnay/rust-toolchain@master
42+
with:
43+
toolchain: stable
44+
45+
- name: Add target
46+
run: rustup target add ${{ matrix.target }}
47+
48+
- name: Cache cargo registry
49+
uses: actions/cache@v4
50+
with:
51+
path: |
52+
~/.cargo/bin/
53+
~/.cargo/registry/index/
54+
~/.cargo/registry/cache/
55+
~/.cargo/git/db/
56+
target/
57+
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
58+
restore-keys: |
59+
${{ runner.os }}-${{ matrix.target }}-
60+
61+
- name: Build release binary
62+
run: cargo build --release --target ${{ matrix.target }} --verbose
63+
64+
- name: Prepare release asset (Windows)
65+
if: matrix.os == 'windows-latest'
66+
shell: pwsh
67+
run: |
68+
cd target/${{ matrix.target }}/release
69+
Compress-Archive -Path sshdb.exe -DestinationPath ${{ github.workspace }}/${{ matrix.asset_name }} -Force
70+
71+
- name: Prepare release asset (Unix)
72+
if: matrix.os != 'windows-latest'
73+
shell: bash
74+
run: |
75+
cd target/${{ matrix.target }}/release
76+
tar czf ${{ github.workspace }}/${{ matrix.asset_name }} sshdb
77+
78+
- name: Upload release asset
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: ${{ matrix.artifact_name }}
82+
path: ${{ matrix.asset_name }}
83+
retention-days: 30
84+
85+
create-release:
86+
name: Create Release
87+
needs: release
88+
runs-on: ubuntu-latest
89+
permissions:
90+
contents: write
91+
92+
steps:
93+
- name: Checkout code
94+
uses: actions/checkout@v4
95+
with:
96+
fetch-depth: 0
97+
98+
- name: Download all artifacts
99+
uses: actions/download-artifact@v4
100+
with:
101+
path: artifacts
102+
103+
- name: Extract version from tag
104+
id: tag
105+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
106+
107+
- name: Create Release
108+
uses: softprops/action-gh-release@v1
109+
with:
110+
tag_name: ${{ github.ref }}
111+
name: Release ${{ steps.tag.outputs.VERSION }}
112+
body: |
113+
## Release ${{ steps.tag.outputs.VERSION }}
114+
115+
### Binaries
116+
117+
- `sshdb-linux-x86_64.tar.gz` - Linux (x86_64)
118+
- `sshdb-macos-x86_64.tar.gz` - macOS (Intel)
119+
- `sshdb-macos-aarch64.tar.gz` - macOS (Apple Silicon)
120+
- `sshdb-windows-x86_64.zip` - Windows (x86_64)
121+
122+
### Installation
123+
124+
Extract the archive and place the binary in your PATH.
125+
126+
#### Linux/macOS
127+
```bash
128+
tar xzf sshdb-*.tar.gz
129+
sudo mv sshdb /usr/local/bin/
130+
```
131+
132+
#### Windows
133+
Extract the zip file and add the directory to your PATH.
134+
files: |
135+
artifacts/*/sshdb-*.tar.gz
136+
artifacts/*/sshdb-*.zip
137+
draft: false
138+
prerelease: false
139+

0 commit comments

Comments
 (0)