From 8839b0af45164abd947cbb9a56316dd4a9572df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0mejkal?= Date: Fri, 10 Nov 2023 23:32:35 +0100 Subject: [PATCH 1/2] feat: skip jobs for chore commits --- orbs/shared/commands/skip_on_chore_commit.yml | 18 ++++++++++++++++++ orbs/shared/jobs/docker_amd64.yaml | 1 + orbs/shared/jobs/e2e.yaml | 1 + orbs/shared/jobs/test_node_client.yaml | 1 + 4 files changed, 21 insertions(+) create mode 100644 orbs/shared/commands/skip_on_chore_commit.yml diff --git a/orbs/shared/commands/skip_on_chore_commit.yml b/orbs/shared/commands/skip_on_chore_commit.yml new file mode 100644 index 00000000..90c1a92d --- /dev/null +++ b/orbs/shared/commands/skip_on_chore_commit.yml @@ -0,0 +1,18 @@ +description: > + If the first commit of the branch (where branch diverged from main/master) + starts with 'chore:' all the following steps of the job will be skipped + and the job finishes as succeeded +steps: + - checkout + - run: + name: Evaluate commit type + command: | + DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | cut -f 4 -d /) + COMMIT_MESSAGE=$(git log $DEFAULT_BRANCH..$CIRCLE_SHA1 --format=%s | tail -1) + echo "First commit: $COMMIT_MESSAGE" + if [[ "${COMMIT_MESSAGE%:*}" == "chore" ]]; then + echo "Skipping job for '${COMMIT_MESSAGE%:*}' commit type." + circleci step halt + else + echo "Running job for '${COMMIT_MESSAGE%:*}' commit type." + fi diff --git a/orbs/shared/jobs/docker_amd64.yaml b/orbs/shared/jobs/docker_amd64.yaml index 91eefdf5..51f00c27 100644 --- a/orbs/shared/jobs/docker_amd64.yaml +++ b/orbs/shared/jobs/docker_amd64.yaml @@ -3,6 +3,7 @@ executor: name: testbed-machine resource_class: xlarge steps: + - skip_on_chore_commit - setup_environment: machine: true - build_docker_image diff --git a/orbs/shared/jobs/e2e.yaml b/orbs/shared/jobs/e2e.yaml index c51bb514..f473621b 100644 --- a/orbs/shared/jobs/e2e.yaml +++ b/orbs/shared/jobs/e2e.yaml @@ -38,6 +38,7 @@ environment: USE_DEVSPACE: << parameters.use_devspace >> resource_class: << parameters.resource_class >> steps: + - skip_on_chore_commit - setup_environment: machine: true - run: diff --git a/orbs/shared/jobs/test_node_client.yaml b/orbs/shared/jobs/test_node_client.yaml index b6598e26..69a0ff31 100644 --- a/orbs/shared/jobs/test_node_client.yaml +++ b/orbs/shared/jobs/test_node_client.yaml @@ -5,6 +5,7 @@ parameters: executor: name: testbed-docker steps: + - skip_on_chore_commit - setup_environment - with_node_client_cache: save: true From feef79b5e7ee8833759fdc5e147ad3cfbe746516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0mejkal?= Date: Mon, 13 Nov 2023 10:13:37 +0100 Subject: [PATCH 2/2] more types and scopes accepted --- orbs/shared/commands/skip_on_chore_commit.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/orbs/shared/commands/skip_on_chore_commit.yml b/orbs/shared/commands/skip_on_chore_commit.yml index 90c1a92d..e688dd72 100644 --- a/orbs/shared/commands/skip_on_chore_commit.yml +++ b/orbs/shared/commands/skip_on_chore_commit.yml @@ -1,18 +1,20 @@ description: > If the first commit of the branch (where branch diverged from main/master) - starts with 'chore:' all the following steps of the job will be skipped - and the job finishes as succeeded + starts with 'chore', 'ci' or 'docs' all the following steps of the job will be skipped + and the job finishes as succeeded. steps: - checkout - run: name: Evaluate commit type command: | DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | cut -f 4 -d /) - COMMIT_MESSAGE=$(git log $DEFAULT_BRANCH..$CIRCLE_SHA1 --format=%s | tail -1) - echo "First commit: $COMMIT_MESSAGE" - if [[ "${COMMIT_MESSAGE%:*}" == "chore" ]]; then - echo "Skipping job for '${COMMIT_MESSAGE%:*}' commit type." - circleci step halt + COMMIT_MESSAGE=$(git log "$DEFAULT_BRANCH..$CIRCLE_SHA1" --format=%s | tail -1) + COMMIT_PREFIX="${COMMIT_MESSAGE%%:*}" + COMMIT_TYPE="${COMMIT_PREFIX%%(*}" + echo "Identified commit type '$COMMIT_TYPE' in the first commit message '$COMMIT_MESSAGE'" + if [[ $COMMIT_TYPE =~ ^(chore|ci|docs)$ ]]; then + echo "Skipping job for '$COMMIT_TYPE' commit type." + circleci-agent step halt else - echo "Running job for '${COMMIT_MESSAGE%:*}' commit type." + echo "Running job for '$COMMIT_TYPE' commit type." fi