From 3df792a630810f3f241ae03dbf54a89b0db099ca Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sat, 12 Oct 2024 14:03:02 -0600 Subject: [PATCH] add github actions CI --- .github/actions/check-dirty-git/action.yml | 17 ++++++ .github/workflows/ci-rust.yml | 65 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/actions/check-dirty-git/action.yml create mode 100644 .github/workflows/ci-rust.yml diff --git a/.github/actions/check-dirty-git/action.yml b/.github/actions/check-dirty-git/action.yml new file mode 100644 index 0000000..3959a79 --- /dev/null +++ b/.github/actions/check-dirty-git/action.yml @@ -0,0 +1,17 @@ +name: Check dirty git +description: Check the git status of the current directory, and raise an error if there are uncommitted changes. + +runs: + using: composite + steps: + - name: Checking dirty git + shell: bash + run: | + # Workaround for https://github.com/actions/checkout/issues/766 + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + if [[ -n $(git status --porcelain) ]]; then + echo "repo is dirty" + git status + exit 1 + fi diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml new file mode 100644 index 0000000..f031473 --- /dev/null +++ b/.github/workflows/ci-rust.yml @@ -0,0 +1,65 @@ +name: Continuous Integration (rust) + +on: + push: + branches: [ "develop" ] + # See docu here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches + # it seems pretty similar to .gitignore + paths: + - '**' + - '!**.md' + pull_request: + paths: + - '**' + - '!**.md' + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: full + +jobs: + # builds and tests rust code, with --deny warnings. tests for dirty git + build-and-test-rust: + runs-on: ubuntu-latest + + env: + RUSTFLAGS: --deny warnings + + steps: + - uses: actions/checkout@v4 + - name: Rustup update + run: rustup toolchain add nightly && rustup update + - name: Show cargo version + run: cargo --version + - name: rust build caching + uses: Swatinem/rust-cache@v2 + with: + workspaces: . -> target + save-if: ${{ github.ref == 'refs/heads/develop' }} + - name: Build Rust + run: cargo check --verbose --locked + - name: Test Rust + run: cargo test --all --verbose --locked + - name: Check dirty git + uses: ./.github/actions/check-dirty-git + + # lints and checks formatting of rust code + lint-rust: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Rustup update + run: rustup update + - name: Show cargo version + run: cargo --version + - name: rust build caching + uses: Swatinem/rust-cache@v2 + with: + key: lint + workspaces: . -> target + save-if: ${{ github.ref == 'refs/heads/develop' }} + - name: Format + run: cargo +nightly fmt -- --check + - name: Clippy + run: cargo clippy --all --all-features -- -D warnings