Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Athanasiou committed Dec 25, 2024
1 parent 2232ec4 commit 25e1757
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 34 deletions.
83 changes: 49 additions & 34 deletions .github/workflows/build.yml
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
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
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 }}

0 comments on commit 25e1757

Please sign in to comment.