Skip to content

Commit abcbc35

Browse files
committed
fix(commitlint): merge back changes handling git refs, commitlint config
1 parent 0a2d8ff commit abcbc35

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

commitlint/action.yaml

+19-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ runs:
4747
echo "::notice::Parsing base ref '$FROM'"
4848
# If we do have the base ref, it can be a branch name, so we want to
4949
# parse it. This will be a pass through for a SHA
50-
FROM="$(git show-ref --hash "$FROM" | tail -n1)"
50+
# via the event context, and we should try to find the default
51+
# branch instead (see below)
52+
if ! git show-ref --hash "$FROM" &>/dev/null; then
53+
# No such ref, so we try the next step
54+
FROM=""
55+
else
56+
FROM="$(git show-ref --hash "$FROM" | tail -n1)"
57+
fi
5158
fi
5259
fi
5360
# If we don't have a base ref, we try to find the history to the default
@@ -80,12 +87,20 @@ runs:
8087
echo "::warning::Could not find commit range for commitlint"
8188
echo "::notice::Checking 20 most recent commit messages."
8289
fi
83-
commitlint --config "${{ inputs.config-file }}" \
90+
CONFIG_FILE="${{ inputs.config-file }}"
91+
if [[ -n "$CONFIG_FILE" ]]; then
92+
CONFIG_FILE="--config $CONFIG_FILE"
93+
fi
94+
echo "::notice::Running commitlint"
95+
commitlint \
96+
$CONFIG_FILE \
8497
--verbose \
8598
--color \
8699
--from "$FROM" \
87100
--to HEAD
88101
- name: Restore commitlint config
89-
if: always() && hashFiles(inputs.config-file) != '' && inputs.turo-conventional-commit
102+
if: always() && hashFiles(inputs.config-file) != '' && inputs.turo-conventional-commit == 'true'
90103
shell: bash
91-
run: git checkout -- "${{ inputs.config-file }}" || true
104+
run: |
105+
# Restore the commitlint config file if we wrote it
106+
git checkout -- "${{ inputs.config-file }}" &>/dev/null || true

0 commit comments

Comments
 (0)