Skip to content

Commit 6bc8a8a

Browse files
author
Joonas Koivunen
authored
Merge pull request #734 from Mirko-von-Leipzig/gh_action_checks
ci: add commit checks for PRs
2 parents 9864ed8 + 32d730a commit 6bc8a8a

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
# 1. spin: is no longer actively maintained
5050
# 2. sized-chunks: no safe upgrade.
5151
# 3. net2: has been removed from crates, still present as a dep to tokio
52-
run: cargo audit --ignore RUSTSEC-2019-0031 --ignore RUSTSEC-2020-0041 --ignore RUSTSEC-2020-0016
52+
# 4. hyper: requires 18 exabytes of data transfer, can be removed with tokio 1.0 upgrade
53+
run: cargo audit --ignore RUSTSEC-2019-0031 --ignore RUSTSEC-2020-0041 --ignore RUSTSEC-2020-0016 --ignore RUSTSEC-2021-0078 --ignore RUSTSEC-2021-0079
5354

5455
- name: Test
5556
run: timeout 15m cargo test --all --all-features

.github/workflows/commits.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Checks all commits in a PR follow the repo rules:
2+
#
3+
# 1. conventional commit messages
4+
# 2. used `git commit --signoff`
5+
# 3. no extra merge commits
6+
name: Commits
7+
8+
on:
9+
workflow_dispatch:
10+
# Perform these checks on PRs into *any* branch.
11+
#
12+
# Motivation:
13+
# Commits which are not --signoff but merged into other branches
14+
# will likely make their way into PRs for master. At which
15+
# point it will be difficult to get the original author to --signoff.
16+
pull_request:
17+
18+
jobs:
19+
commit-checks:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set commit range variables
27+
# Finding the commit range is not as trivial as it may seem.
28+
#
29+
# At this stage git's HEAD does not refer to the latest commit in the PR,
30+
# but rather to the merge commit inserted by the PR. So instead we have
31+
# to get 'HEAD' from the PR event.
32+
#
33+
# One cannot use the number of commits (github.event.pull_request.commits)
34+
# to find the start commit i.e. HEAD~N does not work, this breaks if there
35+
# are merge commits.
36+
run: |
37+
echo "PR_HEAD=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
38+
echo "PR_BASE=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
39+
40+
- name: Install conventional-commit linter
41+
run: |
42+
# Intall the linter and the conventional commits config
43+
npm install @commitlint/config-conventional @commitlint/cli
44+
45+
# Extend the conventional commits config with the `--signoff`
46+
# requirement.
47+
echo "module.exports = {
48+
extends: ['@commitlint/config-conventional'],
49+
rules: {
50+
'signed-off-by': [2, 'always', 'Signed-off-by:'],
51+
}
52+
}" > commitlint.config.js
53+
54+
- name: Conventional commit check
55+
run: |
56+
npx commitlint --from $PR_BASE --to $PR_HEAD
57+
58+
- name: No merge commits
59+
run: |
60+
# This will list any merge commits in the PR commit path
61+
MERGE=$(git log --merges --ancestry-path $PR_BASE..$PR_HEAD)
62+
63+
# The merge list should be empty
64+
[[ ! -z "$MERGE" ]] && {
65+
echo "PR contains merge commits:";
66+
echo $MERGE;
67+
exit 1;
68+
}
69+
exit 0;

docs/CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Before diving in to Interledger.rs, you may find it helpful to familiarize yours
3535
## Pull Requests
3636
We welcome pull requests (PRs) that address reported issues. You can find appropriate issues by `bug` or `help-wanted` labels. To avoid multiple PRs for a single issue, please let us know that you are working on it by a comment for the issue. Also we recommend to make discussions on the issue of how to address the issue, methodology towards the resolution or the architecture of your code, in order to avoid writing inefficient or inappropriate code.
3737

38-
Please follow the instruction below when making pull requests.
38+
Please follow the instruction below when making pull requests. These will be checked by our PR CI process where applicable, so don't worry about getting it wrong.
3939

4040
- Make sure that your branch is forked from the latest `master` branch.
4141
- Make sure that you wrote tests, ran it and the results were all green (required to pass CI).
@@ -47,17 +47,18 @@ Please follow the instruction below when making pull requests.
4747
- To install clippy, run `rustup component add clippy`.
4848
- To run clippy, use `cargo clippy --all-targets --all-features -- -D warnings`.
4949
- If you would like to make your local setup reject unformatted commits, you can add the command as a pre-commit hook in the file `interledger-rs/.git/hooks/pre-commit`.
50-
- Make sure to commit using `-s` or `--signoff` option like `git cz -s`.
50+
- Make sure to commit using `-s` or `--signoff` option like `git cz -s` (required to pass CI).
5151
- `cz` means using the [commitizen](https://github.com/commitizen/cz-cli) explained below.
5252
- Why we use the option is explained later in the [Signing-off](#Signing-off) section.
53-
- Make sure that you committed using the [commitizen](https://github.com/commitizen/cz-cli) format (commit messages should start with `feat:`, `docs:`, `refactor:`, `chore:`, etc). PRs may contain multiple commits but they should generally be squashed into one or a small number of complete change sets (for example, a feature followed by multiple refactors and another commit to add tests and docs should be combined into a single commit for that feature).
53+
- Make sure that you committed using the [commitizen](https://github.com/commitizen/cz-cli) format (commit messages should start with `feat:`, `docs:`, `refactor:`, `chore:`, etc) (required to pass CI). PRs may contain multiple commits but they should generally be squashed into one or a small number of complete change sets (for example, a feature followed by multiple refactors and another commit to add tests and docs should be combined into a single commit for that feature).
5454
- If you would like to make your local setup reject improperly formatted commit headers, you can add the following code to `interledger-rs/.git/hooks/commit-msg`:
5555
```bash
5656
if head -n 1 "$1" | grep -vqE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\(.{1,30}\))?:[ ].{5,100}$"; then
5757
echo "Commit message rejected, commit aborted" && exit 1
5858
fi
5959
```
6060
- Make pull requests against `master` branch of this repository (interledger-rs/interledger-rs) from your repository.
61+
- The pull request should contain no merge commits (required to pass CI).
6162
- If reviewers request some changes, please follow the instruction or make discussions if you have any constructive opinions on the PRs you made.
6263
- Then if you want to make some changes on your PRs, `push -f` is allowed to renew your branch after squashing your new commits. You don't need to open new PRs.
6364
- For our [examples](../examples/README.md), we adopted a [literate programming](https://en.wikipedia.org/wiki/Literate_programming) approach. The examples are described in Markdown with shell commands included. The [`run-md.sh`](../scripts/run-md.sh) script parses the commands out of the Markdown file and runs them. If you want to add examples, please make sure your instruction file can be parsed and run by that script.

0 commit comments

Comments
 (0)