mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-24 12:03:31 +00:00
Merge #8427
8427: Move CI to rust-cache Action r=matklad a=Swatinem This is humbling. I actually took inspiration from RAs pre-cache xtask when developing my action ;-) Closes #7731 Co-authored-by: Arpad Borsos <swatinem@swatinem.de>
This commit is contained in:
commit
242fa3c15b
4 changed files with 4 additions and 117 deletions
35
.github/workflows/ci.yaml
vendored
35
.github/workflows/ci.yaml
vendored
|
@ -42,14 +42,6 @@ jobs:
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old
|
run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old
|
||||||
|
|
||||||
# Work around https://github.com/actions/cache/issues/403 by using GNU tar
|
|
||||||
# instead of BSD tar.
|
|
||||||
- name: Install GNU tar
|
|
||||||
if: matrix.os == 'macos-latest'
|
|
||||||
run: |
|
|
||||||
brew install gnu-tar
|
|
||||||
echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
@ -58,19 +50,8 @@ jobs:
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, rust-src
|
components: rustfmt, rust-src
|
||||||
|
|
||||||
- name: Cache cargo directories
|
- name: Cache Dependencies
|
||||||
uses: actions/cache@v2
|
uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Cache cargo target dir
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: target
|
|
||||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
run: cargo test --no-run --locked
|
run: cargo test --no-run --locked
|
||||||
|
@ -78,9 +59,6 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: cargo test -- --nocapture
|
run: cargo test -- --nocapture
|
||||||
|
|
||||||
- name: Prepare cache
|
|
||||||
run: cargo xtask pre-cache
|
|
||||||
|
|
||||||
# Weird targets to catch non-portable code
|
# Weird targets to catch non-portable code
|
||||||
rust-cross:
|
rust-cross:
|
||||||
name: Rust Cross
|
name: Rust Cross
|
||||||
|
@ -103,13 +81,8 @@ jobs:
|
||||||
- name: Install Rust targets
|
- name: Install Rust targets
|
||||||
run: rustup target add ${{ env.targets }}
|
run: rustup target add ${{ env.targets }}
|
||||||
|
|
||||||
- name: Cache cargo directories
|
- name: Cache Dependencies
|
||||||
uses: actions/cache@v2
|
uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Check
|
- name: Check
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -28,7 +28,6 @@ xflags::xflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd fuzz-tests {}
|
cmd fuzz-tests {}
|
||||||
cmd pre-cache {}
|
|
||||||
|
|
||||||
cmd release {
|
cmd release {
|
||||||
optional --dry-run
|
optional --dry-run
|
||||||
|
@ -62,7 +61,6 @@ pub enum XtaskCmd {
|
||||||
Help(Help),
|
Help(Help),
|
||||||
Install(Install),
|
Install(Install),
|
||||||
FuzzTests(FuzzTests),
|
FuzzTests(FuzzTests),
|
||||||
PreCache(PreCache),
|
|
||||||
Release(Release),
|
Release(Release),
|
||||||
Promote(Promote),
|
Promote(Promote),
|
||||||
Dist(Dist),
|
Dist(Dist),
|
||||||
|
@ -87,9 +85,6 @@ pub struct Install {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FuzzTests;
|
pub struct FuzzTests;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PreCache;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Release {
|
pub struct Release {
|
||||||
pub dry_run: bool,
|
pub dry_run: bool,
|
||||||
|
|
|
@ -18,7 +18,6 @@ mod install;
|
||||||
mod release;
|
mod release;
|
||||||
mod dist;
|
mod dist;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
mod pre_cache;
|
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -39,7 +38,6 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
||||||
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
||||||
flags::XtaskCmd::PreCache(cmd) => cmd.run(),
|
|
||||||
flags::XtaskCmd::Release(cmd) => cmd.run(),
|
flags::XtaskCmd::Release(cmd) => cmd.run(),
|
||||||
flags::XtaskCmd::Promote(cmd) => cmd.run(),
|
flags::XtaskCmd::Promote(cmd) => cmd.run(),
|
||||||
flags::XtaskCmd::Dist(cmd) => cmd.run(),
|
flags::XtaskCmd::Dist(cmd) => cmd.run(),
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
use std::{
|
|
||||||
fs::FileType,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use xshell::rm_rf;
|
|
||||||
|
|
||||||
use crate::flags;
|
|
||||||
|
|
||||||
impl flags::PreCache {
|
|
||||||
/// Cleans the `./target` dir after the build such that only
|
|
||||||
/// dependencies are cached on CI.
|
|
||||||
pub(crate) fn run(self) -> Result<()> {
|
|
||||||
let slow_tests_cookie = Path::new("./target/.slow_tests_cookie");
|
|
||||||
if !slow_tests_cookie.exists() {
|
|
||||||
panic!("slow tests were skipped on CI!")
|
|
||||||
}
|
|
||||||
rm_rf(slow_tests_cookie)?;
|
|
||||||
|
|
||||||
for path in read_dir("./target/debug", FileType::is_file)? {
|
|
||||||
// Can't delete yourself on windows :-(
|
|
||||||
if !path.ends_with("xtask.exe") {
|
|
||||||
rm_rf(&path)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rm_rf("./target/.rustc_info.json")?;
|
|
||||||
|
|
||||||
let to_delete = read_dir("./crates", FileType::is_dir)?
|
|
||||||
.into_iter()
|
|
||||||
.map(|path| path.file_name().unwrap().to_string_lossy().replace('-', "_"))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
|
|
||||||
for path in read_dir(dir, |_file_type| true)? {
|
|
||||||
if path.ends_with("xtask.exe") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let file_name = path.file_name().unwrap().to_string_lossy();
|
|
||||||
let (stem, _) = match rsplit_once(&file_name, '-') {
|
|
||||||
Some(it) => it,
|
|
||||||
None => {
|
|
||||||
rm_rf(path)?;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let stem = stem.replace('-', "_");
|
|
||||||
if to_delete.contains(&stem) {
|
|
||||||
rm_rf(path)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn read_dir(path: impl AsRef<Path>, cond: impl Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> {
|
|
||||||
read_dir_impl(path.as_ref(), &cond)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_dir_impl(path: &Path, cond: &dyn Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> {
|
|
||||||
let mut res = Vec::new();
|
|
||||||
for entry in path.read_dir()? {
|
|
||||||
let entry = entry?;
|
|
||||||
let file_type = entry.file_type()?;
|
|
||||||
if cond(&file_type) {
|
|
||||||
res.push(entry.path())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> {
|
|
||||||
let mut split = haystack.rsplitn(2, delim);
|
|
||||||
let suffix = split.next()?;
|
|
||||||
let prefix = split.next()?;
|
|
||||||
Some((prefix, suffix))
|
|
||||||
}
|
|
Loading…
Reference in a new issue