From 6bc3123108b89940a9fa73023a388b566b3fb60f Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Wed, 27 Mar 2024 11:57:04 -0700 Subject: [PATCH] This is an error. --- .github/workflows/CI.yml | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e18de745b8..7c20b311b0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,6 +20,88 @@ jobs: - name: Checkout Files uses: actions/checkout@v4 id: checkout + + - name: Check commit message + shell: bash + run: | + # This script checks that the commit message is formatted according to the standard: + # - First line: no more than 62 chars and not ending with period (or if it is the + # only line: no more than 70 chars) + # - Second line: empty + # - Following lines: no more than 70 chars + # Run git log command and capture its output + log_output=$(git log --pretty=format:"---commit---%n%H%n%B" ${{ github.event.pull_request.base.sha }}..) + # Define states + STATE_INITIAL="INITIAL" + STATE_HASH="HASH" + STATE_FIRST="FIRST" + STATE_LONG_FIRST="LONG_FIRST" + STATE_SECOND="SECOND" + STATE_OTHER="OTHER" + # Initialize variables + state="$STATE_INITIAL" + commit_hash="" + # Function to reset state to Hash + reset_state() { + state="$STATE_HASH" + commit_hash="" + } + # Iterate through the log results + while IFS= read -r log_line; do + case "$state" in + "$STATE_INITIAL") + # Move to Hash state + if [[ "$log_line" == "---commit---" ]]; then + state="$STATE_HASH" + fi + ;; + "$STATE_HASH") + # Capture commit hash and move to First state + commit_hash="$log_line" + state="$STATE_FIRST" + ;; + "$STATE_FIRST") + # Check first line length and punctuation, move to Second state + if [[ ${#log_line} -gt 70 ]]; then + echo "::warning ⚠️ First line was too long in $commit_hash" + break + elif [[ "$log_line" == *"." ]]; then + echo "::error The first line should not end in a period in $commit_hash" + break + elif [[ ${#log_line} -gt 62 ]]; then + state="$STATE_LONG_FIRST" + else + state="$STATE_SECOND" + fi + ;; + "$STATE_LONG_FIRST") + # Check second line and move to Other state + if [[ "$log_line" == "---commit---" ]]; then + reset_state + else + echo "::warning ⚠️ First line should be less than 60 chars if there is more than one line. $commit_hash" + break + fi + ;; + "$STATE_SECOND") + # Check second line and move to Other state + if [[ -n "$log_line" ]]; then + echo "::error Second line is not blank in commit $commit_hash" + exit 1 + fi + state="$STATE_OTHER" + ;; + "$STATE_OTHER") + # Check other lines length and move to Other state or reset to Hash state + if [[ ${#log_line} -gt 70 ]]; then + echo "::warning ⚠️ Line exceeds 70 characters in commit $commit_hash" + break + elif [[ "$log_line" == "---commit---" ]]; then + reset_state + fi + ;; + esac + done - name: Download 461 targeting pack uses: suisei-cn/actions-download-file@818d6b7dc8fe73f2f924b6241f2b1134ca1377d9 # 1.6.0