Skip to content

Commit

Permalink
Use templates for CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Feb 2, 2020
1 parent cc93906 commit 904a600
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 61 deletions.
130 changes: 69 additions & 61 deletions .ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: $(Build.sourceBranchName)-$(Date:yyyyMMdd)$(Rev:.r)

# Set global variables
variables:
# TODO: gh_repository: 'lukaspustina/usereport-rs'
crate_name: 'usereport-rs'
crate_bin_name: 'usereport'
rust_minimum_version: 1.36.0
Expand All @@ -24,62 +23,77 @@ schedules:
- master

stages:
- stage: Check_n_Test
displayName: "Check'n'Test"
- stage: Check_Build_Test
displayName: "Check, Build, and Test"
jobs:
- job: 'Clippy'
- job: Fmt
strategy:
matrix:
mac-stable:
imageName: ${{ variables.macos_image_name }}
rustup_toolchain: stable
linux-stable:
linux-nightly:
imageName: ${{ variables.linux_image_name }}
rustup_toolchain: stable
rustup_toolchain: nightly
pool:
vmImage: $(imageName)
steps:
- 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
- script: rustup component add clippy
displayName: Install clippy
- script: cargo clippy --all --all-targets --all-features -- -D warnings $(source ".clippy.args")
displayName: Run Clippy

- job: 'Rustfmt'
pool:
vmImage: $(linux_image_name)
container: 'rustlang/rust:nightly'
steps:
- script: rustup component add rustfmt
displayName: Install Rustfmt
- script: cargo fmt --all -- --check
displayName: Run fmt
- template: templates/install_rust.yml
parameters:
rustup_toolchain: $(rustup_toolchain)
- template: templates/version_information.yml
- script: cargo fmt -- --check
displayName: Run Fmt

- job: 'Audit'
- job: Audit
strategy:
matrix:
linux-stable:
imageName: ${{ variables.linux_image_name }}
rustup_toolchain: stable
pool:
vmImage: $(linux_image_name)
container: 'rust:latest'
vmImage: $(imageName)
steps:
- template: templates/install_rust.yml
parameters:
rustup_toolchain: $(rustup_toolchain)
- template: templates/install_dependencies.yml
- script: cargo install cargo-audit
displayName: Install Cargo Audit
- template: templates/version_information.yml
- script: cargo audit
displayName: Run Cargo Audit

- job: 'Test'
- job: Clippy
strategy:
matrix:
mac-minimum:
imageName: ${{ variables.macos_image_name }}
rustup_toolchain: $(rust_minimum_version)
mac-stable:
imageName: ${{ variables.macos_image_name }}
rustup_toolchain: stable
linux-minimum:
linux-stable:
imageName: ${{ variables.linux_image_name }}
rustup_toolchain: $(rust_minimum_version)
rustup_toolchain: stable
pool:
vmImage: $(imageName)
steps:
- template: templates/install_rust.yml
parameters:
rustup_toolchain: $(rustup_toolchain)
- template: templates/install_dependencies.yml
- template: templates/version_information.yml
- script: cargo clippy --all --all-features -- -D warnings $(source ".clippy.args")
displayName: Run Clippy

- job: 'Build_n_Test'
displayName: "Build and Test"
strategy:
matrix:
mac-minimum-${{ variables.rust_minimum_version }}:
imageName: ${{ variables.macos_image_name }}
rustup_toolchain: ${{ variables.rust_minimum_version }}
mac-stable:
imageName: ${{ variables.macos_image_name }}
rustup_toolchain: stable
linux-minimum-${{ variables.rust_minimum_version }}:
imageName: ${{ variables.linux_image_name }}
rustup_toolchain: ${{ variables.rust_minimum_version }}
linux-stable:
imageName: ${{ variables.linux_image_name }}
rustup_toolchain: stable
Expand All @@ -89,49 +103,43 @@ stages:
pool:
vmImage: $(imageName)
steps:
- 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
- script: cargo check --all --tests --examples --benches
displayName: Cargo check
- script: cargo build --all --tests --examples --benches
- template: templates/install_rust.yml
parameters:
rustup_toolchain: $(rustup_toolchain)
- template: templates/install_dependencies.yml
- template: templates/version_information.yml
- script: cargo build --all --all-features --tests --examples --benches
displayName: Cargo build
- script: cargo test --all
- script: cargo test --all --all-features --examples
displayName: Cargo test

