Skip to content

Commit

Permalink
Adds support to pass file path in mapping (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Poonam Jadhav <poonam@circleci.com>
  • Loading branch information
fruit and Poonam Jadhav authored Dec 2, 2022
1 parent 3104d92 commit 28645d2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Empty file modified src/commands/set-parameters.yml
100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions src/examples/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ usage:
mapping: |
src/.* build-code true
doc/.* build-docs true
- path-filtering/filter:
base-revision: main
config-path: .circleci/continue-config.yml
mapping: .circleci/mapping.conf
3 changes: 2 additions & 1 deletion src/jobs/filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ parameters:
default: ""
description: >
Mapping of path regular expressions to pipeline parameters and
values. One mapping per line, whitespace-delimited.
values. If the value is a file, then it will be loaded from the disk.
One mapping per line, whitespace-delimited.
config-path:
type: string
default: ".circleci/continue_config.yml"
Expand Down
16 changes: 11 additions & 5 deletions src/scripts/create-parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ def checkout(revision):
capture_output=True
).stdout.decode('utf-8').splitlines()

mappings = [
m.split() for m in
os.environ.get('MAPPING').splitlines()
]
mappingConfig = os.environ.get('MAPPING')
if os.path.exists(mappingConfig):
with open(mappingConfig) as f:
mappings = [
m.split() for m in f.read().splitlines()
]
else:
mappings = [
m.split() for m in
mappingConfig.splitlines()
]

def check_mapping(m):
if 3 != len(m):
Expand All @@ -78,4 +85,3 @@ def convert_mapping(m):

with open(output_path, 'w') as fp:
fp.write(json.dumps(mappings))

0 comments on commit 28645d2

Please sign in to comment.