The idea of using this CI/CD is create common templates for rust users. It should be ready to work in 5min with good default values. It allow you:
- check and tests:
- on Windows, Linux, MacOs natively and with quemu for other targets
- with any rust version you want (nightly, stable, 1.31 etc)
- check formatting
- use lints (cargo clippy)
- deploys to github (documentation and binaries)
If you just started using azure pipelines you can copy paste into azure-pipelines.yml
. Check and test should be good default one
This is the default and should be sufficiently. How to create endpoint?
trigger:
branches:
include: ['*']
tags:
include: ['*']
resources:
repositories:
- repository: rust_pipelines
type: github
name: xoac/rust-azure-pipelines
ref: refs/tags/v0.1.0
endpoint: PipelinesTemplates # TODO YOU NEED TO CHANGE THIS!
stages:
- stage: check
displayName: "Quick checks"
jobs:
- template: ci/scenarios/check.yml@rust_pipelines
- stage: test
displayName: "Multi OS native tests"
jobs:
- template: ci/scenarios/test.yml@rust_pipelines
parameters:
min_rust_supported: 1.31 # Use first rust version you wanna support
You are done! Everything else is optional!
Check supported targets. Supported targets
the name parameter is because we can't change automatically the name mips-unknow-linux-musl
to mips_unknow_linux_musl
. Name has to be unique in embedded stage.
# This stage allow to easy test your crate using cross project.
# Supported targets: https://github.com/rust-embedded/cross#supported-targets
- stage: embedded
displayName: "Cross check and tests"
dependsOn:
- check
jobs:
- template: ci/scenarios/embeeded.yml@rust_pipelines
parameters:
checks:
- target: mips-unknown-linux-musl
name: cross_chcek_i686_unknown_freebsd
- target: aarch64-unknown-linux-gnu
name: cross_check_aarch64_unknown_linux_gnu
tests:
- target: i686-unknown-linux-gnu
name: cross_test_i686_unknown_linux_gnu
# This stage build binaries - you can deploy them in next stage
- stage: build
displayName: "Builds"
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
dependsOn:
- test
# Deploy binaries to github only if tags start with `v` for example `v0.1.5`
- stage: deploy
displayName: "Deploys"
dependsOn:
- build
jobs:
- template: ci/scenarios/github/release.yml@rust_pipelines
parameters:
job_condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
gitHubConnection: PipelinesTemplates # CHANGED THIS TO YOUR OWN VALUE
If you already have azure-piplines.yml
file add this to be able using templates:
resources:
repositories:
- repository: rust_pipelines
type: github
name: xoac/rust-azure-pipelines
# ref: refs/heads/master ## TODO you may want to change it to refs/tags/TAG_NAME.
ref: refs/tags/v0.1.0
endpoint: YOU_NEED_TO_SET_THIS
More about templates resources
And now you can use it like this:
jobs:
- template: ci/jobs/cargo-check.yml@rust_pipelines
Available items:
ci
├── jobs
│ ├── cargo-build.yml
│ ├── cargo-check.yml
│ ├── cargo-clippy.yml
│ ├── cargo-doc.yml
│ ├── cargo-test.yaml
│ ├── cross-build.yml
│ ├── cross-check.yml
│ ├── cross-test.yml
│ └── rustfmt.yml
├── scenarios
│ ├── builds.yml
│ ├── check.yml
│ ├── embeeded.yml
│ ├── github
│ │ ├── deploy-doc.yml
│ │ └── release.yml
│ └── test.yml
└── steps
├── artifacts.yml
├── install-cross-rust.yml
└── install-rust.yml
You can see ci/scenarios
to get know how to use jobs.
The ci
is split into:
- steps - common steps that are used in many jobs like install rust, publish artifacts etc.
- jobs - here are defined jobs like rustfmt, cargo-*, clippy etc.
- scenarios - groups jobs with good defaults parameters to allow easy check, test, build and deploy.
Most of pepole know how to use cargo
. If you know you know also how to use this CI templates!
For example you wann use this:
cargo build --release --examples --target-dir "myTargetDir"
So you just need:
jobs:
- template: ci/jobs/cargo-build.yml@rust_pipelines
parameters:
release: true
examples: true
target-dir: "myTargetDir"
How to check for more parameters? You can use just --help
flag in cargo or see parameters in cargo-build.yml
cargo build --help
- Create
azure-pipelines.yml
in your reposiotry - Specify service connection
- Specify endpoint in resources.
This is useful if u want to have a separate documentation for master branch.
- First you need to create a PAT (Personal Access Token) on Github. (recommended scopes for the token:
repo
,user
,admin:repo_hook
.) - Then create a branch
gh-pages
and us it as repo page. Here you find how to do it
- Go to your azure dev-ops pipeline project and click edit.
- Go inside variables:
- Add variable called
DocPublishToken
with value of your PAT(Personal Access Token). Don't forget to mark it as secret.
- Edit azure-pipelines.yml section with doc deploy (parameters.git) and you are done.
Example master doc generated for this example create. master doc for this hello word app