Skip to content

Commit

Permalink
feat: lint commit messages with commitlint (#6118)
Browse files Browse the repository at this point in the history
Add support to run Commitlint against commit messages. It supports the
current modes:

- Lint the commit message of the last commit
- Lint the commit messages of the pushed commits in case there is more
  than one pushed commit

This commit also removes stuff that we used to run commitlint as a
standalone tool because we can now use the commitlint instance that
Super-linter ships:

- lint-commit steps in lint-commit the GitHub Actions workflow
- lint-commit Make target
- commitlint and its dependencies in package.json and package-lock.json
  • Loading branch information
ferrarimarco authored Sep 19, 2024
1 parent b526eff commit 5d6e3fc
Show file tree
Hide file tree
Showing 26 changed files with 971 additions and 994 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/lint-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,3 @@ jobs:
else
echo "This pull request contains ${commit_count} commit."
fi
- name: Set commit metadata
run: |
SET_INTERVAL_VALUES="true"
if [[ ${{ github.event_name }} == 'push' ]] || [[ ${{ github.event_name }} == 'merge_group' ]]; then
echo "Using default commit metadata"
SET_INTERVAL_VALUES="false"
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
FROM_INTERVAL_COMMITLINT=${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
TO_INTERVAL_COMMITLINT=${{ github.event.pull_request.head.sha }}
else
echo "[ERROR] Event not supported when setting commit metadata"
exit 1
fi
if [ "${SET_INTERVAL_VALUES}" == "true" ]; then
if [ -z "${FROM_INTERVAL_COMMITLINT}" ]; then
echo "[ERROR] FROM_INTERVAL_COMMITLINT is empty"
exit 1
fi
if [ -z "${TO_INTERVAL_COMMITLINT}" ]; then
echo "[ERROR] TO_INTERVAL_COMMITLINT is empty"
exit 1
fi
{
echo "FROM_INTERVAL_COMMITLINT=${FROM_INTERVAL_COMMITLINT}"
echo "TO_INTERVAL_COMMITLINT=${TO_INTERVAL_COMMITLINT}"
} >> "${GITHUB_ENV}"
else
echo "Skip updating GITHUB_ENV. SET_INTERVAL_VALUES: ${SET_INTERVAL_VALUES}"
fi
- name: Validate commits
run: |
make lint-commits
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ test-actions-runner-debug: ## Run super-linter with ACTIONS_RUNNER_DEBUG=true
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/.github":/tmp/lint/.github \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand All @@ -187,6 +188,7 @@ test-actions-steps-debug: ## Run super-linter with ACTIONS_STEPS_DEBUG=true
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/.github":/tmp/lint/.github \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand All @@ -199,6 +201,7 @@ test-runner-debug: ## Run super-linter with RUNNER_DEBUG=1
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/.github":/tmp/lint/.github \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand All @@ -211,6 +214,7 @@ test-find: ## Run super-linter on a subdirectory with USE_FIND_ALGORITHM=true
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/.github":/tmp/lint/.github \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand All @@ -227,6 +231,7 @@ test-non-default-workdir: ## Run super-linter with DEFAULT_WORKSPACE set
-e DEFAULT_WORKSPACE=/tmp/not-default-workspace \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_ALL_CODEBASE=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v $(CURDIR)/.github:/tmp/not-default-workspace/.github \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand Down Expand Up @@ -433,6 +438,7 @@ test-linter-commands: ## Test linterCommands
# Run this test against a small directory because we're only interested in
# loading default configuration files. The directory that we run super-linter
# against should not be .github because that includes default linter rules.
# Disable commitlint because the workspace is not a Git repository.
.PHONY: test-default-config-files
test-default-config-files: ## Test default configuration files loading
docker run \
Expand All @@ -441,6 +447,7 @@ test-default-config-files: ## Test default configuration files loading
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true \
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/docs":/tmp/lint \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand All @@ -454,6 +461,7 @@ test-custom-ssl-cert: ## Test the configuration of a custom SSL/TLS certificate
-e DEFAULT_BRANCH=main \
-e USE_FIND_ALGORITHM=true \
-e SSL_CERT_SECRET="$(shell cat test/data/ssl-certificate/rootCA-test.crt)" \
-e VALIDATE_GIT_COMMITLINT=false \
-v "$(CURDIR)/docs":/tmp/lint \
--rm \
$(SUPER_LINTER_TEST_CONTAINER_URL)
Expand Down Expand Up @@ -592,19 +600,6 @@ build-dev-container-image: docker-dev-container-build-check ## Build commit lint
--build-arg UID=$(shell id -u) \
-t ${DEV_CONTAINER_URL} "${CURDIR}/dev-dependencies"

.PHONY: lint-commits
lint-commits: build-dev-container-image ## Lint commits
docker run \
-v "$(CURDIR):/source-repository" \
--rm \
${DEV_CONTAINER_URL} \
commitlint \
--config .github/linters/commitlint.config.js \
--cwd /source-repository \
--from ${FROM_INTERVAL_COMMITLINT} \
--to ${TO_INTERVAL_COMMITLINT} \
--verbose

.PHONY: release-please-dry-run
release-please-dry-run: build-dev-container-image check-github-token ## Run release-please in dry-run mode to preview the release pull request
@echo "Running release-please against branch: ${RELEASE_PLEASE_TARGET_BRANCH}"; \
Expand Down
Loading

0 comments on commit 5d6e3fc

Please sign in to comment.