diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-03 14:37:12 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-03 14:37:12 +0100 |
commit | 242fa3c15b43fca473528c93714beb30ef6e1331 (patch) | |
tree | 4eba887b31b469c838d95fbff60ae3433cc188bb | |
parent | eb741e895f1a73420a401f2495c711afe37d9d19 (diff) | |
parent | 3ce59b93e63d61daca92152cf3b842b628676426 (diff) |
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 <[email protected]>
-rw-r--r-- | .github/workflows/ci.yaml | 35 | ||||
-rw-r--r-- | xtask/src/flags.rs | 5 | ||||
-rw-r--r-- | xtask/src/main.rs | 2 | ||||
-rw-r--r-- | xtask/src/pre_cache.rs | 79 |
4 files changed, 4 insertions, 117 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0f68b234c..63518e67f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml | |||
@@ -42,14 +42,6 @@ jobs: | |||
42 | if: matrix.os == 'windows-latest' | 42 | if: matrix.os == 'windows-latest' |
43 | 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 | 43 | 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 |
44 | 44 | ||
45 | # Work around https://github.com/actions/cache/issues/403 by using GNU tar | ||
46 | # instead of BSD tar. | ||
47 | - name: Install GNU tar | ||
48 | if: matrix.os == 'macos-latest' | ||
49 | run: | | ||
50 | brew install gnu-tar | ||
51 | echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV | ||
52 | |||
53 | - name: Install Rust toolchain | 45 | - name: Install Rust toolchain |
54 | uses: actions-rs/toolchain@v1 | 46 | uses: actions-rs/toolchain@v1 |
55 | with: | 47 | with: |
@@ -58,19 +50,8 @@ jobs: | |||
58 | override: true | 50 | override: true |
59 | components: rustfmt, rust-src | 51 | components: rustfmt, rust-src |
60 | 52 | ||
61 | - name: Cache cargo directories | 53 | - name: Cache Dependencies |
62 | uses: actions/cache@v2 | 54 | uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72 |
63 | with: | ||
64 | path: | | ||
65 | ~/.cargo/registry | ||
66 | ~/.cargo/git | ||
67 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
68 | |||
69 | - name: Cache cargo target dir | ||
70 | uses: actions/cache@v2 | ||
71 | with: | ||
72 | path: target | ||
73 | key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} | ||
74 | 55 | ||
75 | - name: Compile | 56 | - name: Compile |
76 | run: cargo test --no-run --locked | 57 | run: cargo test --no-run --locked |
@@ -78,9 +59,6 @@ jobs: | |||
78 | - name: Test | 59 | - name: Test |
79 | run: cargo test -- --nocapture | 60 | run: cargo test -- --nocapture |
80 | 61 | ||
81 | - name: Prepare cache | ||
82 | run: cargo xtask pre-cache | ||
83 | |||
84 | # Weird targets to catch non-portable code | 62 | # Weird targets to catch non-portable code |
85 | rust-cross: | 63 | rust-cross: |
86 | name: Rust Cross | 64 | name: Rust Cross |
@@ -103,13 +81,8 @@ jobs: | |||
103 | - name: Install Rust targets | 81 | - name: Install Rust targets |
104 | run: rustup target add ${{ env.targets }} | 82 | run: rustup target add ${{ env.targets }} |
105 | 83 | ||
106 | - name: Cache cargo directories | 84 | - name: Cache Dependencies |
107 | uses: actions/cache@v2 | 85 | uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72 |
108 | with: | ||
109 | path: | | ||
110 | ~/.cargo/registry | ||
111 | ~/.cargo/git | ||
112 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
113 | 86 | ||
114 | - name: Check | 87 | - name: Check |
115 | run: | | 88 | run: | |
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index f80a5dd16..69b3cb9c1 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs | |||
@@ -28,7 +28,6 @@ xflags::xflags! { | |||
28 | } | 28 | } |
29 | 29 | ||
30 | cmd fuzz-tests {} | 30 | cmd fuzz-tests {} |
31 | cmd pre-cache {} | ||
32 | 31 | ||
33 | cmd release { | 32 | cmd release { |
34 | optional --dry-run | 33 | optional --dry-run |
@@ -62,7 +61,6 @@ pub enum XtaskCmd { | |||
62 | Help(Help), | 61 | Help(Help), |
63 | Install(Install), | 62 | Install(Install), |
64 | FuzzTests(FuzzTests), | 63 | FuzzTests(FuzzTests), |
65 | PreCache(PreCache), | ||
66 | Release(Release), | 64 | Release(Release), |
67 | Promote(Promote), | 65 | Promote(Promote), |
68 | Dist(Dist), | 66 | Dist(Dist), |
@@ -88,9 +86,6 @@ pub struct Install { | |||
88 | pub struct FuzzTests; | 86 | pub struct FuzzTests; |
89 | 87 | ||
90 | #[derive(Debug)] | 88 | #[derive(Debug)] |
91 | pub struct PreCache; | ||
92 | |||
93 | #[derive(Debug)] | ||
94 | pub struct Release { | 89 | pub struct Release { |
95 | pub dry_run: bool, | 90 | pub dry_run: bool, |
96 | } | 91 | } |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index ce3353410..d0bef7b7a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -18,7 +18,6 @@ mod install; | |||
18 | mod release; | 18 | mod release; |
19 | mod dist; | 19 | mod dist; |
20 | mod metrics; | 20 | mod metrics; |
21 | mod pre_cache; | ||
22 | 21 | ||
23 | use anyhow::{bail, Result}; | 22 | use anyhow::{bail, Result}; |
24 | use std::{ | 23 | use std::{ |
@@ -39,7 +38,6 @@ fn main() -> Result<()> { | |||
39 | } | 38 | } |
40 | flags::XtaskCmd::Install(cmd) => cmd.run(), | 39 | flags::XtaskCmd::Install(cmd) => cmd.run(), |
41 | flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), | 40 | flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), |
42 | flags::XtaskCmd::PreCache(cmd) => cmd.run(), | ||
43 | flags::XtaskCmd::Release(cmd) => cmd.run(), | 41 | flags::XtaskCmd::Release(cmd) => cmd.run(), |
44 | flags::XtaskCmd::Promote(cmd) => cmd.run(), | 42 | flags::XtaskCmd::Promote(cmd) => cmd.run(), |
45 | flags::XtaskCmd::Dist(cmd) => cmd.run(), | 43 | flags::XtaskCmd::Dist(cmd) => cmd.run(), |
diff --git a/xtask/src/pre_cache.rs b/xtask/src/pre_cache.rs deleted file mode 100644 index b456224fd..000000000 --- a/xtask/src/pre_cache.rs +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | use std::{ | ||
2 | fs::FileType, | ||
3 | path::{Path, PathBuf}, | ||
4 | }; | ||
5 | |||
6 | use anyhow::Result; | ||
7 | use xshell::rm_rf; | ||
8 | |||
9 | use crate::flags; | ||
10 | |||
11 | impl flags::PreCache { | ||
12 | /// Cleans the `./target` dir after the build such that only | ||
13 | /// dependencies are cached on CI. | ||
14 | pub(crate) fn run(self) -> Result<()> { | ||
15 | let slow_tests_cookie = Path::new("./target/.slow_tests_cookie"); | ||
16 | if !slow_tests_cookie.exists() { | ||
17 | panic!("slow tests were skipped on CI!") | ||
18 | } | ||
19 | rm_rf(slow_tests_cookie)?; | ||
20 | |||
21 | for path in read_dir("./target/debug", FileType::is_file)? { | ||
22 | // Can't delete yourself on windows :-( | ||
23 | if !path.ends_with("xtask.exe") { | ||
24 | rm_rf(&path)? | ||
25 | } | ||
26 | } | ||
27 | |||
28 | rm_rf("./target/.rustc_info.json")?; | ||
29 | |||
30 | let to_delete = read_dir("./crates", FileType::is_dir)? | ||
31 | .into_iter() | ||
32 | .map(|path| path.file_name().unwrap().to_string_lossy().replace('-', "_")) | ||
33 | .collect::<Vec<_>>(); | ||
34 | |||
35 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { | ||
36 | for path in read_dir(dir, |_file_type| true)? { | ||
37 | if path.ends_with("xtask.exe") { | ||
38 | continue; | ||
39 | } | ||
40 | let file_name = path.file_name().unwrap().to_string_lossy(); | ||
41 | let (stem, _) = match rsplit_once(&file_name, '-') { | ||
42 | Some(it) => it, | ||
43 | None => { | ||
44 | rm_rf(path)?; | ||
45 | continue; | ||
46 | } | ||
47 | }; | ||
48 | let stem = stem.replace('-', "_"); | ||
49 | if to_delete.contains(&stem) { | ||
50 | rm_rf(path)?; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | Ok(()) | ||
56 | } | ||
57 | } | ||
58 | fn read_dir(path: impl AsRef<Path>, cond: impl Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> { | ||
59 | read_dir_impl(path.as_ref(), &cond) | ||
60 | } | ||
61 | |||
62 | fn read_dir_impl(path: &Path, cond: &dyn Fn(&FileType) -> bool) -> Result<Vec<PathBuf>> { | ||
63 | let mut res = Vec::new(); | ||
64 | for entry in path.read_dir()? { | ||
65 | let entry = entry?; | ||
66 | let file_type = entry.file_type()?; | ||
67 | if cond(&file_type) { | ||
68 | res.push(entry.path()) | ||
69 | } | ||
70 | } | ||
71 | Ok(res) | ||
72 | } | ||
73 | |||
74 | fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> { | ||
75 | let mut split = haystack.rsplitn(2, delim); | ||
76 | let suffix = split.next()?; | ||
77 | let prefix = split.next()?; | ||
78 | Some((prefix, suffix)) | ||
79 | } | ||