Skip to content

Commit

Permalink
Revert "Revert "Example nix-based CI workflow (#1195)" (#1255)"
Browse files Browse the repository at this point in the history
This reverts commit e25e04d.
  • Loading branch information
Jakub Zalewski committed Feb 20, 2024
1 parent 5017aae commit 5589551
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 28 deletions.
79 changes: 79 additions & 0 deletions .github/actions/ci-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Install CI deps

inputs:
cache-key:
required: false
local-cache:
required: false
GITHUB_TOKEN:
required: true
description: "GITHUB_TOKEN needed to make GitHub API requests"

runs:
using: "composite"

steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v8
with:
github-token: ${{ inputs.GITHUB_TOKEN }}
# Do not use systemd
init: none

- name: Set up Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v3

- name: Install CI deps
shell: bash
run: |
# Remove previously installed nix profiles
nix profile remove '.*'
# Install the current one
nix profile install .#ci-deps
# Set up CI environment
nix run .#ci-env >> $GITHUB_ENV
- id: get-info
name: Get info
shell: bash
run: |
RUST_VERSION="$(taplo get -f rust-toolchain.toml 'toolchain.channel')"
echo "cache-primary-key=toolchain-${{ runner.os }}-${{ runner.arch }}-${RUST_VERSION}" >> "$GITHUB_OUTPUT"
- id: toolchain-cache-restore
name: Restore Cargo Cache (Local Restore)
if: ${{ inputs.local-cache }}
uses: 0xmozak/local-cache/restore@ff33c7264117faa1bbd99aa0ddb467a9ccc3919e
with:
key: ${{ steps.get-info.outputs.cache-primary-key }}
path: |
~/.cargo/git
~/.cargo/registry
- id: toolchain-cache-save
name: Persist Cargo Cache (Local Save)
if: ${{ steps.toolchain-cache-restore.outputs.cache-hit != 'true' }}
uses: 0xmozak/local-cache/save@ff33c7264117faa1bbd99aa0ddb467a9ccc3919e
with:
key: ${{ steps.get-info.outputs.cache-primary-key }}
path: |
~/.cargo/git
~/.cargo/registry
- id: local-cache
name: Cache Rust artifacts (Local)
uses: 0xmozak/rust-cache@d5f76b3ac4ba287ab299d4d3586d5cd11ad21cab
with:
prefix-key: ${{ inputs.cache-key != '' && inputs.cache-key || null }}
cache-provider: "local"

- name: Debug
shell: bash
run: echo cache-hit=${{ steps.local-cache.outputs.cache-hit }} partial-hit=${{ steps.local-cache.outputs.partial-hit }}

- name: Cache Rust artifacts (Remote)
uses: 0xmozak/rust-cache@d5f76b3ac4ba287ab299d4d3586d5cd11ad21cab
if: ${{ steps.local-cache.outputs.cache-hit != 'true'}}
with:
require-full-match: ${{ steps.local-cache.outputs.partial-hit }}
prefix-key: ${{ inputs.cache-key != '' && inputs.cache-key || null }}
47 changes: 29 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
types:
- opened
Expand All @@ -28,16 +28,29 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install rust toolkit
uses: ./.github/actions/rust
- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Compile
run: nice cargo nextest run --no-run --locked --features="enable_poseidon_starks" --all-targets
- name: Compile and archive all the tests
run: nice cargo nextest archive --locked --features="enable_poseidon_starks" --all-targets --archive-file mozak-vm-tests.tar.zst

- name: Test
run: MOZAK_STARK_DEBUG=true nice cargo nextest run --no-fail-fast --locked --features="enable_poseidon_starks" --all-targets
- name: Run all the tests from the archive
run: MOZAK_STARK_DEBUG=true nice cargo nextest run --no-fail-fast --archive-file mozak-vm-tests.tar.zst

run-examples:
needs: check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
- uses: actions/checkout@v4

- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and run examples
run: |
Expand All @@ -50,8 +63,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install rust toolkit
uses: ./.github/actions/rust
- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}

Expand All @@ -68,28 +81,26 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install rust toolkit
uses: ./.github/actions/rust
- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}

- name: Build all examples
run: |
cd examples-builder
cargo build --all-features
cd examples-builder && cargo build --all-features
cargo-fmt:
needs: check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
- uses: actions/checkout@v4

- name: Install rust toolkit
uses: ./.github/actions/rust
- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}


- name: Run fmt
run: cargo fmt --all --check

Expand All @@ -110,8 +121,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install rust toolkit
uses: ./.github/actions/rust
- name: Install CI deps
uses: ./.github/actions/ci-deps
with:
local-cache: ${{ needs.check-runner.outputs.runner-label == 'self-hosted' }}

Expand Down
8 changes: 4 additions & 4 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
description = "A very basic flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"aarch64-darwin"
];

perSystem = {
config,
system,
pkgs,
...
}: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;

overlays = [
inputs.fenix.overlays.default
];

config = {};
};

formatter = pkgs.alejandra;

packages.rust-toolchain = pkgs.fenix.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-/Qcw88/iUz/WDWv19OZs4zL/EpdLHsD7loh65qSXvU8=";
};

packages.ci-deps = pkgs.symlinkJoin {
name = "ci-deps";

paths = with pkgs;
[
taplo
nodejs_20
wasmtime
cargo-nextest
config.packages.rust-toolchain
]
++ lib.lists.optional (stdenv.isDarwin) pkgs.darwin.libiconv;
};

# CI Setup for GitHub Actions
packages.ci-env = pkgs.writeScriptBin "ci-setup" ''
echo CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-args=-Wl,-rpath,${config.packages.ci-deps}/lib/"
echo CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C link-args=-Wl,-rpath,${config.packages.ci-deps}/lib/"
'';

devShells.default = pkgs.mkShell {
nativeBuildInputs = [
config.packages.ci-deps
];

CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS = ''-C link-args=-Wl,-rpath,${config.packages.ci-deps}/lib/'';
CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS = ''-C link-args=-Wl,-rpath,${config.packages.ci-deps}/lib/'';
};
};
};
}
Loading

0 comments on commit 5589551

Please sign in to comment.