Skip to content

Commit 3950431

Browse files
committed
Normalize CRLF in the gate guard parsing; cover it with a test
1 parent 26a4056 commit 3950431

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

bin/check-ci-gates.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {MANIFEST_JOB_IDS} from './ci-gates.js'
1313
// (up to the next top-level key) and allow a trailing comment after the id. Job
1414
// keys are always bare (their mapping is on following lines), so nested keys —
1515
// indented deeper than 2 spaces — and `key: value` anchors are naturally excluded.
16-
export function parseJobIds(workflow) {
16+
export function parseJobIds(workflowText) {
17+
const workflow = workflowText.replace(/\r\n/g, '\n')
1718
const jobsAt = workflow.search(/^jobs:/m)
1819
if (jobsAt === -1) return []
1920
const afterHeader = workflow.slice(jobsAt).replace(/^jobs:.*\n/, '')
@@ -24,9 +25,13 @@ export function parseJobIds(workflow) {
2425

2526
// Pure and testable: given the two YAML texts and the manifest job ids, return the
2627
// list of human-readable problems (empty when everything is in sync).
27-
export function findProblems({workflow, devYml, manifestJobIds}) {
28+
export function findProblems({workflow: workflowText, devYml: devYmlText, manifestJobIds}) {
2829
const problems = []
2930

31+
// Normalize line endings so the parsing below is robust to CRLF working trees.
32+
const workflow = workflowText.replace(/\r\n/g, '\n')
33+
const devYml = devYmlText.replace(/\r\n/g, '\n')
34+
3035
const workflowJobIds = parseJobIds(workflow)
3136
const manifestSet = new Set(manifestJobIds)
3237
const workflowSet = new Set(workflowJobIds)

bin/check-ci-gates.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ test('parseJobIds tolerates comments and ignores non-job lines', () => {
5252
test('parseJobIds returns empty when there is no jobs block', () => {
5353
assert.deepEqual(parseJobIds('name: t\non: push\n'), [])
5454
})
55+
56+
test('CRLF line endings are handled', () => {
57+
const wf = workflow(['a', 'b']).replace(/\n/g, '\r\n')
58+
assert.deepEqual(parseJobIds(wf), ['a', 'b'])
59+
const {problems} = findProblems({workflow: wf, devYml: devYml().replace(/\n/g, '\r\n'), manifestJobIds: ['a', 'b']})
60+
assert.deepEqual(problems, [])
61+
})

0 commit comments

Comments
 (0)