master: Build Status

develop: Build Status

The idea

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)

Copy past examples:

If you just started using azure pipelines you can copy paste into azure-pipelines.yml. Check and test should be good default one

Check and test

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/[email protected]_pipelines

- stage: test
  displayName: "Multi OS native tests"
  jobs:
  - template: ci/scenarios/[email protected]_pipelines
    parameters:
      min_rust_supported: 1.31  # Use first rust version you wanna support

You are done! Everything else is optional!

More stages:

Check and tests for embedded

Just modify `checks` and `tests`. This step use [cross project](https://github.com/rust-embedded/cross)

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/[email protected]_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

Build and deploy to github

Parameter `gitHubConnection` need to be changed. [More info](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/github-release?view=azure-devops#prerequisites)
# 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/[email protected]_pipelines
    parameters:
      job_condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
      gitHubConnection: PipelinesTemplates # CHANGED THIS TO YOUR OWN VALUE

Add this repo templates to your project:

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/[email protected]_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.

Intuitive:

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.

Using template jobs:

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/[email protected]_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

How to use run azure-pipelines?

  1. Create azure-pipelines.yml in your reposiotry
  2. Specify service connection
  3. Specify endpoint in resources.

How to deploy doc to github pages?

This is useful if u want to have a separate documentation for master branch.

Github part

  1. First you need to create a PAT (Personal Access Token) on Github. (recommended scopes for the token: repo, user, admin:repo_hook.)
  2. Then create a branch gh-pages and us it as repo page. Here you find how to do it

Azure part

  1. Go to your azure dev-ops pipeline project and click edit.
  2. Go inside variables:
  3. Add variable called DocPublishToken with value of your PAT(Personal Access Token). Don't forget to mark it as secret.
  4. 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


Sources:

Rust Azure Pipelines

Collection of azure pipelines templates for rust

Rust Azure Pipelines Info

ā­ Stars 36
šŸ”— Source Code github.com
šŸ•’ Last Update 8 months ago
šŸ•’ Created 2 years ago
šŸž Open Issues 6
āž— Star-Issue Ratio 6
šŸ˜Ž Author xoac