Skip to content

Commit

Permalink
🔨 Move gitmoji check heavy-lifting from CI workflow to bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
vis4rd committed Sep 22, 2024
1 parent d668354 commit 625fe3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/ensure_all_commits_start_with_gitmoji.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Usage: ./ensure_all_commits_start_with_gitmoji.sh <commit_messages_file> <gitmoji_list_file>
# 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
23 changes: 4 additions & 19 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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

0 comments on commit 625fe3e

Please sign in to comment.