Skip to content

QA-23787: adding a new wf for boiler app test #576

QA-23787: adding a new wf for boiler app test

QA-23787: adding a new wf for boiler app test #576

---
name: Lint Commit Messages
on:
pull_request:
merge_group:
jobs:
commit-lint:
runs-on:
group: infra1-runners-arc
labels: runners-small
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
- id: set_commit_range
name: Set commit range based on event type
shell: bash
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
echo "commit_range=${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
elif [[ ${{ github.event_name }} == 'merge_group' ]]; then
echo "commit_range=${{ github.event.merge_group.base_sha }}..${{ github.event.merge_group.head_sha }}" >> $GITHUB_OUTPUT
else
echo "Unsupported event type: ${{ github.event_name }}"
exit 1
fi
- name: Validate commits
if: success()
shell: bash
run: |
# Validate commits against Conventional Commits guidelines and internal rules
# Define conventional commit regex with optional breaking change mark
CONVENTIONAL_REGEX="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.+\))?!?: .{1,70}"
# Get commit subjects and hashes
COMMITS=$(git log --reverse --no-merges --pretty=format:"%h %s" ${{ steps.set_commit_range.outputs.commit_range }})
# Initialize violation flag and message
VIOLATIONS=""
# Check each commit subject
while IFS= read -r COMMIT; do
COMMIT_HASH=$(echo "$COMMIT" | awk '{print $1}')
COMMIT_SUBJECT=$(echo "$COMMIT" | cut -d' ' -f2-)
COMMIT_VIOLATIONS=""
if [[ "$COMMIT_SUBJECT" =~ ^revert ]]; then
continue
fi
if ! [[ "$COMMIT_SUBJECT" =~ $CONVENTIONAL_REGEX ]]; then
COMMIT_VIOLATIONS+=":x: does not follow Conventional Commits guidelines\n"
fi
if [[ ! "$COMMIT_SUBJECT" =~ ^chore(\(deps\):|:[[:space:]]bump) ]] && [[ ${#COMMIT_SUBJECT} -gt 70 ]]; then
COMMIT_VIOLATIONS+=":x: exceeds 70 characters\n"
fi
REPO_NAME="${{ github.repository }}"
if [[ "$REPO_NAME" =~ ^(.*/)?(gdc-nas|gdc-ui|gooddata-ui-sdk|gdc-panther)$ ]]; then
if [[ ! "$COMMIT_SUBJECT" =~ ^chore.*:[[:space:]][Uu]pdate ]]; then
TRAILERS=$(git show -s --format=%B "$COMMIT_HASH" | git interpret-trailers --parse)
if ! echo "$TRAILERS" | grep -iqE '^risk:\s*(nonprod|low|high)'; then
COMMIT_VIOLATIONS+=":x: does not contain a valid risk trailer\n"
fi
fi
fi
if [[ -n "$COMMIT_VIOLATIONS" ]]; then
VIOLATIONS+="\`$COMMIT_HASH $COMMIT_SUBJECT\`\n$COMMIT_VIOLATIONS\n"
fi
done <<< "$COMMITS"
# Output violations if any
if [[ -n "$VIOLATIONS" ]]; then
echo -e "$VIOLATIONS"
echo "## Commit Lint Results" >> $GITHUB_STEP_SUMMARY
echo "### Violations" >> $GITHUB_STEP_SUMMARY
echo -e "$VIOLATIONS" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "All commit messages follow Conventional Commits guidelines."
echo "## Commit Lint Results" >> $GITHUB_STEP_SUMMARY
echo ":white_check_mark: All commit messages follow Conventional Commits guidelines." >> $GITHUB_STEP_SUMMARY