-
Notifications
You must be signed in to change notification settings - Fork 31
CircleCI - added a filtering branch for the push trigger
#1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eae7ff7
Added a "branch_protection_filter" CI task to filter out a direct pus…
pomek e02b8b8
Apply suggestion from @pomek
pomek 8fddba4
Debug log.
pomek bf65f90
Apply suggestion from @pomek
pomek ed6fbae
Apply suggestion from @pomek
pomek 7987dfb
Thu Jul 17 08:02:09 AM CEST 2025 -- ci/4073-ci-filters.
pomek 4aec9de
Thu Jul 17 08:02:32 AM CEST 2025 -- ci/4073-ci-filters.
pomek 24c710b
Thu Jul 17 08:50:47 AM CEST 2025 -- ci/4073-ci-filters.
pomek 52c8164
Use a dedicated config to handle CircleCI Github event parameters.
pomek d844fd5
Thu Jul 17 09:54:02 AM CEST 2025 -- ci/4073-ci-filters.
pomek 6b7b444
Thu Jul 17 09:55:37 AM CEST 2025 -- ci/4073-ci-filters.
pomek e5b96fe
Apply suggestion from @pomek
pomek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # This is the based configuration required by CircleCI to run a build. | ||
| # | ||
| # | ||
| # The repository uses the dynamic configuration to generate | ||
| # tasks for executing tests and checking the code coverage. | ||
| # | ||
| # This configuration aims to prepare a complete design and continue checking | ||
| # the repository in a new workflow. | ||
| # | ||
| # To modify the commands to execute on CI, review the following files: | ||
| # - scripts/ci/generate-circleci-configuration.js - the script that creates the `config-tests.yml` file used on the new workflow. | ||
| # - .circleci/template.yml - the template filled with data to execute. | ||
| # | ||
| # Useful resources: | ||
| # - https://circleci.com/docs/using-dynamic-configuration/ | ||
| version: 2.1 | ||
|
|
||
| setup: true | ||
|
|
||
| parameters: | ||
| triggerCommitHash: | ||
| type: string | ||
| default: "" | ||
| isNightly: | ||
| type: boolean | ||
| default: false | ||
| isRelease: | ||
| type: boolean | ||
| default: false | ||
|
|
||
| orbs: | ||
| continuation: circleci/continuation@0.1.2 | ||
|
|
||
| commands: | ||
| install_ssh_keys_command: | ||
| description: "Install SSH keys" | ||
| steps: | ||
| - add_ssh_keys: | ||
| fingerprints: | ||
| - "a0:41:a2:56:c8:7d:3f:29:41:d1:87:92:fd:50:2b:6b" | ||
|
|
||
| jobs: | ||
| branch_protection_filter: | ||
| machine: true | ||
| resource_class: medium | ||
| steps: | ||
| - run: | ||
| name: Check if the build should continue. | ||
| command: | | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| PIPELINE_EVENT_ACTION="<< pipeline.event.action >>" | ||
| PIPELINE_GIT_BRANCH="<< pipeline.git.branch >>" | ||
|
|
||
| # Check what happens when applying a suggestion. | ||
| echo PIPELINE_EVENT_ACTION=$PIPELINE_EVENT_ACTION | ||
| echo PIPELINE_GIT_BRANCH=$PIPELINE_GIT_BRANCH | ||
|
|
||
| readonly PROTECTED_BRANCHES=( | ||
| master | ||
| ) | ||
|
|
||
| readonly ALLOWED_PATTERNS=( | ||
| '^epic/' | ||
| '/epic/' | ||
| ) | ||
|
|
||
| is_protected_branch() { | ||
| for b in "${PROTECTED_BRANCHES[@]}"; do | ||
| [[ $PIPELINE_GIT_BRANCH == "$b" ]] && return 0 | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| matches_allowed_pattern() { | ||
| for pattern in "${ALLOWED_PATTERNS[@]}"; do | ||
| [[ $PIPELINE_GIT_BRANCH =~ $pattern ]] && return 0 | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| should_allow_pipeline() { | ||
| # Allow for non-push events. A job could be trigger via API, a pull request, or a scheduled event. | ||
| [[ $PIPELINE_EVENT_ACTION != "push" ]] && return 0 | ||
|
|
||
| # Direct commits on protected branches (after merging a pull request). | ||
| is_protected_branch && return 0 | ||
|
|
||
| # Epic branches (direct commits or merged pull requests). | ||
| matches_allowed_pattern && return 0 | ||
|
|
||
| # Most probably a direct commit on a feature branch. | ||
| return 1 | ||
| } | ||
|
|
||
| if ! should_allow_pipeline; then | ||
| circleci-agent step halt | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit 0 | ||
|
|
||
| generate_configuration: | ||
| docker: | ||
| - image: cimg/node:22.12.0 | ||
| steps: | ||
| - checkout | ||
| - install_ssh_keys_command | ||
| - run: | ||
| name: Install dependencies | ||
| command: yarn install | ||
| - run: | ||
| name: Generate a new configuration to check all packages in the repository | ||
| command: node scripts/ci/generate-circleci-configuration.js | ||
| - continuation/continue: | ||
| configuration_path: .circleci/config-tests.yml | ||
|
|
||
| workflows: | ||
| version: 2 | ||
| config: | ||
| jobs: | ||
| - branch_protection_filter | ||
| - generate_configuration: | ||
| requires: | ||
| - branch_protection_filter | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.