diff --git a/.github/scripts/ensure_all_commits_start_with_gitmoji.sh b/.github/scripts/ensure_all_commits_start_with_gitmoji.sh new file mode 100644 index 00000000..96e6e3a7 --- /dev/null +++ b/.github/scripts/ensure_all_commits_start_with_gitmoji.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Usage: ./ensure_all_commits_start_with_gitmoji.sh +# Working directory should be the root of the repository. + +commit_messages_file=$1 +gitmoji_list_file=$2 + +# Check each commit message +is_ok=true +while IFS= read -r commit; do + .scripts/ensure_commit_starts_with_gitmoji.sh "$commit" "$gitmoji_list_file" + if [[ $? -eq 1 ]]; then + is_ok=false + break + fi +done < "$commit_messages_file" + +if [[ $is_ok == false ]]; then + echo "Commit message does not start with a Gitmoji: '$commit'" + exit 1 +fi diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 08c11756..7c2046a6 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -14,7 +14,6 @@ jobs: submodules: false - name: Get commits from pull request - # Fetch commit messages from the pull request shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -23,33 +22,19 @@ jobs: "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits" \ | jq -r '.[].commit.message' > commit_messages.txt - - name: Get all Gitmoji's + - name: Get all gitmoji's shell: bash run: | curl -s https://gitmoji.dev/api/gitmojis > gitmoji_spec.json cat gitmoji_spec.json | jq '.gitmojis[] | .emoji, .code' > gitmojis.txt - - name: Check if commit messages contain a Gitmoji + - name: Check if commit messages start with a gitmoji shell: bash run: | - gitmoji_script="${{ github.workspace }}/.scripts/ensure_commit_starts_with_gitmoji.sh" + gitmoji_script="${{ github.workspace }}/.github/scripts/ensure_all_commits_start_with_gitmoji.sh" # Set executable permission on the script chmod +x $gitmoji_script # Check each commit message - is_ok=true - while IFS= read -r commit; do - $gitmoji_script "$commit" gitmojis.txt - if [[ $? -eq 1 ]]; then - is_ok=false - break - fi - done < commit_messages.txt - - if [[ $is_ok == false ]]; then - echo "Commit message does not start with a Gitmoji: '$commit'" - exit 1 - else - echo "All commit messages start with a Gitmoji" - fi + $gitmoji_script commit_messages.txt gitmojis.txt