diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..388779d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + code-quality: + name: Code Quality + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt, clippy + + - uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - run: cargo fmt --all -- --check + + - run: cargo clippy --all-targets --all-features -- -D warnings + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - run: cargo test --locked --verbose + + - run: cargo test --doc --locked --verbose diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..268328a --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,33 @@ +name: Quick Build (Makefile) + +on: + workflow_dispatch: # Manual trigger only + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Quick Build & Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Prepare + run: make prepare + + - name: Run tests + run: make test + + - name: Build + run: make build + + - name: Display binary info + run: | + ls -lh target/release/slugify + file target/release/slugify diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ad20d28 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: Release + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +permissions: + contents: write + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + build: + name: Build - ${{ matrix.platform.os }} (${{ matrix.platform.target }}) + strategy: + fail-fast: false + matrix: + platform: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + asset: slugify-linux-x86_64 + - os: macos-latest + target: aarch64-apple-darwin + asset: slugify-macos-aarch64 + runs-on: ${{ matrix.platform.os }} + steps: + - uses: actions/checkout@v4 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: ${{ matrix.platform.target }} + + - uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-${{ matrix.platform.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Build + run: cargo build --release --locked --target ${{ matrix.platform.target }} + + - name: Prepare asset + run: | + strip target/${{ matrix.platform.target }}/release/slugify + cp target/${{ matrix.platform.target }}/release/slugify ${{ matrix.platform.asset }} + + - uses: softprops/action-gh-release@v2 + with: + files: ${{ matrix.platform.asset }} + generate_release_notes: true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17c7d7f --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +prepare: + cargo fetch --locked + +build: prepare + cargo build --release + +test: prepare + cargo test --release