- stage: Build_Release
dependsOn: Check_n_Test
dependsOn: Check_Build_Test
displayName: "Build Release"
jobs:
- job: 'Build_Static_Binary'
displayName: "Build Static Binary"
pool:
# Other pools are currently (2019-10-14) not supported
vmImage: $(linux_image_name)
vmImage: ${{ variables.linux_image_name }}
container:
image: lukaspustina/rust_musl:stable
# Required, because Azure is going to add a user which requires root privileges
options: --user 0:0
steps:
# The Docker Image already includes a rustup installation but for user 'rust'. Since Azure uses its own user (cf. above), we install it again.
# - template: templates/install_rust.yml
# - template: templates/version_information.yml
# - script: |
# cd $BUILD_SOURCESDIRECTORY && \
# cargo build --all-features --release && \
# ls -al target/release/${CRATE_BIN_NAME} && \
# echo "##vso[task.setvariable variable=release_binary]target/release/${CRATE_BIN_NAME}"
- template: templates/install_rust.yml
parameters:
rustup_toolchain: stable
- template: templates/version_information.yml
- script: |
cd $BUILD_SOURCESDIRECTORY && \
mkdir -p target/release && \
ls -al > target/release/${CRATE_BIN_NAME} && \
cargo build --all --all-features --release && \
ls -al target/release/${CRATE_BIN_NAME} && \
echo "##vso[task.setvariable variable=release_binary]target/release/${CRATE_BIN_NAME}"
displayName: MUSL Cargo Build
displayName: Build MUSL Static Binary
- publish: $(Build.SourcesDirectory)/$(release_binary)
artifact: Release_Binary
displayName: Storing Release Binary
displayName: Store Release Binary

- stage: Publish_Release
displayName: "Publish Release"
Expand All @@ -146,19 +154,19 @@ stages:
buildType: 'current'
artifactName: 'Release_Binary'
targetPath: '$(Build.ArtifactStagingDirectory)'
displayName: "Download Release Binary"
- script: |
ls -al $BUILD_ARTIFACTSTAGINGDIRECTORY && \
mv "$BUILD_ARTIFACTSTAGINGDIRECTORY/${CRATE_BIN_NAME}" "$BUILD_ARTIFACTSTAGINGDIRECTORY/${CRATE_BIN_NAME}-$AGENT_OSARCHITECTURE-musl-static" && \
ls -al $BUILD_ARTIFACTSTAGINGDIRECTORY
displayName: "Preparing assets for upload"
displayName: "Prepare Assets for Upload"
- task: GitHubRelease@0
env:
SYSTEM_DEBUG: true
displayName: "Creating GitHub Release"
displayName: "Create GitHub Release"
inputs:
gitHubConnection: 'lukaspustina-releaseupload'
repositoryName: '$(Build.Repository.Name)'
# TODO: repositoryName: '$(gh_repository)'
action: create
# target: '$(Build.SourceVersion)'
# tagSource: 'auto'
Expand Down
4 changes: 4 additions & 0 deletions .ci/templates/install_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
steps:
- script: |
echo "No dependencies required for this crate."
displayName: Install Dependencies
15 changes: 15 additions & 0 deletions .ci/templates/install_rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
rustup_toolchain: stable

steps:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${{ parameters.rustup_toolchain }}
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
displayName: Install rust ${{ parameters.rustup_toolchain }}
- script: rustup default ${{ parameters.rustup_toolchain }}
displayName: Setting rust default toolchain to ${{ parameters.rustup_toolchain }}
- script: rustup component add clippy
displayName: Install clippy
- script: rustup component add rustfmt
displayName: Install rustfmt

8 changes: 8 additions & 0 deletions .ci/templates/restore_cargo_and_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- download: current
artifact: Cargo
displayName: Restoring .cargo directory
- publish: current
artifact: Target
displayName: Restoring target directory

8 changes: 8 additions & 0 deletions .ci/templates/save_cargo_and_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- publish: /home/vsts/.cargo
artifact: Cargo
displayName: Storing .cargo directory
- publish: $(Build.SourcesDirectory)/target
artifact: Target
displayName: Storing target directory

12 changes: 12 additions & 0 deletions .ci/templates/version_information.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
steps:
- script: |
rustup --version
rustup toolchain list
rustc --version
cargo --version
cargo --list
cargo clippy --version && echo "Clippy installed"
cargo fmt --version && echo "Rustfmt installed"
clang --version && echo "Clang installed"
displayName: Gather Build Environment Information

0 comments on commit 904a600

Please sign in to comment.