Skip to content

Commit

Permalink
Rework CI and improve project toolchain (JelteF#212)
Browse files Browse the repository at this point in the history
- add Contribution Guide
- add template for GitHub PRs
- runs CI only once for PRs
- auto-cancel previous CI pipelines for the same PR/branch
- switch to `dtolnay/rust-toolchain` GitHub action
- remove redundant CI jobs
- check documentation integrity with `rustdoc` lints on CI
- create GitHub releases on CI
- remove `Cargo.lock` and enable @dependabot
- turn on `#![forbid(non_ascii_idents, unsafe_code)]` to simplify life of hypothetical auditors
- replace `#[cfg(feature = "nightly")]` with `#[cfg(nightly)]`
- tune up `.editorconfig` rules

Co-authored-by: Jelte Fennema <[email protected]>
  • Loading branch information
tyranron and JelteF authored Oct 20, 2022
1 parent 74c5729 commit 6754a9a
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 316 deletions.
9 changes: 8 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ trim_trailing_whitespace = true
indent_style = space
charset = utf-8

[*.rs,*.toml]
[*.rs]
indent_size = 4

[*.sh]
indent_size = 4

[*.toml]
indent_size = 4

[*.yml]
indent_size = 2
39 changes: 39 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Resolves <!-- paste issue reference -->
<!-- and/or -->
Part of <!-- paste issue/PR reference -->
<!-- and/or -->
Required for <!-- paste issues/PRs references -->
<!-- and/or -->
Requires <!-- paste issues/PRs references -->
<!-- and/or -->
Related to <!-- paste issues/PRs references -->

<!-- Remove the lines above if there are no related issues/PRs -->




## Synopsis

<!-- Give a brief overview of the problem -->




## Solution

<!-- Describe how exactly the problem is (or will be) resolved -->




## Checklist

- [ ] Documentation is updated (if required)
- [ ] Tests are added/updated (if required)
- [ ] [CHANGELOG entry][l:1] is added (if required)




[l:1]: /CHANGELOG.md
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: daily

- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
227 changes: 135 additions & 92 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,134 +1,177 @@
name: CI

on: [push, pull_request]
on:
push:
branches: ["master"]
tags: ["v*"]
pull_request:
branches: ["master"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
RUST_BACKTRACE: 1

jobs:
test:
name: Test Rust ${{ matrix.toolchain }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
toolchain: [stable, nightly, 1.56.0]
os: [ubuntu, macOS, windows]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
override: true

- name: Remove .lock file
run: rm Cargo.lock
##########################
# Linting and formatting #
##########################

- name: Test
uses: actions-rs/cargo@v1
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
command: test
args: --features testing-helpers
toolchain: stable
components: clippy

- run: cargo clippy --all-features -- -D warnings

test_features_separate:
name: Test features
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt

- name: Install tomljson
run: go get github.com/pelletier/go-toml/cmd/tomljson
- run: cargo +nightly fmt --all -- --check

- name: Test
run: |
export GOBIN=$HOME/go/bin
export PATH=$PATH:$GOBIN
ci/test_all_features.sh


doc_test:
name: Doc tests
runs-on: ubuntu-latest

###########
# Testing #
###########

msrv:
name: MSRV
strategy:
fail-fast: false
matrix:
msrv: ["1.56.0"]
os:
- ubuntu
- macOS
- windows
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.msrv }}
- run: rustup default ${{ matrix.msrv }}
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
override: true

- name: Run cargo-external-doc
uses: actions-rs/cargo@v1
- name: Install minimal dependencies versions
run: cargo +nightly update -Z minimal-versions

- run: cargo test --features testing-helpers

test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu
- macOS
- windows
toolchain:
- stable
- nightly
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
command: test
args: --doc --features testing-helpers
toolchain: ${{ matrix.toolchain }}
- run: rustup default ${{ matrix.toolchain }}

- run: cargo test --features testing-helpers

clippy:
name: Clippy
test-features:
name: test features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true
- run: rustup default nightly

- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features -- -D warnings
- name: Install tomljson
run: go get github.com/pelletier/go-toml/cmd/tomljson

- run: ci/test_all_features.sh
env:
GOBIN: "$HOME/go/bin"
PATH: "$PATH:$GOBIN"

rustfmt:



#################
# Documentation #
#################

rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
override: true

- name: rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- run: cargo +nightly doc
env:
RUSTDOCFLAGS: --cfg docsrs


msrv:
# TODO: Use MSRV once it understands new `Cargo.lock` format.
# name: MSRV
name: Minimal crates versions
strategy:
fail-fast: false
matrix:
# msrv: ["1.36.0"]
msrv: [stable]
os: [ubuntu, macOS, windows]
runs-on: ${{ matrix.os }}-latest


#############
# Releasing #
#############

release-github:
name: release on GitHub
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs:
- clippy
- msrv
- rustdoc
- rustfmt
- test
- test-features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.msrv }}
override: true
- uses: actions/checkout@v3

- name: Install minimal dependecies versions
run: cargo +nightly update -Z minimal-versions
- name: Parse release version
id: release
run: echo ::set-output
name=version::${GITHUB_REF#refs/tags/v}
- name: Verify release version matches `derive_more` Cargo manifest
run: |
test "${{ steps.release.outputs.version }}" \
== "$(grep -m1 'version = "' Cargo.toml | cut -d '"' -f2)"
- name: Parse CHANGELOG link
id: changelog
run: echo ::set-output
name=link::${{ github.server_url }}/${{ github.repository }}/blob/v${{ steps.release.outputs.version }}/CHANGELOG.md#$(sed -n '/^## ${{ steps.release.outputs.version }}/{s/^## \([^ ]*\) - \([0-9].*\)/\1---\2/;s/[^0-9a-z-]*//g;p;}' CHANGELOG.md)

- name: Test
uses: actions-rs/cargo@v1
- uses: softprops/action-gh-release@v1
with:
command: test
args: --features testing-helpers
name: ${{ steps.release.outputs.version }}
body: |
[API docs](https://docs.rs/derive_more/${{ steps.release.outputs.version }})
[Changelog](${{ steps.changelog.outputs.link }})
prerelease: ${{ contains(steps.release.outputs.version, '-') }}
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
*.exe

# Generated by Cargo
Cargo.lock
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
# Cargo.lock

gh-pages

# git files
Expand Down
Loading

0 comments on commit 6754a9a

Please sign in to comment.