Skip to content
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

ci: Update module_name filter step #7106

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/scripts/get_module_path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Test this locally with:
// node .github/scripts/get_module_path.js

// Core functionality that processes the file paths
function get_module_names(filter_modules_files) {
return [
...new Set(
filter_modules_files.map((path) =>
path
.replace("tests/", "")
.replace("modules/nf-core/", "")
.split("/")
.slice(0, 2)
.filter(
(x) =>
!x.startsWith("main.nf") &&
x !== "tests" &&
x !== "meta.yml" &&
x !== "environment.yml" &&
!x.endsWith(".snap") &&
!x.endsWith(".config")
)
.join("/")
)
),
];
}

// GitHub Actions entry point
function run({ github, context }) {
try {
// Debug logging
console.log('Context payload:', context.payload);
console.log('Input files:', context.payload.inputs?.files);

// Get the files from the context and ensure it's a valid JSON string
let files;
if (typeof context.payload.inputs?.files === "string") {
console.log('Processing string input');
files = JSON.parse(context.payload.inputs.files);
} else if (Array.isArray(context.payload.inputs?.files)) {
console.log('Processing array input');
files = context.payload.inputs.files;
} else {
console.log('No valid input found, defaulting to empty array');
files = [];
}

console.log('Files to process:', files);
const result = get_module_names(files);
console.log('Processed result:', result);

// Ensure we're returning a properly formatted JSON string
const jsonResult = JSON.stringify(result);
console.log('Final JSON output:', jsonResult);
return jsonResult;
} catch (error) {
console.error("Error processing module paths:", error);
console.error("Error details:", {
errorName: error.name,
errorMessage: error.message,
errorStack: error.stack
});
return "[]";
}
}

// Test cases
function runTests() {
const test_case_1 = [
"modules/nf-core/umicollapse/tests/main.nf.test",
"modules/nf-core/umicollapse/tests/main.nf.test.snap",
"modules/nf-core/umicollapse/tests/nextflow.config",
"modules/nf-core/umicollapse/tests/nextflow_PE.config",
"modules/nf-core/umicollapse/tests/nextflow_SE.config",
"modules/nf-core/umitools/dedup/tests/main.nf.test",
"modules/nf-core/umitools/dedup/tests/main.nf.test.snap",
"modules/nf-core/umitools/dedup/main.nf",
];
const result_1 = ["umicollapse", "umitools/dedup"];

const test_case_2 = [
"modules/nf-core/mafft/align/environment.yml",
"modules/nf-core/mafft/align/main.nf",
"modules/nf-core/mafft/align/meta.yml",
"modules/nf-core/mafft/align/tests/main.nf.test",
"modules/nf-core/mafft/align/tests/main.nf.test.snap",
"modules/nf-core/mafft/guidetree/environment.yml",
"modules/nf-core/mafft/guidetree/main.nf",
"modules/nf-core/mafft/guidetree/meta.yml",
"modules/nf-core/mafft/guidetree/tests/main.nf.test",
"modules/nf-core/mafft/guidetree/tests/main.nf.test.snap",
"tests/modules/nf-core/epang/split/main.nf",
];
const result_2 = ["mafft/align", "mafft/guidetree", "epang/split"];

console.assert(JSON.stringify(get_module_names(test_case_1)) === JSON.stringify(result_1), "Test case 1 failed");
console.assert(JSON.stringify(get_module_names(test_case_2)) === JSON.stringify(result_2), "Test case 2 failed");

console.log("All tests passed!");
}

// Handle different execution contexts
if (require.main === module) {
// Script was run directly (node get_module_path.js)
runTests();
} else {
// Script was imported/required
module.exports = run;
}
27 changes: 14 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,31 @@ jobs:
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: module_names
with:
result-encoding: string
script: |
return [...new Set(${{ steps.filter.outputs.modules_files }}
.map(path => path
.replace('modules/nf-core/', '')
.split('/')
.slice(0, 2)
.filter(x => !x.startsWith('main.nf') && x !== 'tests' && x !== 'meta.yml' && x !== 'environment.yml')
.join('/'))
)
];
const script = require('./.github/scripts/get_module_path.js')
console.log('Raw modules_files:', '${{ steps.filter.outputs.modules_files }}')
const files = JSON.parse('${{ steps.filter.outputs.modules_files }}')
console.log('Parsed files:', files)
const result = script({ github, context: { payload: { inputs: { files } } } })
console.log('Result:', result)
return result

- name: debug
run: |
echo ${{ steps.filter.outputs.modules_files }}
echo ${{ steps.module_names.outputs.result }}
echo "Modules files: ${{ steps.filter.outputs.modules_files }}"
echo "Module names: ${{ fromJson(steps.module_names.outputs.result) }}"
echo "Raw module names output: ${{ steps.module_names.outputs.result }}"

nf-core-lint-modules:
runs-on: ${{ github.event.inputs.runners || 'self-hosted' }}
name: nf-core lint modules
needs: nf-core-changes
if: ${{ (needs.nf-core-changes.outputs.modules == 'true') }}
if: ${{ needs.nf-core-changes.outputs.modules_files != '[]' && needs.nf-core-changes.outputs.modules_files != '' }}
strategy:
fail-fast: false
matrix:
module: "${{ fromJson(needs.nf-core-changes.outputs.modules_files) }}"
module: ${{ fromJson(needs.nf-core-changes.outputs.modules_files || '[]') }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

Expand Down
2 changes: 1 addition & 1 deletion modules/nf-core/upd/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
process {
ext.args = { "--proband earlycasualcaiman --father hugelymodelbat --mother slowlycivilbuck --af-tag AF regions" }
ext.args = { "--proband earlycasualcaiman --father hugelymodelbat --mother slowlycivilbuck --af-tag AF regions" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this ended up in the PR, but otherwise that looks good to me.

}
Loading