uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.54k stars 1.26k forks source link

Useless GH actions for cache in FreeBSD workflow #5797

Open lcheylus opened 8 months ago

lcheylus commented 8 months ago

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

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

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

tertsdiepraam commented 8 months ago

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

lcheylus commented 8 months ago

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 commented 7 months ago

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 :

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:

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).

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).

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

After some runs, using Rust cache is efficient:


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 commented 7 months ago

@sylvestre @tertsdiepraam Comments welcome.