Skip to content

Commit

Permalink
Handle multi line strings in include statements (#13)
Browse files Browse the repository at this point in the history
* Handle multi line strings in include statements

* Add tests for multi-line inputs

* correct test step name

* revert logic at the end
  • Loading branch information
adamrtalbot authored Nov 22, 2024
1 parent e114e73 commit 6bf6fd9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
Binary file modified .github/workflows/test.tar.gz
Binary file not shown.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ jobs:
head: change_module_a
base: main
tags: "test" # should pick up no tests


- name: Detect multi-line include
id: multi_line_include
uses: ./
with:
root: testrepo/test
head: multi_line_include
base: main

- name: print outputs
run: |
echo Default: ${{ steps.detect_module_a_default.outputs.components }}
Expand All @@ -90,3 +98,5 @@ jobs:
echo Directories: ${{ steps.detect_module_a_directory.outputs.components }}
echo Config files: ${{ steps.detect_config_changes.outputs.components }}
echo Additional include file: ${{ steps.detect_additional_include_file.outputs.components }}
echo Tags: ${{ steps.detect_tags.outputs.components }}
echo Multi-line include: ${{ steps.multi_line_include.outputs.components }}
2 changes: 1 addition & 1 deletion .github/workflows/test/modules/a/main.nf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
process PROCESS_A {
// Fake change
// No change
}
5 changes: 4 additions & 1 deletion .github/workflows/test/subworkflows/a/main.nf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
include { PROCESS_A } from '../../modules/a/main.nf'
include {
PROCESS_A;
PROCESS_B
} from '../../modules/a/main.nf'

workflow SUBWORKFLOW_A {
PROCESS_A()
Expand Down
15 changes: 15 additions & 0 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ def find_include_statements(self) -> list[str]:
result = []
for line in self.lines:
if "include {" in line:
# Handle multi-line include statements
if "{" in line and "}" not in line:
# Keep reading lines until we find the closing brace
full_include = line
line_idx = self.lines.index(line) + 1
while (
line_idx < len(self.lines) and "}" not in self.lines[line_idx]
):
full_include += self.lines[line_idx]
line_idx += 1
if line_idx < len(self.lines):
full_include += self.lines[line_idx]
line = full_include

# Extract the 'from' part which contains the path
dependency = line.split()[2].strip("'\"").replace("/", "_").casefold()
result.append(dependency)
return result
Expand Down

0 comments on commit 6bf6fd9

Please sign in to comment.