Skip to content

Commit 36ed2ce

Browse files
authored
Add base for Rust CI (#1)
* add base for Rust CI * add temporary crate inside workspace
1 parent 2f9185d commit 36ed2ce

File tree

7 files changed

+356
-0
lines changed

7 files changed

+356
-0
lines changed

.github/DOCS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Github config and workflows
2+
3+
In this folder there is configuration for codecoverage, dependabot, and ci
4+
workflows that check the library more deeply than the default configurations.
5+
6+
This folder can be or was merged using a --allow-unrelated-histories merge
7+
strategy from <https://github.com/jonhoo/rust-ci-conf/> which provides a
8+
reasonably sensible base for writing your own ci on. By using this strategy
9+
the history of the CI repo is included in your repo, and future updates to
10+
the CI can be merged later.
11+
12+
To perform this merge run:
13+
14+
```shell
15+
git remote add ci https://github.com/jonhoo/rust-ci-conf.git
16+
git fetch ci
17+
git merge --allow-unrelated-histories ci/main
18+
```
19+
20+
An overview of the files in this project is available at:
21+
<https://www.youtube.com/watch?v=xUH-4y92jPg&t=491s>, which contains some
22+
rationale for decisions and runs through an example of solving minimal version
23+
and OpenSSL issues.

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Taken from https://github.com/jonhoo/rust-ci-conf/blob/main/.github/dependabot.yml
2+
3+
version: 2
4+
updates:
5+
- package-ecosystem: github-actions
6+
directory: /
7+
schedule:
8+
interval: daily
9+
- package-ecosystem: cargo
10+
directory: /
11+
schedule:
12+
interval: daily
13+
ignore:
14+
- dependency-name: "*"
15+
# patch and minor updates don't matter for libraries as consumers of this library build
16+
# with their own lockfile, rather than the version specified in this library's lockfile
17+
# remove this ignore rule if your package has binaries to ensure that the binaries are
18+
# built with the exact set of dependencies and those are up to date.
19+
update-types:
20+
- "version-update:semver-patch"
21+
- "version-update:semver-minor"

.github/workflows/check.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Taken from https://github.com/jonhoo/rust-ci-conf/blob/main/.github/workflows/check.yml
2+
3+
# This workflow runs whenever a PR is opened or updated, or a commit is pushed to main. It runs
4+
# several checks:
5+
# - fmt: checks that the code is formatted according to rustfmt
6+
# - clippy: checks that the code does not contain any clippy warnings
7+
# - doc: checks that the code can be documented without errors
8+
# - hack: check combinations of feature flags
9+
# - msrv: check that the msrv specified in the crate is correct
10+
permissions:
11+
contents: read
12+
# This configuration allows maintainers of this repo to create a branch and pull request based on
13+
# the new branch. Restricting the push trigger to the main branch ensures that the PR only gets
14+
# built once.
15+
on:
16+
push:
17+
branches: [main]
18+
pull_request:
19+
# If new code is pushed to a PR branch, then cancel in progress workflows for that PR. Ensures that
20+
# we don't waste CI time, and returns results quicker https://github.com/jonhoo/rust-ci-conf/pull/5
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
23+
cancel-in-progress: true
24+
name: check
25+
jobs:
26+
fmt:
27+
runs-on: ubuntu-latest
28+
name: stable / fmt
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
submodules: true
33+
- name: Install stable
34+
uses: dtolnay/rust-toolchain@stable
35+
with:
36+
components: rustfmt
37+
- name: cargo fmt --check
38+
run: cargo fmt --check
39+
clippy:
40+
runs-on: ubuntu-latest
41+
name: ${{ matrix.toolchain }} / clippy
42+
permissions:
43+
contents: read
44+
checks: write
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
# Get early warning of new lints which are regularly introduced in beta channels.
49+
toolchain: [stable, beta]
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
submodules: true
54+
- name: Install ${{ matrix.toolchain }}
55+
uses: dtolnay/rust-toolchain@master
56+
with:
57+
toolchain: ${{ matrix.toolchain }}
58+
components: clippy
59+
- name: cargo clippy
60+
uses: giraffate/clippy-action@v1
61+
with:
62+
reporter: 'github-pr-check'
63+
github_token: ${{ secrets.GITHUB_TOKEN }}
64+
# # Since this is not a proper library on crates.io we do not need this.
65+
# semver:
66+
# runs-on: ubuntu-latest
67+
# name: semver
68+
# steps:
69+
# - uses: actions/checkout@v4
70+
# with:
71+
# submodules: true
72+
# - name: Install stable
73+
# uses: dtolnay/rust-toolchain@stable
74+
# with:
75+
# components: rustfmt
76+
# - name: cargo-semver-checks
77+
# uses: obi1kenobi/cargo-semver-checks-action@v2
78+
doc:
79+
# run docs generation on nightly rather than stable. This enables features like
80+
# https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an
81+
# API be documented as only available in some specific platforms.
82+
runs-on: ubuntu-latest
83+
name: nightly / doc
84+
steps:
85+
- uses: actions/checkout@v4
86+
with:
87+
submodules: true
88+
- name: Install nightly
89+
uses: dtolnay/rust-toolchain@nightly
90+
- name: Install cargo-docs-rs
91+
uses: dtolnay/install@cargo-docs-rs
92+
- name: cargo docs-rs
93+
# TODO: Once we figure out the crates, rename this.
94+
run: cargo docs-rs -p optd-tmp
95+
hack:
96+
# cargo-hack checks combinations of feature flags to ensure that features are all additive
97+
# which is required for feature unification
98+
runs-on: ubuntu-latest
99+
name: ubuntu / stable / features
100+
steps:
101+
- uses: actions/checkout@v4
102+
with:
103+
submodules: true
104+
- name: Install stable
105+
uses: dtolnay/rust-toolchain@stable
106+
- name: cargo install cargo-hack
107+
uses: taiki-e/install-action@cargo-hack
108+
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
109+
# --feature-powerset runs for every combination of features
110+
- name: cargo hack
111+
run: cargo hack --feature-powerset check
112+
msrv:
113+
# check that we can build using the minimal rust version that is specified by this crate
114+
runs-on: ubuntu-latest
115+
# we use a matrix here just because env can't be used in job names
116+
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
117+
strategy:
118+
matrix:
119+
msrv: ["1.56.1"] # 2021 edition requires 1.56
120+
name: ubuntu / ${{ matrix.msrv }}
121+
steps:
122+
- uses: actions/checkout@v4
123+
with:
124+
submodules: true
125+
- name: Install ${{ matrix.msrv }}
126+
uses: dtolnay/rust-toolchain@master
127+
with:
128+
toolchain: ${{ matrix.msrv }}
129+
- name: cargo +${{ matrix.msrv }} check
130+
run: cargo check

.github/workflows/test.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Taken from https://github.com/jonhoo/rust-ci-conf/blob/main/.github/workflows/test.yml
2+
3+
# This is the main CI workflow that runs the test suite on all pushes to main and all pull requests.
4+
# It runs the following jobs:
5+
# - required: runs the test suite on ubuntu with stable and beta rust toolchains
6+
# - minimal: runs the test suite with the minimal versions of the dependencies that satisfy the
7+
# requirements of this crate, and its dependencies
8+
# - os-check: runs the test suite on mac and windows
9+
# - coverage: runs the test suite and collects coverage information
10+
# See check.yml for information about how the concurrency cancellation and workflow triggering works
11+
permissions:
12+
contents: read
13+
on:
14+
push:
15+
branches: [main]
16+
pull_request:
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
name: test
21+
jobs:
22+
required:
23+
runs-on: ubuntu-latest
24+
name: ubuntu / ${{ matrix.toolchain }}
25+
strategy:
26+
matrix:
27+
# run on stable and beta to ensure that tests won't break on the next version of the rust
28+
# toolchain
29+
toolchain: [stable, beta]
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
submodules: true
34+
- name: Install ${{ matrix.toolchain }}
35+
uses: dtolnay/rust-toolchain@master
36+
with:
37+
toolchain: ${{ matrix.toolchain }}
38+
- name: cargo generate-lockfile
39+
# enable this ci template to run regardless of whether the lockfile is checked in or not
40+
if: hashFiles('Cargo.lock') == ''
41+
run: cargo generate-lockfile
42+
# https://twitter.com/jonhoo/status/1571290371124260865
43+
- name: cargo test --locked
44+
run: cargo test --locked --all-features --all-targets
45+
# https://github.com/rust-lang/cargo/issues/6669
46+
- name: cargo test --doc
47+
run: cargo test --locked --all-features --doc
48+
minimal:
49+
# This action chooses the oldest version of the dependencies permitted by Cargo.toml to ensure
50+
# that this crate is compatible with the minimal version that this crate and its dependencies
51+
# require. This will pickup issues where this create relies on functionality that was introduced
52+
# later than the actual version specified (e.g., when we choose just a major version, but a
53+
# method was added after this version).
54+
#
55+
# This particular check can be difficult to get to succeed as often transitive dependencies may
56+
# be incorrectly specified (e.g., a dependency specifies 1.0 but really requires 1.1.5). There
57+
# is an alternative flag available -Zdirect-minimal-versions that uses the minimal versions for
58+
# direct dependencies of this crate, while selecting the maximal versions for the transitive
59+
# dependencies. Alternatively, you can add a line in your Cargo.toml to artificially increase
60+
# the minimal dependency, which you do with e.g.:
61+
# ```toml
62+
# # for minimal-versions
63+
# [target.'cfg(any())'.dependencies]
64+
# openssl = { version = "0.10.55", optional = true } # needed to allow foo to build with -Zminimal-versions
65+
# ```
66+
# The optional = true is necessary in case that dependency isn't otherwise transitively required
67+
# by your library, and the target bit is so that this dependency edge never actually affects
68+
# Cargo build order. See also
69+
# https://github.com/jonhoo/fantoccini/blob/fde336472b712bc7ebf5b4e772023a7ba71b2262/Cargo.toml#L47-L49.
70+
# This action is run on ubuntu with the stable toolchain, as it is not expected to fail
71+
runs-on: ubuntu-latest
72+
name: ubuntu / stable / minimal-versions
73+
steps:
74+
- uses: actions/checkout@v4
75+
with:
76+
submodules: true
77+
- name: Install stable
78+
uses: dtolnay/rust-toolchain@stable
79+
- name: Install nightly for -Zminimal-versions
80+
uses: dtolnay/rust-toolchain@nightly
81+
- name: rustup default stable
82+
run: rustup default stable
83+
- name: cargo update -Zminimal-versions
84+
run: cargo +nightly update -Zminimal-versions
85+
- name: cargo test
86+
run: cargo test --locked --all-features --all-targets
87+
os-check:
88+
# run cargo test on mac and windows
89+
runs-on: ${{ matrix.os }}
90+
name: ${{ matrix.os }} / stable
91+
strategy:
92+
fail-fast: false
93+
matrix:
94+
os: [macos-latest, windows-latest]
95+
steps:
96+
# if your project needs OpenSSL, uncomment this to fix Windows builds.
97+
# it's commented out by default as the install command takes 5-10m.
98+
# - run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
99+
# if: runner.os == 'Windows'
100+
# - run: vcpkg install openssl:x64-windows-static-md
101+
# if: runner.os == 'Windows'
102+
- uses: actions/checkout@v4
103+
with:
104+
submodules: true
105+
- name: Install stable
106+
uses: dtolnay/rust-toolchain@stable
107+
- name: cargo generate-lockfile
108+
if: hashFiles('Cargo.lock') == ''
109+
run: cargo generate-lockfile
110+
- name: cargo test
111+
run: cargo test --locked --all-features --all-targets
112+
# # TODO: Setup code coverage.
113+
# coverage:
114+
# # use llvm-cov to build and collect coverage and outputs in a format that
115+
# # is compatible with codecov.io
116+
# #
117+
# # note that codecov as of v4 requires that CODECOV_TOKEN from
118+
# #
119+
# # https://app.codecov.io/gh/<user or org>/<project>/settings
120+
# #
121+
# # is set in two places on your repo:
122+
# #
123+
# # - https://github.com/jonhoo/guardian/settings/secrets/actions
124+
# # - https://github.com/jonhoo/guardian/settings/secrets/dependabot
125+
# #
126+
# # (the former is needed for codecov uploads to work with Dependabot PRs)
127+
# #
128+
# # PRs coming from forks of your repo will not have access to the token, but
129+
# # for those, codecov allows uploading coverage reports without a token.
130+
# # it's all a little weird and inconvenient. see
131+
# #
132+
# # https://github.com/codecov/feedback/issues/112
133+
# #
134+
# # for lots of more discussion
135+
# runs-on: ubuntu-latest
136+
# name: ubuntu / stable / coverage
137+
# steps:
138+
# - uses: actions/checkout@v4
139+
# with:
140+
# submodules: true
141+
# - name: Install stable
142+
# uses: dtolnay/rust-toolchain@stable
143+
# with:
144+
# components: llvm-tools-preview
145+
# - name: cargo install cargo-llvm-cov
146+
# uses: taiki-e/install-action@cargo-llvm-cov
147+
# - name: cargo generate-lockfile
148+
# if: hashFiles('Cargo.lock') == ''
149+
# run: cargo generate-lockfile
150+
# - name: cargo llvm-cov
151+
# run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info
152+
# - name: Record Rust version
153+
# run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV"
154+
# - name: Upload to codecov.io
155+
# uses: codecov/codecov-action@v5
156+
# with:
157+
# fail_ci_if_error: true
158+
# token: ${{ secrets.CODECOV_TOKEN }}
159+
# env_vars: OS,RUST

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[workspace]
2+
members = ["optd-tmp"]
3+
resolver = "2"

optd-tmp/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "optd-tmp"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

optd-tmp/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

0 commit comments

Comments
 (0)