Skip to content

Commit bcc6077

Browse files
committed
ci(workflows): add github actions for ci and release
Adds GitHub Actions workflows to automate key development processes, including testing, building, and releasing the application. The CI workflow (`ci.yml`) is triggered on pushes and pull requests to the `main` branch. It performs the following steps across Ubuntu, macOS, and Windows runners: - Checks out the repository. - Installs the stable Rust toolchain with clippy and rustfmt components. - Verifies code formatting using `cargo fmt --check`. - Lints the code using `cargo clippy -D warnings`. - Runs all tests using `cargo test --all-targets`. - Builds the project in both debug and release modes. The Release workflow (`release.yml`) is triggered when a version tag matching `v*.*.*` is pushed. It automates the release process: - Builds release binaries for multiple targets: - `x86_64-unknown-linux-gnu` (Ubuntu) - `x86_64-apple-darwin` (macOS Intel) - `aarch64-apple-darwin` (macOS Apple Silicon) - `x86_64-pc-windows-msvc` (Windows) - Packages each binary into an appropriate archive (`.tar.gz` or `.zip`) along with the `LICENSE` and `README.md` files. - Uploads these archives as build artifacts. - Creates a GitHub Release associated with the tag, automatically generating release notes and attaching the packaged binary archives as release assets.
1 parent e0f9cee commit bcc6077

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
15+
jobs:
16+
build_and_test:
17+
name: Build and Test (${{ matrix.os }})
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
os: [ubuntu-latest, macos-latest, windows-latest]
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Install Rust toolchain (stable)
28+
uses: actions-rust-lang/setup-rust-toolchain@v1
29+
with:
30+
toolchain: stable
31+
cache: 'cargo'
32+
components: clippy, rustfmt
33+
34+
- name: Check Formatting (cargo fmt)
35+
run: cargo fmt --all -- --check
36+
37+
- name: Linting (cargo clippy)
38+
run: cargo clippy --all-targets -- -D warnings
39+
40+
- name: Run Tests (cargo test)
41+
run: cargo test --all-targets --verbose
42+
43+
- name: Build (Debug)
44+
run: cargo build --verbose
45+
46+
- name: Build (Release)
47+
run: cargo build --release --verbose

.github/workflows/release.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # Trigger on tags like v0.1.0, v1.2.3
7+
8+
permissions:
9+
contents: write # Needed to create releases and upload assets
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
BINARY_NAME: strux
14+
STAGING_DIR: staging
15+
16+
jobs:
17+
build-release:
18+
name: Build Release Binaries (${{ matrix.target }})
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
matrix:
22+
include:
23+
# Linux (GNU) - tar.gz archive
24+
- os: ubuntu-latest
25+
target: x86_64-unknown-linux-gnu
26+
bin_suffix: ""
27+
archive_format: tar.gz
28+
archive_command: |
29+
tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} .
30+
archive_shell: bash
31+
32+
# macOS (Intel x86_64) - tar.gz archive
33+
- os: macos-latest
34+
target: x86_64-apple-darwin
35+
bin_suffix: ""
36+
archive_format: tar.gz
37+
archive_command: |
38+
tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} .
39+
archive_shell: bash
40+
41+
# macOS (Apple Silicon arm64) - tar.gz archive
42+
- os: macos-14
43+
target: aarch64-apple-darwin
44+
bin_suffix: ""
45+
archive_format: tar.gz
46+
archive_command: |
47+
tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} .
48+
archive_shell: bash
49+
50+
# Windows (MSVC x86_64) - zip archive
51+
- os: windows-latest
52+
target: x86_64-pc-windows-msvc
53+
bin_suffix: ".exe"
54+
archive_format: zip
55+
archive_command: |
56+
Compress-Archive -Path ${{ env.STAGING_DIR }}\* -DestinationPath ${{ env.ARCHIVE_NAME }}
57+
archive_shell: pwsh
58+
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v4
62+
63+
- name: Install Rust toolchain (stable)
64+
uses: actions-rust-lang/setup-rust-toolchain@v1
65+
with:
66+
toolchain: stable
67+
target: ${{ matrix.target }}
68+
cache: 'cargo'
69+
70+
- name: Build release binary
71+
run: cargo build --release --target ${{ matrix.target }} --verbose
72+
73+
- name: Prepare archive name
74+
run: echo "ARCHIVE_NAME=${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive_format }}" >> $GITHUB_ENV
75+
shell: bash
76+
77+
- name: Create staging directory
78+
run: mkdir ${{ env.STAGING_DIR }}
79+
shell: bash
80+
81+
- name: Copy binary to staging directory
82+
run: |
83+
set -e
84+
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.bin_suffix }} ${{ env.STAGING_DIR }}/
85+
shell: bash
86+
87+
- name: Copy documentation and license files to staging directory
88+
# Copy only LICENSE and README.md, not COMMIT.md
89+
run: |
90+
set -e
91+
cp LICENSE ${{ env.STAGING_DIR }}/
92+
cp README.md ${{ env.STAGING_DIR }}/
93+
shell: bash
94+
95+
- name: List staging directory contents (for debugging)
96+
run: ls -R ${{ env.STAGING_DIR }}
97+
shell: bash
98+
99+
- name: Package release artifacts from staging directory
100+
run: ${{ matrix.archive_command }}
101+
shell: ${{ matrix.archive_shell }}
102+
103+
- name: Upload release asset
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: release-assets
107+
path: ${{ env.ARCHIVE_NAME }}
108+
109+
create-release:
110+
name: Create GitHub Release
111+
needs: build-release
112+
runs-on: ubuntu-latest
113+
114+
steps:
115+
- name: Download all release assets
116+
uses: actions/download-artifact@v4
117+
with:
118+
name: release-assets
119+
path: release-assets
120+
121+
- name: List downloaded files (for debugging)
122+
run: ls -R release-assets
123+
124+
- name: Create Release and Upload Assets
125+
uses: softprops/action-gh-release@v2
126+
with:
127+
tag_name: ${{ github.ref_name }}
128+
name: Release ${{ github.ref_name }}
129+
generate_release_notes: true
130+
files: release-assets/*
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)