diff --git a/.github/workflows/pr_detector_labels.yaml b/.github/workflows/pr_detector_labels.yaml index 1a3203dfb..06261dffb 100644 --- a/.github/workflows/pr_detector_labels.yaml +++ b/.github/workflows/pr_detector_labels.yaml @@ -103,9 +103,15 @@ jobs: /* * -------------------------------------------------- - * 2. Detect detector from detector-server folders + * 2. Detect detector from changed files * -------------------------------------------------- * + * We inspect each file once and short-circuit as soon + * as a detector-server folder confirms a label. That + * avoids scanning the same detector folder again and + * avoids checking the rest of the file for unrelated + * detector names. + * * Examples: * * slsDetectorServers/eigerDetectorServer/... @@ -116,45 +122,49 @@ jobs: * ↓ * Xilinx_ctb */ + const ignoredDetectorServerFolders = new Set(); + for (const file of files) { - const match = file.filename.match( + const serverMatch = file.filename.match( /^slsDetectorServers\/([^/]+)DetectorServer\// ); - if (!match) { - continue; + if (serverMatch) { + const detectorFolder = serverMatch[0]; + + // Skip all later files under a detected detector folder. + if (ignoredDetectorServerFolders.has(detectorFolder)) { + core.info( + `Skipping file in ignored detector-server folder: ${file.filename}` + ); + continue; + } + + const detectorName = serverMatch[1]; + + /* + * Remove "DetectorServer" and capitalize + * the first character. + */ + const detector = + detectorName.charAt(0).toUpperCase() + + detectorName.slice(1); + + if (detectorLabels.includes(detector)) { + detectedDetectors.add(detector); + + core.info( + `Detected ${detector} from detector-server path: ${file.filename}` + ); + + // Once a detector is confirmed from the server folder, + // do not inspect this file or the rest of that folder. + ignoredDetectorServerFolders.add(detectorFolder); + continue; + } } - const detectorName = match[1]; - - /* - * Remove "DetectorServer" and capitalize - * the first character. - */ - const detector = - detectorName.charAt(0).toUpperCase() + - detectorName.slice(1); - - if (detectorLabels.includes(detector)) { - detectedDetectors.add(detector); - - core.info( - `Detected ${detector} from detector-server path: ${file.filename}` - ); - } - } - - /* - * -------------------------------------------------- - * 3. Detect detector from changed code - * -------------------------------------------------- - * - * Only the PR patch is searched. - * - * Therefore, text that already existed elsewhere - * in an unchanged file does not trigger a label. - */ - for (const file of files) { + // Only inspect the PR patch, never the full file. if (!file.patch) { continue; } @@ -177,7 +187,7 @@ jobs: /* * -------------------------------------------------- - * 4. Detect detector from PR title/description + * 3. Detect detector from PR title/description * -------------------------------------------------- */ diff --git a/.github/workflows/pr_edit_trigger.yaml b/.github/workflows/pr_edit_trigger.yaml index 57c8449eb..389bf5ce2 100644 --- a/.github/workflows/pr_edit_trigger.yaml +++ b/.github/workflows/pr_edit_trigger.yaml @@ -36,7 +36,7 @@ jobs: * If triggered by label change, ignore unrelated labels. */ const action = context.payload.action; - + if (action === 'labeled' || action === 'unlabeled') { const changedLabel = context.payload.label?.name; core.info( @@ -49,6 +49,7 @@ jobs: 'Infrastructure', 'Breaking API' ]; + if (!relevantLabels.includes(changedLabel)) { requireValidation = false; } @@ -59,12 +60,9 @@ jobs: ]; if (fileLabels.includes(changedLabel)) { fileLabelChange = true; - } + } } - /* - * Set workflow outputs. - */ core.setOutput( 'require_validation', requireValidation.toString() @@ -74,9 +72,6 @@ jobs: fileLabelChange.toString() ); - /* - * Log what will run. - */ if (requireValidation) { core.info('PR type validation required.'); } else { @@ -86,7 +81,7 @@ jobs: core.info('File version label change detected.'); } else { core.info('No file version label change detected.'); - } + } validate-pr-type: needs: check-pr-trigger @@ -125,4 +120,3 @@ jobs: permissions: pull-requests: write contents: read - diff --git a/.github/workflows/pr_synchronize_trigger.yaml b/.github/workflows/pr_synchronize_trigger.yaml index e0e29b47a..7ae240a2a 100644 --- a/.github/workflows/pr_synchronize_trigger.yaml +++ b/.github/workflows/pr_synchronize_trigger.yaml @@ -1,4 +1,4 @@ -# This workflow is triggered when code is pushed to a pull request. It runs the reusable detector label workflow. +# This workflow is triggered when code is pushed to a pull request. It runs the reusable detector label workflow Nd the file version workflow in parallel. name: PR Synchronize Trigger @@ -26,5 +26,4 @@ jobs: pr_number: ${{ github.event.pull_request.number }} permissions: pull-requests: write - contents: read - + contents: read \ No newline at end of file