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..e688dd72 --- /dev/null +++ b/orbs/shared/commands/skip_on_chore_commit.yml @@ -0,0 +1,20 @@ +description: > + If the first commit of the branch (where branch diverged from main/master) + 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) + 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_TYPE' 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