1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2025-02-03 20:48:30 +00:00

ci: Fix CI to work with changes to Azure Pipelines build agent (#55)

This commit is contained in:
Matan Kushner 2019-05-16 09:40:30 -06:00 committed by GitHub
parent 90d6e6cf0b
commit 2cf69a82b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 125 additions and 93 deletions

View File

@ -1,12 +0,0 @@
steps:
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN%
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
displayName: Windows install rust
condition: eq( variables['Agent.OS'], 'Windows_NT' )
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
displayName: Install rust
condition: ne( variables['Agent.OS'], 'Windows_NT' )

View File

@ -1,73 +1,25 @@
jobs: jobs:
# Run the Rust linter # Check formatting
- job: "Clippy" - template: ci/azure-rustfmt.yml
pool: parameters:
vmImage: "ubuntu-16.04" name: rustfmt
container: "rust:latest"
steps:
- script: rustup component add clippy
displayName: Install Clippy
- script: cargo clippy --all
displayName: Run clippy
# Run the Rust formatter # Test with Rust stable
- job: "Rustfmt" - template: ci/azure-test-stable.yml
pool: parameters:
vmImage: "ubuntu-16.04" name: test_starship
container: "rust:latest" displayName: Test starship
condition: eq(variables['Build.Reason'], 'PullRequest')
steps: # Test with Rust nightly
- script: rustup component add rustfmt - template: ci/azure-test-nightly.yml
displayName: Install Rustfmt parameters:
- script: cargo fmt --all -- --check name: test_nightly
displayName: Run rustfmt displayName: Check starship with nightly
# Run the integration tests in a Docker container # Run the integration tests in a Docker container
- job: "Docker" - job: test_docker
displayName: Test starship Docker
pool: pool:
vmImage: "ubuntu-16.04" vmImage: ubuntu-16.04
steps: steps:
- script: ./integration_test - script: ./integration_test
displayName: Dockerized tests
# Run the integration tests on virtual machines
- job: "Test"
strategy:
matrix:
windows-stable:
imageName: "vs2017-win2016"
RUSTUP_TOOLCHAIN: stable
mac-stable:
imageName: "macos-10.13"
RUSTUP_TOOLCHAIN: stable
linux-stable:
imageName: "ubuntu-16.04"
RUSTUP_TOOLCHAIN: stable
linux-beta:
imageName: "ubuntu-16.04"
RUSTUP_TOOLCHAIN: beta
linux-nightly:
imageName: "ubuntu-16.04"
RUSTUP_TOOLCHAIN: nightly
pool:
vmImage: "ubuntu-16.04"
steps:
# Install Node.js
- task: NodeTool@0
inputs:
versionSpec: "12.0.0"
# Install Go
- task: GoTool@0
inputs:
versionSpec: "1.10"
# Install Python
- task: UsePythonVersion@0
inputs:
versionSpec: "3.7.2"
# Install Rust
- template: ".build/install-rust.yml"
- script: cargo build
displayName: Cargo build
- script: cargo test -- --ignored
displayName: Cargo test

25
ci/azure-install-rust.yml Normal file
View File

@ -0,0 +1,25 @@
steps:
# Linux and macOS
- script: |
set -e
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin:/usr/local/cargo/bin"
env:
RUSTUP_TOOLCHAIN: ${{parameters.rust_version}}
displayName: "Install rust (*nix)"
condition: not(eq(variables['Agent.OS'], 'Windows_NT'))
# Windows
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN%
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
env:
RUSTUP_TOOLCHAIN: ${{parameters.rust_version}}
displayName: "Install rust (windows)"
condition: eq(variables['Agent.OS'], 'Windows_NT')
# All platforms.
- script: |
rustc -Vv
cargo -V
displayName: Query rust and cargo versions

16
ci/azure-rustfmt.yml Normal file
View File

@ -0,0 +1,16 @@
jobs:
# Check formatting
- job: ${{ parameters.name }}
displayName: Check rustfmt
pool:
vmImage: ubuntu-16.04
steps:
- template: azure-install-rust.yml
parameters:
rust_version: stable
- script: |
rustup component add rustfmt
displayName: Install rustfmt
- script: |
cargo fmt --all -- --check
displayName: Check formatting

View File

@ -0,0 +1,16 @@
steps:
# Install Node.js
- task: NodeTool@0
inputs:
versionSpec: "12.0.0"
displayName: "Install a fixed version of Node"
# Install Go
- task: GoTool@0
inputs:
versionSpec: "1.10"
displayName: "Install a fixed version of Go"
# Install Python
- task: UsePythonVersion@0
inputs:
versionSpec: "3.6.8"
displayName: "Install a fixed version of Python"

13
ci/azure-test-nightly.yml Normal file
View File

@ -0,0 +1,13 @@
jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
pool:
vmImage: ubuntu-16.04
steps:
- template: azure-install-rust.yml
parameters:
rust_version: nightly
- script: cargo check --all
displayName: cargo +nightly check --all

23
ci/azure-test-stable.yml Normal file
View File

@ -0,0 +1,23 @@
jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
strategy:
matrix:
Linux:
vmImage: ubuntu-16.04
MacOS:
vmImage: macOS-10.13
Windows:
vmImage: vs2017-win2016
pool:
vmImage: $(vmImage)
steps:
- template: azure-install-rust.yml
parameters:
rust_version: stable
- template: azure-setup-test-env.yml
- script: cargo test -- --ignored
displayName: cargo test

View File

@ -21,6 +21,7 @@ pub fn segment(context: &Context) -> Option<Module> {
module.set_style(module_color); module.set_style(module_color);
let current_dir = &context.current_dir; let current_dir = &context.current_dir;
log::debug!("Current directory: {:?}", current_dir);
let dir_string; let dir_string;
if let Some(repo_root) = &context.repo_root { if let Some(repo_root) = &context.repo_root {
@ -58,7 +59,7 @@ fn contract_path(full_path: &Path, top_level_path: &Path, top_level_replacement:
format!( format!(
"{replacement}{separator}{path}", "{replacement}{separator}{path}",
replacement = top_level_replacement, replacement = top_level_replacement,
separator = std::path::MAIN_SEPARATOR, separator = "/",
path = full_path path = full_path
.strip_prefix(top_level_path) .strip_prefix(top_level_path)
.unwrap() .unwrap()
@ -76,15 +77,13 @@ fn truncate(dir_string: String, length: usize) -> String {
return dir_string; return dir_string;
} }
let components = dir_string let components = dir_string.split("/").collect::<Vec<&str>>();
.split(std::path::MAIN_SEPARATOR)
.collect::<Vec<&str>>();
if components.len() <= length { if components.len() <= length {
return dir_string; return dir_string;
} }
let truncated_components = &components[components.len() - length..]; let truncated_components = &components[components.len() - length..];
truncated_components.join(&std::path::MAIN_SEPARATOR.to_string()) truncated_components.join("/")
} }
#[cfg(test)] #[cfg(test)]

View File

@ -28,7 +28,7 @@ RUN goenv global $GO_VERSION
RUN go version RUN go version
# Install Python # Install Python
ENV PYTHON_VERSION 3.7.2 ENV PYTHON_VERSION 3.6.8
ENV PYENV_ROOT /root/.pyenv ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
RUN curl https://pyenv.run | bash \ RUN curl https://pyenv.run | bash \

View File

@ -67,9 +67,9 @@ fn root_directory() -> io::Result<()> {
#[test] #[test]
fn directory_in_root() -> io::Result<()> { fn directory_in_root() -> io::Result<()> {
let dir = Path::new("/opt"); let dir = Path::new("/tmp");
let expected = format!("via {} ", Color::Cyan.bold().paint("/opt").to_string()); let expected = format!("via {} ", Color::Cyan.bold().paint("/tmp").to_string());
let actual = common::render_module("dir", &dir); let actual = common::render_module("dir", &dir);
assert_eq!(expected, actual); assert_eq!(expected, actual);
@ -79,7 +79,7 @@ fn directory_in_root() -> io::Result<()> {
#[test] #[test]
#[ignore] #[ignore]
fn truncated_directory_in_root() -> io::Result<()> { fn truncated_directory_in_root() -> io::Result<()> {
let dir = Path::new("/opt/starship/thrusters/rocket"); let dir = Path::new("/tmp/starship/thrusters/rocket");
fs::create_dir_all(&dir)?; fs::create_dir_all(&dir)?;
let expected = format!( let expected = format!(
@ -98,7 +98,7 @@ fn truncated_directory_in_root() -> io::Result<()> {
#[test] #[test]
#[ignore] #[ignore]
fn git_repo_root() -> io::Result<()> { fn git_repo_root() -> io::Result<()> {
let tmp_dir = TempDir::new()?; let tmp_dir = TempDir::new_in(home_dir().unwrap())?;
let repo_dir = tmp_dir.path().join("rocket-controls"); let repo_dir = tmp_dir.path().join("rocket-controls");
fs::create_dir(&repo_dir)?; fs::create_dir(&repo_dir)?;
@ -117,7 +117,7 @@ fn git_repo_root() -> io::Result<()> {
#[test] #[test]
#[ignore] #[ignore]
fn directory_in_git_repo() -> io::Result<()> { fn directory_in_git_repo() -> io::Result<()> {
let tmp_dir = TempDir::new()?; let tmp_dir = TempDir::new_in(home_dir().unwrap())?;
let repo_dir = tmp_dir.path().join("rocket-controls"); let repo_dir = tmp_dir.path().join("rocket-controls");
let dir = repo_dir.join("src"); let dir = repo_dir.join("src");
fs::create_dir_all(&dir)?; fs::create_dir_all(&dir)?;

View File

@ -15,7 +15,7 @@ fn folder_with_python_version() -> io::Result<()> {
let expected = format!( let expected = format!(
"via {} ", "via {} ",
Segment::new("python") Segment::new("python")
.set_value("🐍 v3.7.2") .set_value("🐍 v3.6.8")
.set_style(Color::Yellow.bold()) .set_style(Color::Yellow.bold())
); );
let actual = common::render_module("python", &dir.path()); let actual = common::render_module("python", &dir.path());
@ -33,7 +33,7 @@ fn folder_with_requirements_txt() -> io::Result<()> {
let expected = format!( let expected = format!(
"via {} ", "via {} ",
Segment::new("python") Segment::new("python")
.set_value("🐍 v3.7.2") .set_value("🐍 v3.6.8")
.set_style(Color::Yellow.bold()) .set_style(Color::Yellow.bold())
); );
let actual = common::render_module("python", &dir.path()); let actual = common::render_module("python", &dir.path());
@ -51,7 +51,7 @@ fn folder_with_pyproject_toml() -> io::Result<()> {
let expected = format!( let expected = format!(
"via {} ", "via {} ",
Segment::new("python") Segment::new("python")
.set_value("🐍 v3.7.2") .set_value("🐍 v3.6.8")
.set_style(Color::Yellow.bold()) .set_style(Color::Yellow.bold())
); );
let actual = common::render_module("python", &dir.path()); let actual = common::render_module("python", &dir.path());
@ -69,7 +69,7 @@ fn folder_with_py_file() -> io::Result<()> {
let expected = format!( let expected = format!(
"via {} ", "via {} ",
Segment::new("python") Segment::new("python")
.set_value("🐍 v3.7.2") .set_value("🐍 v3.6.8")
.set_style(Color::Yellow.bold()) .set_style(Color::Yellow.bold())
); );
let actual = common::render_module("python", &dir.path()); let actual = common::render_module("python", &dir.path());