|
| 1 | +name: Nextflow Lint |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + lint: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - name: Install Nextflow |
| 14 | + uses: nf-core/setup-nextflow@v2 |
| 15 | + |
| 16 | + - name: Run Nextflow lint |
| 17 | + run: | |
| 18 | + mkdir -p lint-results |
| 19 | + # TODO: Remove '|| true' to fail CI when linting errors are fixed |
| 20 | + nextflow lint **/solutions/* -o json > lint-results/lint-output.json 2>&1 || true |
| 21 | +
|
| 22 | + - name: Generate markdown report |
| 23 | + if: always() |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const fs = require('fs'); |
| 28 | + const lintOutput = JSON.parse(fs.readFileSync('lint-results/lint-output.json', 'utf8')); |
| 29 | + const { summary, errors, warnings } = lintOutput; |
| 30 | + const sha = context.sha; |
| 31 | + const repo = `${context.repo.owner}/${context.repo.repo}`; |
| 32 | +
|
| 33 | + // Handle warnings array (added in future Nextflow version) |
| 34 | + const warningsArray = warnings || []; |
| 35 | + const warningCount = summary.warnings || 0; |
| 36 | +
|
| 37 | + let markdown = '**Nextflow linting complete!**\n\n'; |
| 38 | +
|
| 39 | + const hasIssues = summary.errors > 0 || warningCount > 0; |
| 40 | +
|
| 41 | + if (!hasIssues) { |
| 42 | + markdown += `✅ ${summary.filesWithoutErrors} files had no errors\n`; |
| 43 | + } else { |
| 44 | + if (summary.errors > 0) { |
| 45 | + markdown += `❌ ${summary.filesWithErrors} files had ${summary.errors} errors\n`; |
| 46 | + } |
| 47 | + if (warningCount > 0) { |
| 48 | + const filesWithWarnings = summary.filesWithWarnings || 'N/A'; |
| 49 | + markdown += `⚠️ ${filesWithWarnings} files had ${warningCount} warnings\n`; |
| 50 | + } |
| 51 | + markdown += `✅ ${summary.filesWithoutErrors} files had no errors\n\n`; |
| 52 | +
|
| 53 | + // Combine errors and warnings with type labels |
| 54 | + const allIssues = [ |
| 55 | + ...errors.map(e => ({ ...e, type: 'Error' })), |
| 56 | + ...warningsArray.map(w => ({ ...w, type: 'Warning' })) |
| 57 | + ]; |
| 58 | +
|
| 59 | + // Group by file |
| 60 | + const grouped = {}; |
| 61 | + for (const issue of allIssues) { |
| 62 | + if (!grouped[issue.filename]) { |
| 63 | + grouped[issue.filename] = []; |
| 64 | + } |
| 65 | + grouped[issue.filename].push(issue); |
| 66 | + } |
| 67 | +
|
| 68 | + // Build table rows |
| 69 | + const rows = []; |
| 70 | + for (const [filename, fileIssues] of Object.entries(grouped).sort()) { |
| 71 | + for (const issue of fileIssues) { |
| 72 | + const location = `${issue.startLine}:${issue.startColumn}`; |
| 73 | + const link = `[${filename}:${location}](https://github.com/${repo}/blob/${sha}/${filename}#L${issue.startLine})`; |
| 74 | + rows.push(`| ${issue.type} | ${link} | ${issue.message} |`); |
| 75 | + } |
| 76 | + } |
| 77 | +
|
| 78 | + const totalIssues = summary.errors + warningCount; |
| 79 | + markdown += `<sup>💡 Tip: Click filename locations to go directly to that code.</sup>\n\n`; |
| 80 | + markdown += `<details>\n<summary>View all ${totalIssues} issues</summary>\n\n`; |
| 81 | + markdown += `| Type | Location | Message |\n|------|----------|---------|\n`; |
| 82 | + markdown += rows.join('\n'); |
| 83 | + markdown += `\n\n</details>\n`; |
| 84 | + } |
| 85 | +
|
| 86 | + // Write to file |
| 87 | + fs.writeFileSync('lint-results/report.md', markdown); |
| 88 | +
|
| 89 | + // Add to job summary |
| 90 | + await core.summary |
| 91 | + .addRaw(markdown) |
| 92 | + .write(); |
| 93 | +
|
| 94 | + - name: Save PR info |
| 95 | + if: always() && github.event_name == 'pull_request' |
| 96 | + run: | |
| 97 | + echo "${{ github.event.pull_request.number }}" > lint-results/pr-number.txt |
| 98 | + echo "${{ github.sha }}" > lint-results/head-sha.txt |
| 99 | +
|
| 100 | + - name: Upload lint results |
| 101 | + if: always() && github.event_name == 'pull_request' |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: lint-results |
| 105 | + path: lint-results/ |
| 106 | + retention-days: 1 |
0 commit comments