Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 committed Feb 27, 2024
1 parent 1c2e10a commit cd59544
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Setup Rust'
description: 'Toolchain setup and Initial compilation'
inputs:
rye-version:
description: 'Rye version to use'
required: true
default: '0.16.0'
runs:
using: "composite"
steps:
- name: Rye Cache
id: rye-cache
uses: actions/cache@v4
with:
path: ~/.rye
key: "rye-${{ runner.os }}-${{ inputs.rye-version }}"

- name: Rye Install
shell: bash
run: curl -sSf https://rye-up.com/get | bash
if: steps.rye-cache.outputs.cache-hit != 'true'
env:
RYE_VERSION: "${{ inputs.rye-version }}"
RYE_INSTALL_OPTION: "--yes"

- name: Rye Shims
shell: bash
run: echo "~/.rye/shims" >> $GITHUB_PATH

- name: Venv Cache
id: venv-cache
uses: actions/cache@v4
with:
path: .venv
key: "venv-${{ runner.os }}-${{ hashFiles('requirements**.lock') }}"

- name: Rye Sync
shell: bash
# --no-lock prevents resolution of the lock file. The locks are still respected.
# We always run `rye sync` even if the cache fetch was successful since it builds our Rust extensions for us.
run: rye sync --no-lock
env:
MATURIN_PEP517_ARGS: "--profile dev"

- name: Export Path
shell: bash
run: echo "PATH=$PATH" >> $GITHUB_ENV
44 changes: 44 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Setup Rust'
description: 'Toolchain setup and Initial compilation'
inputs:
rust-toolchain: # id of input
description: 'Rust toolchain version to use'
required: true
default: stable
runs:
using: "composite"
steps:
- name: Rust Toolchain Cache
id: rustup-cache
uses: actions/cache@v4
with:
path: ~/.rustup
key: "rustup-${{ runner.os }}-${{ inputs.rust-toolchain }}"

- name: Rust Toolchain
uses: dtolnay/rust-toolchain@stable
if: steps.rustup-cache.outputs.cache-hit != 'true'
with:
toolchain: "${{ inputs.rust-toolchain }}"
components: clippy, rustfmt
- name: Rust Dependency Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: "shared" # To allow reuse across jobs

- name: Rust Compile Cache
uses: mozilla-actions/[email protected]
- name: Rust Compile Cache Config
shell: bash
run: |
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
- name: Rust Build
shell: bash
run: cargo build --all-targets

- name: Export Path
shell: bash
run: echo "PATH=$PATH" >> $GITHUB_ENV
23 changes: 23 additions & 0 deletions .github/actions/setup-zig/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Setup Zig'
description: 'Toolchain setup and Initial compilation'
runs:
using: "composite"
steps:
- name: Zig Version
id: zig-version
shell: bash
run: echo "version=$(cat .zig-version | tr -d '\n ')" >> $GITHUB_OUTPUT

- name: Zig Setup
uses: goto-bus-stop/setup-zig@v2
with:
version: "${{ steps.zig-version.outputs.version }}"

# TODO(ngates): should we cache zig-cache? Or zig-out?
- name: Zig Build
shell: bash
run: zig build

- name: Export Path
shell: bash
run: echo "PATH=$PATH" >> $GITHUB_ENV
42 changes: 42 additions & 0 deletions .github/workflows/bench-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PR Benchmarks

on:
pull_request:
types: [ labeled, synchronize ]
branches: [ "develop" ]
workflow_dispatch: { }

permissions:
actions: write
contents: read
pull-requests: write

jobs:
bench:
runs-on: ubuntu-latest-large
if: ${{ contains(github.event.head_commit.message, '[benchmark]') || github.event.label.name == 'benchmark' && github.event_name == 'pull_request' }}
steps:
# We remove the benchmark label first so that the workflow can be re-triggered.
- uses: actions-ecosystem/action-remove-labels@v1
with:
labels: benchmark

- uses: actions/checkout@v4

- uses: ./.github/actions/setup-zig
- uses: ./.github/actions/setup-rust

- name: Bench - Vortex
run: cargo bench | tee bench.txt

- name: Store benchmark result
uses: benchmark-action/[email protected]
with:
name: Vortex Benchmarks
tool: cargo
github-token: ${{ secrets.GITHUB_TOKEN }}
output-file-path: bench.txt
summary-always: true
auto-push: true
fail-on-alert: false

35 changes: 35 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Benchmarks

on:
push:
branches: [ "develop" ]
workflow_dispatch: { }

permissions:
actions: read
contents: write
deployments: write

jobs:
bench:
runs-on: ubuntu-latest-large
if: ${{ github.event_name == 'workflow_dispatch' || (contains(github.event.head_commit.message, '[benchmark]') && github.ref_name == 'develop') }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-zig
- uses: ./.github/actions/setup-rust

- name: Bench - Vortex
run: cargo bench | tee bench.txt

- name: Store benchmark result
uses: benchmark-action/[email protected]
with:
name: Vortex Benchmarks
tool: cargo
github-token: ${{ secrets.GITHUB_TOKEN }}
output-file-path: bench.txt
summary-always: true
auto-push: true
fail-on-alert: false
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
workflow_dispatch: { }

permissions:
actions: read
contents: read

jobs:
build:
name: 'build'
runs-on: ubuntu-latest-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-zig
- uses: ./.github/actions/setup-rust
- uses: ./.github/actions/setup-python

- name: Python Lint - Format
run: rye run ruff format --check .
- name: Python Lint - Ruff
run: rye run ruff .

- name: Rust Lint - Format
run: cargo fmt --all --check
- name: Rust Lint - Clippy
run: cargo clippy --all-targets

- name: Zig Lint - Fmt
run: zig fmt --check zig/

- name: Rust Test
run: cargo test --all

- name: Zig Test
run: zig build test

- name: Pytest - PyEnc
run: rye run pytest --benchmark-disable test/
working-directory: pyenc/

0 comments on commit cd59544

Please sign in to comment.