Skip to content

Commit 1bade89

Browse files
committed
ci: add github actions for continuous integration and releases
Implement workflows to automate testing, linting, build checks, and cross-platform release packaging. - ci.yml: runs tests, clippy, and formatting on pull requests and main. - release.yml: builds binaries for Linux, macOS, and Windows upon tag creation and publishes them to GitHub Releases.
1 parent 76d6524 commit 1bade89

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
env:
16+
CARGO_TERM_COLOR: always
17+
18+
jobs:
19+
build:
20+
name: Build and test
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Rust
28+
uses: dtolnay/rust-toolchain@stable
29+
with:
30+
components: rustfmt, clippy
31+
32+
- name: Cache cargo
33+
uses: Swatinem/rust-cache@v2
34+
35+
- name: Check format
36+
run: cargo fmt --all -- --check
37+
38+
- name: Run clippy
39+
run: cargo clippy --all-targets --all-features -- -D warnings
40+
41+
- name: Run tests
42+
run: cargo test --all --all-features
43+
44+
- name: Build release
45+
run: cargo build --release --locked
46+
47+
- name: Upload binary artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: safe-clean-linux-x86_64
51+
path: target/release/safe-clean

.github/workflows/release.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
15+
jobs:
16+
build:
17+
name: Build ${{ matrix.target }}
18+
runs-on: ${{ matrix.os }}
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- os: ubuntu-latest
25+
target: x86_64-unknown-linux-gnu
26+
binary: safe-clean
27+
archive: safe-clean-linux-x86_64.tar.gz
28+
29+
- os: macos-latest
30+
target: x86_64-apple-darwin
31+
binary: safe-clean
32+
archive: safe-clean-macos-x86_64.tar.gz
33+
34+
- os: macos-latest
35+
target: aarch64-apple-darwin
36+
binary: safe-clean
37+
archive: safe-clean-macos-aarch64.tar.gz
38+
39+
- os: windows-latest
40+
target: x86_64-pc-windows-msvc
41+
binary: safe-clean.exe
42+
archive: safe-clean-windows-x86_64.zip
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Rust
49+
uses: dtolnay/rust-toolchain@stable
50+
with:
51+
targets: ${{ matrix.target }}
52+
53+
- name: Cache cargo
54+
uses: Swatinem/rust-cache@v2
55+
56+
- name: Build release
57+
run: cargo build --release --locked --target ${{ matrix.target }}
58+
59+
- name: Package Unix binary
60+
if: runner.os != 'Windows'
61+
run: |
62+
mkdir -p dist
63+
cp target/${{ matrix.target }}/release/${{ matrix.binary }} dist/
64+
tar -czf ${{ matrix.archive }} -C dist ${{ matrix.binary }}
65+
66+
- name: Package Windows binary
67+
if: runner.os == 'Windows'
68+
shell: pwsh
69+
run: |
70+
New-Item -ItemType Directory -Force -Path dist
71+
Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary }}" "dist/${{ matrix.binary }}"
72+
Compress-Archive -Path "dist/${{ matrix.binary }}" -DestinationPath "${{ matrix.archive }}"
73+
74+
- name: Upload release artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: ${{ matrix.archive }}
78+
path: ${{ matrix.archive }}
79+
80+
release:
81+
name: Create GitHub Release
82+
needs: build
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- name: Download artifacts
87+
uses: actions/download-artifact@v4
88+
with:
89+
path: artifacts
90+
91+
- name: Create release
92+
env:
93+
GH_TOKEN: ${{ github.token }}
94+
run: |
95+
gh release create "${GITHUB_REF_NAME}" \
96+
artifacts/*/* \
97+
--title "${GITHUB_REF_NAME}" \
98+
--notes "Automated release for safe-clean ${GITHUB_REF_NAME}"

0 commit comments

Comments
 (0)