Skip to content

Commit

Permalink
ci: Require commits to have conventional commit prefix (open-policy-a…
Browse files Browse the repository at this point in the history
…gent#766)

This helps reviewers and automation quickly categorize the change.

Signed-off-by: James Alseth <[email protected]>
  • Loading branch information
jalseth authored Jan 10, 2023
1 parent efe8033 commit 3b6c625
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ permissions:
statuses: none

jobs:
style:
runs-on: ubuntu-latest
steps:
- name: checkout all PR branch and commits
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ github.event.pull_request.commits }}

- name: validate conventional commit prefix
working-directory: scripts
run: ./validate-conventional-commit-prefix.sh

validate:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ If you are contributing code, please consider the following:
- Most changes should be accompanied by tests.
- All commits must be signed off (see next section).
- Related commits must be squashed before they are merged.
- All commits must have a [conventional commit prefix](https://www.conventionalcommits.org/en/v1.0.0/#summary), such as `feat:`, `fix:`, etc.
- All tests must pass.

If you are new to Go, consider reading [Effective
Expand All @@ -45,7 +46,7 @@ guidance on writing idiomatic Go code.
Commit messages should explain *why* the changes were made and should probably look like this:

```
Description of the change in 50 characters or less
fix: Description of a bug fix in 50 characters or less
More detail on what was changed. Provide some background on the issue
and describe how the changes address the issue. Feel free to use multiple
Expand Down Expand Up @@ -103,4 +104,4 @@ their own commit and added to the PR.

If your Pull Request is small though, it is acceptable to squash changes during
the review process. Use your judgment about what constitutes a small Pull
Request. If you aren't sure, send a message to the `#conftest` channel on the OPA slack or post a comment on the Pull Request.
Request. If you aren't sure, send a message to the `#conftest` channel on the OPA slack or post a comment on the Pull Request.
16 changes: 16 additions & 0 deletions scripts/validate-conventional-commit-prefix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -eo pipefail

code=0
while read -r commit; do
match=$(echo "${commit}" | grep -o -h -E "^[a-z]+(\([a-z]+\))?: " || true)
if [[ -z "${match}" ]]; then
echo "::error::Commit \"${commit}\" does not have the required conventional commit prefix. See https://www.conventionalcommits.org/ for more info."
code=1
else
echo "Commit \"${commit}\" has conventional commit prefix \"${match}\"."
fi
done < <(git --no-pager log --pretty=format:%s && echo "") # git log does not include newline after last commit

exit ${code}

0 comments on commit 3b6c625

Please sign in to comment.