ci: Reduce size of .cargo cache #4721
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
fmt: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Rust fmt | |
run: | | |
shopt -s globstar | |
rustfmt **/*.rs --check | |
contracts-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci | |
# "It should be sufficient to cache the following files and directories across builds:" | |
path: | | |
~/.cargo/.crates.toml | |
~/.cargo/.crates2.json | |
~/.cargo/bin | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target | |
key: ${{ runner.os }}-contracts-${{ hashFiles('creusot-contracts/Cargo.lock') }} | |
- name: Build creusot-contracts with nightly rustc | |
run: cargo build -p creusot-contracts -F nightly | |
contracts-build-stable: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci | |
# "It should be sufficient to cache the following files and directories across builds:" | |
path: | | |
~/.cargo/.crates.toml | |
~/.cargo/.crates2.json | |
~/.cargo/bin | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target | |
key: ${{ runner.os }}-contracts-stable-${{ hashFiles('creusot-contracts/Cargo.lock') }} | |
- name: Build creusot-contracts with stable rustc | |
run: cargo +stable build -p creusot-contracts | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci | |
# "It should be sufficient to cache the following files and directories across builds:" | |
path: | | |
~/.cargo/.crates.toml | |
~/.cargo/.crates2.json | |
~/.cargo/bin | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Build | |
run: cargo build | |
- name: dummy creusot setup | |
run: | | |
mkdir -p ~/.config/creusot | |
cp ci/creusot-config-dummy.toml ~/.config/creusot/Config.toml | |
- name: Run tests | |
run: cargo test | |
- run: du -d 2 -h ~/.cargo/registry | |
why3-deps: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
id: cache-opam | |
with: | |
path: | | |
/home/runner/work/creusot/creusot/_opam | |
key: ${{ runner.os }}-opam-${{ hashFiles('creusot-deps.opam') }} | |
- uses: ocaml/setup-ocaml@v3 | |
if: steps.cache-opam.outputs.cache-hit != 'true' | |
with: | |
ocaml-compiler: 5.3.0 | |
- name: install opam dependencies | |
if: steps.cache-opam.outputs.cache-hit != 'true' | |
run: | | |
sudo apt update | |
opam switch | |
opam --cli=2.1 var --global in-creusot-ci=true | |
opam install . | |
mkdir /tmp/to-delete | |
opam info --list-files why3 why3find > keep | |
sed -i 's/^.*\/_opam\///' keep | |
rsync -a -r --remove-source-files --exclude-from=keep _opam/ /tmp/to-delete | |
- name: archive why3 and why3find | |
run: tar -czf _opam.tar.gz _opam | |
# use tar because upload-artifact does not preserve file permissions | |
# https://github.com/actions/upload-artifact/tree/v4/?tab=readme-ov-file#permission-loss | |
- name: upload why3 and why3find | |
uses: actions/upload-artifact@v4 | |
with: | |
name: why3-deps | |
path: _opam.tar.gz | |
why3: | |
needs: why3-deps | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: ${{ github.event.pull_request.commits }} | |
- name: Fetch target branch | |
if: github.base_ref | |
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}} | |
- uses: actions/cache@v4 | |
with: | |
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci | |
# "It should be sufficient to cache the following files and directories across builds:" | |
path: | | |
~/.cargo/.crates.toml | |
~/.cargo/.crates2.json | |
~/.cargo/bin | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target | |
key: ${{ runner.os }}-cargo-creusot-${{ hashFiles('prelude/**', 'creusot-setup/build.rs', '**/Cargo.lock') }} | |
- uses: actions/cache@v4 | |
id: cache-creusot-setup | |
with: | |
path: | | |
~/.config/creusot | |
~/.local/share/creusot | |
_opam/lib/why3find/packages | |
key: ${{ runner.os }}-cargo-creusot-setup-${{ hashFiles('prelude/**', 'creusot-setup/build.rs', 'creusot-deps.opam', 'creusot-setup/src/tools_versions_urls.rs', 'creusot-setup/src/config.rs') }} | |
- name: download why3 and why3find | |
uses: actions/download-artifact@v4 | |
with: | |
name: why3-deps | |
- name: setup opam PATH | |
run: | | |
tar -xzf _opam.tar.gz | |
echo /home/runner/work/creusot/creusot/_opam/bin >> $GITHUB_PATH | |
- name: Install solvers | |
if: steps.cache-creusot-setup.outputs.cache-hit != 'true' | |
# Use only 2 parallel provers, because more provers (4) makes replaying proofs unstable | |
run: | | |
./INSTALL --skip-cargo-creusot --skip-creusot-rustc --provers-parallelism 2 | |
echo -e "\n>> ~/.config/creusot/Config.toml:\n" | |
cat ~/.config/creusot/Config.toml | |
echo -e "\n>> ~/.config/creusot/why3.conf:\n" | |
cat ~/.config/creusot/why3.conf | |
- run: cargo test --test why3 | |
install: | |
needs: why3-deps | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci | |
# "It should be sufficient to cache the following files and directories across builds:" | |
path: | | |
~/.cargo/.crates.toml | |
~/.cargo/.crates2.json | |
~/.cargo/bin | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target | |
key: ${{ runner.os }}-cargo-install-${{ hashFiles('**/Cargo.lock') }} | |
- name: download why3 and why3find | |
uses: actions/download-artifact@v4 | |
with: | |
name: why3-deps | |
- name: unpack why3 and why3find | |
run: tar -xzf _opam.tar.gz | |
- name: Setup | |
# Add /home/runner/work/creusot/creusot/_opam/bin to PATH just for this step | |
run: | | |
export PATH=/home/runner/work/creusot/creusot/_opam/bin:$PATH | |
./INSTALL | |
- name: test cargo creusot new | |
run: | | |
set -x | |
cd .. | |
cargo creusot new test-project --main --creusot-contracts ../creusot/creusot-contracts | |
cd test-project | |
cargo fmt --check | |
cargo build | |
cargo creusot | |
cargo creusot prove |