Skip to content

Feature/pylace removable rows #378

Feature/pylace removable rows

Feature/pylace removable rows #378

name: 'Rust: Build and Test'
on:
push:
tags:
- rust-*
workflow_dispatch:
pull_request:
paths:
- 'lace/**'
- 'book/**'
- '.github/workflows/rust-build-test.yaml'
- '.github/scripts/run_code_in_mdfile.py'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: . -> lace/target
- name: Install dependencies
run: cargo install cargo-hack
- name: Run cargo check on all features
working-directory: lace
run: cargo hack check --each-feature --all-targets
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: lace
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: . -> lace/target
- name: Run rustfmt (Lace)
working-directory: lace
run: cargo fmt --all -- --check
- name: Run rustfmt (CLI)
working-directory: cli
run: cargo fmt --all -- --check
- name: Run clippy (Lace)
working-directory: lace
env:
RUSTFLAGS: -C debuginfo=0
run: |
cargo clippy --all-features
- name: Run clippy (CLI)
working-directory: cli
env:
RUSTFLAGS: -C debuginfo=0
run: |
cargo clippy --all-features
- name: Install audit
run: cargo install cargo-audit
- name: Run audit (Lace)
working-directory: lace
# Note: Both `polars` and `arrow2` trigger this security violation
# due to their reliance on `chrono`, which is the ultimate source of the violation
# as of 2/21/23, no version of `chrono` has been published that fixes the issue
# and thus neither `polars` or `arrow2` can pass `audit` checks
run: cargo audit -f Cargo.lock --ignore RUSTSEC-2020-0071
- name: Run audit (CLI)
working-directory: cli
# Note: Both `polars` and `arrow2` trigger this security violation
# due to their reliance on `chrono`, which is the ultimate source of the violation
# as of 2/21/23, no version of `chrono` has been published that fixes the issue
# and thus neither `polars` or `arrow2` can pass `audit` checks
run: cargo audit -f Cargo.lock --ignore RUSTSEC-2020-0071
test:
runs-on: ${{ matrix.os }}
needs: ["lint", "features"]
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
defaults:
run:
working-directory: lace
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: . -> lace/target
- name: Regen Examples
working-directory: cli
env:
RUSTFLAGS: -C debuginfo=0
run: cargo run -- regen-examples
- name: Run Lace tests
env:
RUSTFLAGS: -C debuginfo=0
run: cargo test --all-features
- name: Run CLI tests
working-directory: cli
env:
RUSTFLAGS: -C debuginfo=0
run: cargo test --all-features
# semver-checks:
# runs-on: ubuntu-latest
# needs: ["features", "lint", "test"]
# steps:
# - name: Checkout branch
# uses: actions/checkout@v4
# with:
# path: branch
# - name: Checkout master
# uses: actions/checkout@v4
# with:
# ref: master
# path: master
# - name: Set up Rust
# uses: dtolnay/rust-toolchain@stable
# - name: Cache Rust
# uses: Swatinem/rust-cache@v2
# with:
# workspaces: . -> lace/target
# - name: Install extra cargo tools
# run: cargo install cargo-semver-checks --locked
# - name: Check for semver-incompatibilities
# run: cargo semver-checks check-release --manifest-path branch/lace/Cargo.toml --baseline-root master/lace --verbose
compile-benchmarks:
runs-on: ubuntu-latest
needs: ["features", "lint", "test"]
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Compile benchmark tests (but do not run)
uses: actions-rs/cargo@v1
with:
command: bench
args: --manifest-path lace/Cargo.toml --no-run
test-mdbook-rust:
name: Test MDBook Rust Snippets
runs-on: ubuntu-latest
needs: ["features", "lint", "test"]
steps:
- uses: actions/checkout@v4
- name: Install codedown
run: npm install -g codedown
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: . -> lace/target
- name: Install rust-script
run: cargo install rust-script
- name: Test MDBook Code Samples (Rust)
env:
FORCE_COLOR: 1
run: |
pip install termcolor yq
NEW_VERSION=$(tomlq -r .package.version < lace/Cargo.toml)
python3 .github/scripts/run_code_in_mdfile.py directory rust book $NEW_VERSION --exclusion-file .github/resources/mdbook_exclusions.txt
release:
name: release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/rust-')
needs: ["compile-benchmarks", "features", "lint", "test", "test-mdbook-rust"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Branch
env:
NEW_VERSION: ${{github.ref_name}}
run: |
git fetch origin master
git tag --merged origin/master | grep $NEW_VERSION
- uses: dtolnay/rust-toolchain@stable
- name: Check Semver
working-directory: lace
env:
NEW_VERSION: ${{github.ref_name}}
run: |
pip install yq
DEPLOYING_VERSION=$(echo "$NEW_VERSION" | perl -lpe 's/^rust-//')
MAIN_VERSION=$(tomlq -r .package.version Cargo.toml)
test "$DEPLOYING_VERSION" = "$MAIN_VERSION"
- name: Install dependencies
run: cargo install cargo-crate
- name: Publish Updated Library Crates to Crates.io
working-directory: lace
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
PACKAGE_ORDER: "lace_utils lace_consts lace_data lace_stats lace_codebook lace_geweke lace_cc lace_metadata lace"
run: |
for PACKAGE_NAME in $PACKAGE_ORDER
do
echo "Processing package $PACKAGE_NAME"
if [ "$PACKAGE_NAME" == 'lace' ]
then
CARGO_FILE="Cargo.toml"
else
CARGO_FILE="$PACKAGE_NAME/Cargo.toml"
fi
PACKAGE_VERSION=$(tomlq .package.version $CARGO_FILE)
ALREADY_PUBLISHED=$(cargo crate info $PACKAGE_NAME --json --max-versions 100 | jq '[.krate.versions[].num] | any(. == '$PACKAGE_VERSION')')
if [ "$ALREADY_PUBLISHED" == 'false' ]
then
cargo publish --token "${CRATES_TOKEN}" -p $PACKAGE_NAME
fi
done
- name: Publish Updated CLI Crate to Crates.io
working-directory: cli
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: |
PACKAGE_VERSION=$(tomlq .package.version Cargo.toml)
ALREADY_PUBLISHED=$(cargo crate info lace-cli --json --max-versions 100 | jq '[.krate.versions[].num] | any(. == '$PACKAGE_VERSION')')
if [ "$ALREADY_PUBLISHED" == 'false' ]
then
cargo publish --token "${CRATES_TOKEN}" -p lace-cli
fi