-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konstantinos Athanasiou
committed
Dec 25, 2024
1 parent
2232ec4
commit 25e1757
Showing
2 changed files
with
81 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,63 @@ | ||
name: Build and Publish Rust Crate | ||
|
||
name: Build | ||
on: | ||
# Triggers the workflow on every push to the main branch | ||
workflow_call: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
# Also allow manual triggering of the workflow | ||
workflow_dispatch: | ||
|
||
env: | ||
RUST_TOOLCHAIN: stable | ||
|
||
jobs: | ||
build: | ||
name: Build the crate | ||
style: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
- name: Checkout the code | ||
uses: actions/checkout@v4 | ||
- name: Setup Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
|
||
- name: Build the project | ||
run: cargo build --release | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
components: rustfmt | ||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
- name: Run cargo fmt | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --all -- --check | ||
- name: Run cargo clippy | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idioms | ||
|
||
publish: | ||
name: Publish to crates.io | ||
test: | ||
needs: [style] | ||
runs-on: ubuntu-latest | ||
needs: build | ||
if: github.ref == 'refs/heads/main' # Only publish if on the main branch | ||
|
||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
- name: Checkout the code | ||
uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
- name: Run cargo test | ||
run: cargo test --all-features | ||
|
||
build: | ||
needs: [test] | ||
runs-on: ubuntu-latest | ||
|
||
- name: Publish to crates.io | ||
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }} | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
- name: Build | ||
run: cargo build --release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Build and Publish Rust Crate | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
env: | ||
RUST_TOOLCHAIN: stable | ||
TOOLCHAIN_PROFILE: minimal | ||
|
||
jobs: | ||
build: | ||
name: Build the crate | ||
runs-on: ubuntu-latest | ||
uses: build.yml | ||
|
||
publish: | ||
name: Publish to crates.io | ||
runs-on: ubuntu-latest | ||
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
|
||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
- name: Publish to crates.io | ||
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }} |