|
| 1 | +name: "Check commit messages" |
| 2 | +description: "Performs checks for commit messages format." |
| 3 | + |
| 4 | +runs: |
| 5 | + using: "composite" |
| 6 | + steps: |
| 7 | + - name: Setup python |
| 8 | + uses: actions/setup-python@v4 |
| 9 | + with: |
| 10 | + python-version: "${{ env.PYTHON_VERSION }}" |
| 11 | + |
| 12 | + - name: Activate Python virtualenv |
| 13 | + shell: bash |
| 14 | + run: | |
| 15 | + # Activate Python virtualenv |
| 16 | + echo "VIRTUAL_ENV=${PWD}/.venv" >> "${GITHUB_ENV}" |
| 17 | + echo "${PWD}/.venv/bin" >> "${GITHUB_PATH}" |
| 18 | + echo "PRE_COMMIT=$(grep -m1 pre-commit test/requirements.txt)" >> ${GITHUB_ENV} |
| 19 | +
|
| 20 | + - name: Cache Python virtualenv |
| 21 | + id: cache-pre_commit-venv |
| 22 | + uses: actions/cache@v4 |
| 23 | + with: |
| 24 | + key: ${{ env.PRE_COMMIT }}-venv-${{ runner.os }}-Py_${{ env.PYTHON_VERSION }}-${{ hashFiles('test/requirements.txt') }} |
| 25 | + path: ${{ env.VIRTUAL_ENV }} |
| 26 | + |
| 27 | + - name: Install pre-commit in virtualenv |
| 28 | + if: steps.cache-pre_commit-venv.outputs.cache-hit != 'true' |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + # Install pre-commit |
| 32 | + python3 -m venv "${{ env.VIRTUAL_ENV }}" |
| 33 | + python -m pip install $PRE_COMMIT |
| 34 | +
|
| 35 | +
|
| 36 | + - name: Set git config user info |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + # Set git config user info |
| 40 | + git config user.name "$(git --no-pager log --format=format:'%an' -n 1)" |
| 41 | + git config user.email "$(git --no-pager log --format=format:'%ae' -n 1)" |
| 42 | +
|
| 43 | + - name: Cache pre-commit repo data |
| 44 | + uses: actions/cache@v4 |
| 45 | + with: |
| 46 | + path: ~/.cache/pre-commit |
| 47 | + key: ${{ env.PRE_COMMIT }}|${{ runner.os }}|Py_${{ env.PYTHON_VERSION }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 48 | + |
| 49 | + - name: Get commit messages |
| 50 | + id: get_commit_msgs |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + # Get commit messages |
| 54 | + dir=$(mktemp -d -t commit_msgs_XXXXXXX) |
| 55 | + echo "COMMIT_MSG_DIR=$dir" >> $GITHUB_OUTPUT |
| 56 | + commits=$(git log --pretty=format:"%H" "origin/master..HEAD") |
| 57 | + for hash in $commits; do |
| 58 | + git show -s --format=%B $hash > $dir/$hash.txt |
| 59 | + done |
| 60 | +
|
| 61 | + - name: Checks for commit messages format |
| 62 | + id: check_commit_msgs |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + # Checks for commit messages format |
| 66 | + for file in ${{ steps.get_commit_msgs.outputs.COMMIT_MSG_DIR }}/*.txt; do |
| 67 | + hash=${$(basename $file)%.*} |
| 68 | + echo "Check message for <${hash}>" |
| 69 | + echo " > \"$(git log --pretty=format:%s ${hash}^..${hash})\"" |
| 70 | + pre-commit run --commit-msg-filename $file --hook-stage commit-msg |
| 71 | + done |
0 commit comments