Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7575e5b
fix(ci): improve changed file detection in linter script
shivanee-p Jul 24, 2026
00944ff
fix(ci): use explicit refspec when fetching base branch
shivanee-p Jul 24, 2026
70084ee
fix(linter): use namespace import for typescript ESM compatibility
shivanee-p Jul 27, 2026
ba23899
fix(linter): make changed file resolution hermetic and improve base r…
shivanee-p Jul 30, 2026
d795744
fix(linter): use default import for typescript in ESM module
shivanee-p Jul 30, 2026
290434b
fix(linter): check remote main refs before HEAD~1 when on main branch
shivanee-p Jul 30, 2026
b0accfe
refactor(linter): consolidate getChangedFiles reference resolution logic
shivanee-p Jul 30, 2026
e2c5ef3
chore(linter): clean up comments and format branch check in linter.mjs
shivanee-p Jul 30, 2026
49c80ce
fix(linter): resolve origin/baseRef in CI for actions/checkout compat…
shivanee-p Jul 30, 2026
5b42816
feat(linter): add --strict mode changed file detection
shivanee-p Jul 31, 2026
3db57ca
fix(ci): fetch base branch in presubmit workflow for strict linter diff
shivanee-p Jul 31, 2026
da4b704
refactor(linter): use environment variables for strict mode diff logic
shivanee-p Jul 31, 2026
28667f2
style(linter): clean up unused space in getChangedFiles()
shivanee-p Jul 31, 2026
409044a
refactor(linter): simplify getChangedFiles for default non-strict mode
shivanee-p Jul 31, 2026
fd811c9
refactor(linter): inline process.env.GIT_DIFF_ARG directly in getChan…
shivanee-p Jul 31, 2026
00807c3
refactor(linter): use git diff ref...HEAD directly in getChangedFiles
shivanee-p Jul 31, 2026
384a079
fix(linter): align strict mode CI diff logic with PR #9021
shivanee-p Aug 3, 2026
3c3bd25
revert(linter): restore getChangedFiles implementation from PR #8968
shivanee-p Aug 3, 2026
585034e
refactor(linter): clean up strict mode handling and flags
shivanee-p Aug 3, 2026
21bad2f
style(linter): remove empty line in getChangedFiles
shivanee-p Aug 3, 2026
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
6 changes: 4 additions & 2 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ jobs:
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 300
fetch-depth: 2
persist-credentials: false
- name: Use Node.js 24
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: 24
- run: npm install
- run: npm run lint
- run: node ./bin/linter.mjs --strict
name: Run monorepo linter
env:
GIT_DIFF_ARG: "HEAD^1"
52 changes: 49 additions & 3 deletions bin/linter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ const tsconfigCache = new Map();
// --- Main Runner (Entry Point) ---
async function run() {
try {
const changedTsFiles = getChangedFiles();
const isStrict = Boolean(process.argv.includes('--strict'));
let changedTsFiles;
if (isStrict) {
changedTsFiles = getChangedFilesStrict();
} else {
changedTsFiles = getChangedFiles();
}

if (changedTsFiles.length === 0) {
console.log('No TypeScript files changed. Skipping checks.');
Expand Down Expand Up @@ -63,16 +69,56 @@ function runGit(args, options = {}) {
});
}

function getChangedFilesStrict() {
const gitDiffArg = process.env.GIT_DIFF_ARG;

if (!gitDiffArg) {
throw new Error(
'Strict mode is enabled, but GIT_DIFF_ARG environment variable or --git-diff-arg flag was not provided. ' +
'Please set the GIT_DIFF_ARG environment variable or provide --git-diff-arg <arg>.'
);
}

console.log(`Strict mode enabled. Comparing using GIT_DIFF_ARG: ${gitDiffArg}`);

const args = gitDiffArg.trim().split(/\s+/);

try {
const output = runGit([
'diff',
'--name-only',
'--diff-filter=ACMRT',
...args,
'--',
'*.ts',
]);
return output
.split('\n')
.map(f => f.trim())
.filter(f => f.length > 0 && existsSync(f));
} catch (err) {
if (err.status !== 1) {
throw new Error(
`Strict mode error: git diff --quiet ${gitDiffArg} failed with exit code ${err.status}.\n` +
`Ensure that the git reference '${gitDiffArg}' exists locally and that you have fetched the required commits/branches.\n` +
`Details: ${String(err.stderr || err.message || '').trim()}`
);
}
}
}

/**
* Returns a list of changed TypeScript files comparing against target branches/references.
*/
function getChangedFiles() {
Comment thread
shivanee-p marked this conversation as resolved.
const base = process.env.GITHUB_BASE_REF || 'main';
const refsToTry = [
`origin/${base}...HEAD`,
`${base}...HEAD`,
`upstream/${base}...HEAD`,
`origin/${base}`,
base,
`upstream/${base}`,
`origin/${base}`,
'FETCH_HEAD',
'HEAD~1',
'HEAD^',
];
Expand Down
Loading