Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useless GH actions for cache in FreeBSD workflow #5797

Open
lcheylus opened this issue Jan 6, 2024 · 5 comments
Open

Useless GH actions for cache in FreeBSD workflow #5797

lcheylus opened this issue Jan 6, 2024 · 5 comments

Comments

@lcheylus
Copy link
Contributor

lcheylus commented Jan 6, 2024

In FreeBSD GH workflow (defined in .github/workflows/freebsd.yml), GH actions are used to cache the Rust build artefacts:

  • Swatinem/rust-cache@v2
  • mozilla-actions/sccache-action@v0.0.3

Theses actions are useless because the Rust build artefacts are not copied back from FreeBSD guest to Ubuntu GH runner after build:

  • FreeBSD workflow uses vmactions/freebsd-vm: runs a FreeBSD guest (VM) in a GH Ubuntu runner (host)
  • Files are synced between guest and host via rsync sync: rsync
  • At the end of job, the files are not copied back from FreeBSD guest to Ubuntu host: copyback: false.

Proposal to remove the 2 actions in FreeBSD workflow or to fix sync of files between guest/host after build to use cache.

@tertsdiepraam
Copy link
Member

Sounds good! Would you like to put up a PR for this?

@lcheylus
Copy link
Contributor Author

lcheylus commented Jan 8, 2024

I'm currently doing some tests (WIP to add CI for OpenBSD :), GH workflow similar to the FreeBSD one).

I will propose a fix/PR to support Rust cache in the FreeBSD workflow and some improvements inspired by the FreeBSD workflow from the rustup project.

@lcheylus
Copy link
Contributor Author

lcheylus commented Jan 17, 2024

Status of my work on FreeBSD workflow

After some analysis and (a lot of) tests, I have a working "rework" of the FreeBSD workflow using Swatinem/rust-cache and mozilla-actions/sccache-action :)

Reorg of FreeBSD workflow

The workflow have 2 jobs :

  • "Style and Lint" to check Rust code with cargo fmt and cargo clippy
  • "Tests" to build and test code with cargo nextest

The both jobs are executed with the vmactions/freebsd-vm action : FreeBSD stable (current version 14.0) VM runned in Ubuntu latest GH runner.

I have reorg the code of the workflow, inspired by the job build-freebsd from the CI workflow of the rustup project => https://github.com/rust-lang/rustup/blob/master/.github/workflows/ci.yaml#L1025

Both jobs started with prepare task to install necessary packages (with pkg FreeBSD command), create a temporary user tester (via shell) then run a script shell with sudo -E -u ${TEST_USER} to execute further tasks:

  • job "Style and Lint" => exec ci/freebsd_style_lint.sh script
  • job "Tests" => exec ci/freebsd_tests.sh script

With this separation between jobs defined in workflow (YAML format) and shell scripts, it's easier to modify them if needed.

I have also remove the definition of the jobs matrix (GH runner is always ubuntu-latest) and define feature = "unix" in workflow environment.

Action mozilla-actions/sccache-action

(The easiest part)

This action is only used in "Tests" job (not used for cargo fmt and cargo clippy in "Style and Lint" job).

  • define SCCACHE_GHA_ENABLED: "true" and RUSTC_WRAPPER: "sccache" in job env.
  • export FEATURES SCCACHE_GHA_ENABLED RUSTC_WRAPPER ACTIONS_CACHE_URL ACTIONS_RUNTIME_TOKEN variables for FreeBSD VM (variable envs for this action)
  • install sccache package for the FreeBSD VM
  • at the end of the ci/freebsd_tests.sh script, exec command sccache --show-stats > "${WORKSPACE}/sccache-stats.txt" 2>&1 to get the sccache stats in a text file => copyback to the Ubuntu host (see the section below for the copyback enabled option).
  • add a final step to display the sccache stats, reading the outputs in the copied file.

During the "Tests" job, sccache is correctly used by rustc and the cached files are read/written using ACTIONS_CACHE_URL/ACTIONS_RUNTIME_TOKEN parameters.

After some tests, I found that this action is not very useful : cache hits are low => only 3 / 193 compile requests.

I'm waiting your comments to decide if we must keep this action or suppress it.

Action for Rust cache Swatinem/rust-cache

Action used in the both jobs : "Style and Lint" and "Tests".

In the "Configure" step of this action, a cache key is created using Rust version (get via rust -vV command). To have a functional cache used in FreeBSD VM, this version must be the same as used on FreeBSD.

I created a shell script to fake the output of rustc -vV command => ci/fake_rustc_freebsd-stable.sh, returns rustc version rustc 1.75.0 (82e1608df 2023-12-21) for FreeBSD (host: x86_64-unknown-freebsd).

  • before the "Configure" step of rust-cache action, the rustc binary on Ubuntu runner is copied for backup
  • the shell script fake_rustc_freebsd-stable.sh is copied as ~/.cargo/bin/rustc
  • during "Configure" step, the cache key is created with the fake rustc version for FreeBSD (exec ~/.cargo/bin/rustc -vV)
  • I add a post-step to copy back the rustc binary on the Ubuntu runner (needed for the "Post Configure Rust cache" step at the end of the job).
  • the parameter prefix-key: "v0-rust-freebsd" is defined for the action to add a specific prefix when creating the cache key.

In the FreeBSD VM action, I enabled the copyback parameter to use the Rust cache:

  • after start of the FreeBSD VM, sources and files for the Rust cache are copied on it
  • tasks are run on the FreeBSD VM using Rust cache
  • in both CI shell scripts, remove execution of cargo clean to keep the created files by rustc/cargo
  • at the end of the step, files from the Rust cache are copied back from the FreeBSD guest to the Ubuntu host
  • the "Post Configure Rust cache" step uses these copied files to create the new version of the cache and upload it in GH cache.

After some runs, using Rust cache is efficient:

  • job "Style and Lint" running time: 4m51 with cold cache vs 4m10 with cache
  • job "Tests" running time: 8m01 with cold cache vs 7m12 with cache

You can check a complete run of this modified workflow on my own repository https://github.com/lcheylus/rust-coreutils/actions/runs/7552906886

You could also check my modified code on it (ugly main branch without rebase and also my ongoing work to add CI for OpenBSD).

I'm waiting your comments before splitting/rebasing my work in a separate branch and submitting a PR for merge.

@lcheylus
Copy link
Contributor Author

@sylvestre @tertsdiepraam Comments welcome.

@sylvestre
Copy link
Contributor

Sounds good, let's do it :)
The FreeBSD action is very reliable lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants