Skip to content

ci: add auto checks for commit message #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/actions/check-commit-msg/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: "Check commit messages"
description: "Performs checks for commit messages format."

runs:
using: "composite"
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Activate Python virtualenv
shell: bash
run: |
# Activate Python virtualenv
echo "VIRTUAL_ENV=${PWD}/.venv" >> "${GITHUB_ENV}"
echo "${PWD}/.venv/bin" >> "${GITHUB_PATH}"
echo "PRE_COMMIT=$(grep -m1 pre-commit test/requirements.txt)" >> ${GITHUB_ENV}
- name: Cache Python virtualenv
id: cache-pre_commit-venv
uses: actions/cache@v4
with:
key: ${{ env.PRE_COMMIT }}-venv-${{ runner.os }}-Py_${{ env.PYTHON_VERSION }}-${{ hashFiles('test/requirements.txt') }}
path: ${{ env.VIRTUAL_ENV }}

- name: Install pre-commit in virtualenv
if: steps.cache-pre_commit-venv.outputs.cache-hit != 'true'
shell: bash
run: |
# Install pre-commit
python3 -m venv "${{ env.VIRTUAL_ENV }}"
python -m pip install $PRE_COMMIT
- name: Set git config user info
shell: bash
run: |
# Set git config user info
git config user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
- name: Cache pre-commit repo data
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ env.PRE_COMMIT }}|${{ runner.os }}|Py_${{ env.PYTHON_VERSION }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Get commit messages
id: get_commit_msgs
shell: bash
run: |
# Get commit messages
dir=$(mktemp -d -t commit_msgs_XXXXXXX)
echo "COMMIT_MSG_DIR=$dir" >> $GITHUB_OUTPUT
commits=$(git log --pretty=format:"%H" "origin/master..HEAD")
for hash in $commits; do
git show -s --format=%B $hash > $dir/$hash.txt
done
- name: Checks for commit messages format
id: check_commit_msgs
shell: bash
run: |
# Checks for commit messages format
for file in ${{ steps.get_commit_msgs.outputs.COMMIT_MSG_DIR }}/*.txt; do
hash=$(basename ${file%.*})
echo "Check message for <${hash}>"
echo " > \"$(git log --pretty=format:%s ${hash}^..${hash})\""
pre-commit run --commit-msg-filename $file --hook-stage commit-msg
done
11 changes: 11 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ env:
PYTHON_VERSION: '3.10'

jobs:
check-commit-msg:
if: github.event_name == 'push'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check commit messages
uses: ./.github/actions/check-commit-msg

tests-ce:
if: |
(github.event_name == 'push') ||
Expand Down
Loading