Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): record filter-key flips in the paths-filter shadow (#91696)

Raúl Negrón-Oteroafcc607f1195
diff --git a/.depot/actions/paths-filter/README.md b/.depot/actions/paths-filter/README.md
index cb2b746d89a6..81e8ff92a1c3 100644
--- a/.depot/actions/paths-filter/README.md
+++ b/.depot/actions/paths-filter/README.md
@@ -81,6 +81,10 @@ Without the variable the action does no extra work. Set it in one workflow that
every pull request; that keeps the merge-ref fetch off the critical path of the other
gating jobs. This is temporary, and goes away with the decision it exists to inform.
+The event carries the differing paths and, in `selection_changed` and `keys_lost`, which
+filter keys answer differently on the two lists. The keys are what gate a job, so they are
+what the decision reads; the paths are there to explain a flip.
+
## Rebuilding after source changes
The action runs the committed `dist/index.js` bundle. After editing anything under `src/`,
diff --git a/.depot/actions/paths-filter/__tests__/shadow.test.ts b/.depot/actions/paths-filter/__tests__/shadow.test.ts
index 257a62d706fe..367fff5b7e37 100644
--- a/.depot/actions/paths-filter/__tests__/shadow.test.ts
+++ b/.depot/actions/paths-filter/__tests__/shadow.test.ts
@@ -1,7 +1,8 @@
import {PullRequest} from '@octokit/webhooks-types'
-import {ChangeStatus} from '../src/file'
-import {compareWithMergeCommit} from '../src/shadow'
+import {ChangeStatus, File} from '../src/file'
+import {Filter} from '../src/filter'
+import {ShadowInput, compareWithMergeCommit} from '../src/shadow'
const cp = jest.requireMock('child_process') as {execFile: jest.Mock}
@@ -22,6 +23,26 @@ type ExecFileArgs = [
const pullRequest = {number: 42, head: {sha: HEAD}} as PullRequest
+const filter = new Filter(`
+backend:
+ - 'posthog/**'
+frontend:
+ - 'frontend/**'
+`)
+
+// The action matches the API list once in `run()` and hands the result to the shadow, so
+// a test builds the same pairing here.
+function input(withFilter: Filter, apiFiles: File[]): ShadowInput {
+ return {
+ filter: withFilter,
+ apiFiles,
+ apiResults: withFilter.match(apiFiles),
+ apiRows: apiFiles.length,
+ apiTruncated: false,
+ pr: pullRequest
+ }
+}
+
function stubGit(...stdouts: string[]): void {
for (const stdout of stdouts) {
cp.execFile.mockImplementationOnce((...args: ExecFileArgs) => args[3](null, stdout, ''))
@@ -40,12 +61,13 @@ describe('shadow merge-commit comparison', () => {
cp.execFile.mockReset()
})
- // A git call that forgets the scratch dir runs against the job workspace, where a
- // --depth or --filter fetch drops the schema cache of every later step in the job.
+ // A git call against the job workspace drops the schema cache of every later step.
test('never runs git against the job workspace', async () => {
- stubGit('', '', HEAD, 'a.ts\0')
+ stubGit('', '', HEAD, 'M\0posthog/a.py\0')
- const result = await compareWithMergeCommit([{filename: 'a.ts', status: ChangeStatus.Modified}], pullRequest)
+ const result = await compareWithMergeCommit(
+ input(filter, [{filename: 'posthog/a.py', status: ChangeStatus.Modified}])
+ )
expect(result.verdict).toBe('match')
expect(argvOf(0)).toContain(GIT_DIR)
@@ -54,41 +76,39 @@ describe('shadow merge-commit comparison', () => {
}
})
- // Losing this guard scores a merge ref from an earlier push as this pull request's
- // changes, which fills the measurement with mismatches that mean nothing.
+ // Without this guard an earlier push's merge ref reads as this pull request's changes.
test('refuses a stale merge ref instead of comparing against it', async () => {
stubGit('', '', OTHER_SHA)
- const result = await compareWithMergeCommit([{filename: 'a.ts', status: ChangeStatus.Modified}], pullRequest)
+ const result = await compareWithMergeCommit(
+ input(filter, [{filename: 'posthog/a.py', status: ChangeStatus.Modified}])
+ )
expect(result.verdict).toBe('unavailable')
expect(result.reason).toBe('stale-merge-ref')
})
- // Losing --no-renames reports one path where the API path reports two, so every
- // rename reads as a mismatch.
+ // Without --no-renames every rename reads as a mismatch.
test('matches a rename that the API reported as two entries', async () => {
- stubGit('', '', HEAD, 'old.ts\0new.ts\0')
+ stubGit('', '', HEAD, 'D\0posthog/old.py\0A\0posthog/new.py\0')
const result = await compareWithMergeCommit(
- [
- {filename: 'new.ts', status: ChangeStatus.Added},
- {filename: 'old.ts', status: ChangeStatus.Deleted}
- ],
- pullRequest
+ input(filter, [
+ {filename: 'posthog/new.py', status: ChangeStatus.Added},
+ {filename: 'posthog/old.py', status: ChangeStatus.Deleted}
+ ])
)
expect(result.verdict).toBe('match')
expect(cp.execFile.mock.calls.map(c => c[1])).toContainEqual(expect.arrayContaining(['--no-renames']))
})
- // An exec with no handle on the child leaves the fetch running after the budget gives
- // up, and the action's process stays open until git exits.
+ // Without a handle on the child, an abandoned fetch holds the action open until git exits.
test('stops git when the budget expires', async () => {
cp.execFile.mockImplementation(() => undefined)
jest.useFakeTimers()
- const pending = compareWithMergeCommit([], pullRequest)
+ const pending = compareWithMergeCommit(input(filter, []))
await jest.advanceTimersByTimeAsync(PAST_ANY_BUDGET_MS)
const result = await pending
@@ -98,4 +118,44 @@ describe('shadow merge-commit comparison', () => {
expect(options.signal.aborted).toBe(true)
jest.useRealTimers()
})
+
+ // Comparing the file lists instead of the keys reports every dropped path as consequential.
+ test.each([
+ ['the dropped path is the only one holding a key', 'M\0frontend/b.ts\0', ['backend']],
+ ['a surviving path holds the same key', 'M\0posthog/b.py\0M\0frontend/b.ts\0', []]
+ ])('reports keys lost when %s', async (_case, diff, keysLost) => {
+ stubGit('', '', HEAD, diff)
+
+ const result = await compareWithMergeCommit(
+ input(filter, [
+ {filename: 'posthog/a.py', status: ChangeStatus.Modified},
+ {filename: 'posthog/b.py', status: ChangeStatus.Modified},
+ {filename: 'frontend/b.ts', status: ChangeStatus.Modified}
+ ])
+ )
+
+ expect(result.verdict).toBe('mismatch')
+ expect(result.keysLost).toEqual(keysLost)
+ expect(result.keysGained).toEqual([])
+ })
+
+ // Reading the -z fields in the wrong order turns every path into a status letter.
+ test('carries each file status through to a status-scoped rule', async () => {
+ const scoped = new Filter(`
+added_only:
+ - added: 'posthog/**'
+`)
+ stubGit('', '', HEAD, 'A\0posthog/new.py\0D\0posthog/gone.py\0')
+
+ const result = await compareWithMergeCommit(
+ input(scoped, [
+ {filename: 'posthog/new.py', status: ChangeStatus.Added},
+ {filename: 'posthog/gone.py', status: ChangeStatus.Deleted}
+ ])
+ )
+
+ expect(result.verdict).toBe('match')
+ expect(result.keysLost).toEqual([])
+ expect(result.keysGained).toEqual([])
+ })
})
diff --git a/.depot/actions/paths-filter/dist/index.js b/.depot/actions/paths-filter/dist/index.js
index 1115cb186a4f..7debf5e327a7 100644
--- a/.depot/actions/paths-filter/dist/index.js
+++ b/.depot/actions/paths-filter/dist/index.js
@@ -42189,6 +42189,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Filter = void 0;
+exports.firedKeys = firedKeys;
const jsyaml = __importStar(__nccwpck_require__(4281));
const picomatch_1 = __importDefault(__nccwpck_require__(4006));
// Minimatch options used in all matchers
@@ -42203,6 +42204,11 @@ function isNegatedPattern(pattern) {
function positivePattern(pattern) {
return isNegatedPattern(pattern) ? pattern.slice(1) : pattern;
}
+// A key gates a job on whether any file matched it, so its answer is `length > 0` and
+// nothing finer. Both the action's outputs and the shadow comparison read it through here.
+function firedKeys(results) {
+ return new Set(Object.keys(results).filter(key => results[key].length > 0));
+}
class Filter {
// Creates instance of Filter and load rules from YAML if it's provided
constructor(yaml) {
@@ -42708,10 +42714,13 @@ async function run() {
return;
}
const filter = new filter_1.Filter(filtersYaml);
- const files = await getChangedFiles(token, base, ref, initialFetchDepth);
+ const { files, api } = await getChangedFiles(token, base, ref, initialFetchDepth);
core.info(`Detected ${files.length} changed files`);
const results = filter.match(files);
exportResults(results, listFiles);
+ if (api) {
+ await shadow.report({ filter, apiFiles: files, apiResults: results, ...api });
+ }
}
catch (error) {
core.setFailed(getErrorMessage(error));
@@ -42737,7 +42746,7 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
if (ref) {
core.warning(`'ref' input parameter is ignored when 'base' is set to HEAD`);
}
- return await git.getChangesOnHead();
+ return { files: await git.getChangesOnHead() };
}
switch (github.context.eventName) {
// To keep backward compatibility, commits in GitHub pull request event
@@ -42754,9 +42763,8 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
}
const pr = github.context.payload.pull_request;
if (token) {
- const apiFiles = await getChangedFilesFromApi(token, pr);
- await shadow.report(apiFiles, pr);
- return apiFiles;
+ const { files, apiRows, apiTruncated } = await getChangedFilesFromApi(token, pr);
+ return { files, api: { apiRows, apiTruncated, pr } };
}
if (github.context.eventName === 'pull_request_target') {
// pull_request_target is executed in context of base branch and GITHUB_SHA points to last commit in base branch
@@ -42768,10 +42776,10 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
const baseSha = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base.sha;
const defaultBranch = (_b = github.context.payload.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
const currentRef = await git.getCurrentRef();
- return await git.getChanges(base || baseSha || defaultBranch, currentRef);
+ return { files: await git.getChanges(base || baseSha || defaultBranch, currentRef) };
}
}
- return getChangedFilesFromGit(base, ref, initialFetchDepth);
+ return { files: await getChangedFilesFromGit(base, ref, initialFetchDepth) };
}
async function getChangedFilesFromGit(base, head, initialFetchDepth) {
var _a;
@@ -42820,13 +42828,17 @@ async function getChangedFilesFromGit(base, head, initialFetchDepth) {
core.info(`Changes will be detected between ${base} and ${head}`);
return await git.getChangesSinceMergeBase(base, head, initialFetchDepth);
}
+// The API truncates at this many rows and says nothing when it does.
+const API_FILE_CAP = 3000;
// Uses github REST api to get list of files changed in PR
+// Truncation is judged on API rows, not on `files`, which expands a rename into two.
async function getChangedFilesFromApi(token, pullRequest) {
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`);
try {
const client = github.getOctokit(token);
const per_page = 100;
const files = [];
+ let apiRows = 0;
core.info(`Invoking listFiles(pull_number: ${pullRequest.number}, per_page: ${per_page})`);
for await (const response of client.paginate.iterator(client.rest.pulls.listFiles.endpoint.merge({
owner: github.context.repo.owner,
@@ -42839,6 +42851,7 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
core.info(`Received ${response.data.length} items`);
for (const row of response.data) {
+ apiRows++;
core.info(`[${row.status}] ${row.filename}`);
// There's no obvious use-case for detection of renames
// Therefore we treat it as if rename detection in git diff was turned off.
@@ -42864,7 +42877,7 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
}
}
- return files;
+ return { files, apiRows, apiTruncated: apiRows >= API_FILE_CAP };
}
finally {
core.endGroup();
@@ -42872,12 +42885,11 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
function exportResults(results, format) {
core.info('Results:');
- const changes = [];
+ const fired = (0, filter_1.firedKeys)(results);
for (const [key, files] of Object.entries(results)) {
- const value = files.length > 0;
+ const value = fired.has(key);
core.startGroup(`Filter ${key} = ${value}`);
- if (files.length > 0) {
- changes.push(key);
+ if (value) {
core.info('Matching files:');
for (const file of files) {
core.info(`${file.filename} [${file.status}]`);
@@ -42895,7 +42907,7 @@ function exportResults(results, format) {
core.endGroup();
}
if (results['changes'] === undefined) {
- const changesJson = JSON.stringify(changes);
+ const changesJson = JSON.stringify([...fired]);
core.info(`Changes output set to ${changesJson}`);
core.setOutput('changes', changesJson);
}
@@ -42976,35 +42988,24 @@ const child_process_1 = __nccwpck_require__(5317);
const os = __importStar(__nccwpck_require__(857));
const path = __importStar(__nccwpck_require__(6928));
const core = __importStar(__nccwpck_require__(7484));
-// Compares the API's changed-file list against the same list derived locally from
-// the pull request's merge commit, and reports disagreement without acting on it.
-// The API result stays authoritative, so a wrong local answer can only produce a
-// log line. Removing the API call later is only safe once this has run quiet
-// across the shapes no offline sample can reach: very large diffs, and ones GitHub
-// has not finished computing a merge ref for.
-//
-// Detecting changes from `base.sha..HEAD` instead reports every commit the branch
-// picked up when the base was merged into it as the pull request's own work, which
-// is wrong by thousands of files on a branch that has taken master in. The merge
-// commit's first parent is the base GitHub actually merged against, so
-// `HEAD^1..HEAD` is the pull request's own changes and matches the API.
+const filter_1 = __nccwpck_require__(9037);
+const git_1 = __nccwpck_require__(1243);
+// Compares the API's changed-file list against the same list derived from the pull
+// request's merge commit, and reports disagreement without acting on it. The API
+// result stays authoritative, so a wrong local answer can only produce a log line.
const MERGE_REF_FETCH_DEPTH = 2;
const POSTHOG_HOST = 'https://us.i.posthog.com';
const EVENT_NAME = 'paths_filter_shadow_compared';
// A change-detection job is on the critical path of every workflow, so the comparison
-// and the capture that follows it share one wall-clock budget, and give up rather than
-// holding the job to its timeout-minutes. The git-level low-speed settings cover a
-// stalled transfer; the budget covers everything else.
+// and its capture share one wall-clock budget rather than holding the job to its
+// timeout-minutes.
const BUDGET_MS = 20000;
const CAPTURE_FLOOR_MS = 500;
const LIST_CAP = 50;
-// A queue branch carries the cumulative batch diff, so the path list can be far larger
-// than a human pull request's. execFile's 1 MB default would fail those as a diff error,
-// which drops the population the comparison most needs to measure.
+// A queue branch carries the cumulative batch diff, which execFile's 1 MB default would
+// fail as a diff error.
const MAX_GIT_OUTPUT_BYTES = 64 * 1024 * 1024;
const DETAIL_CAP = 200;
-// The API caps pulls/{n}/files at this many entries and says nothing when it truncates.
-const API_FILE_CAP = 3000;
class Unavailable extends Error {
constructor(reason, detail) {
super(`${reason}: ${detail}`);
@@ -43012,20 +43013,15 @@ class Unavailable extends Error {
this.detail = detail;
}
}
-// Every git call that reads or writes history names the scratch repository. `--depth`
-// and `--filter` rewrite `.git/shallow` and the promisor config of whatever repository
-// they run in, and steps later in the same job read history from the workspace checkout:
-// ci-dagster and ci-e2e-playwright resolve `git merge-base HEAD^2 origin/<base>` after
-// this action returns, and an empty merge base there silently drops their schema cache.
+// `--depth` and `--filter` rewrite `.git/shallow` and the promisor config of whatever
+// repository they run in, so every call names the scratch repository. ci-dagster and
+// ci-e2e-playwright read history from the workspace checkout after this action returns.
async function git(gitDir, args, signal) {
return run(['--git-dir', gitDir, ...args], signal);
}
-// The signal is what makes the wall-clock budget real. `@actions/exec` gives no handle
-// on the child process, so a fetch the budget gave up on keeps running and holds the
-// action's process open until it finishes, past the budget it was supposed to obey.
-//
-// stdout is returned raw. A caller that reads a path list must not trim it, because a
-// tracked path can begin with a space, and that path sorts first in the -z output.
+// execFile rather than `@actions/exec`, which gives no handle on the child process, so a
+// fetch the budget gave up on would hold the action open until it finished. stdout is
+// returned raw because a tracked path can begin with a space.
async function run(args, signal) {
return new Promise(resolve => {
(0, child_process_1.execFile)('git', args, { signal, maxBuffer: MAX_GIT_OUTPUT_BYTES }, (error, stdout, stderr) => {
@@ -43039,6 +43035,9 @@ function firstLine(stderr) {
function messageOf(error) {
return error instanceof Error ? error.message : String(error);
}
+function missing(from, against) {
+ return [...from].filter(key => !against.has(key)).sort();
+}
async function scratchRepo(signal) {
const gitDir = path.join(process.env.RUNNER_TEMP || os.tmpdir(), 'paths-filter-shadow.git');
const init = await run(['init', '--bare', '--quiet', gitDir], signal);
@@ -43047,9 +43046,8 @@ async function scratchRepo(signal) {
}
return gitDir;
}
-// The workspace remote carries no credentials of its own: actions/checkout keeps the
-// token in an http.extraheader the scratch repository does not inherit. A private
-// remote therefore reports unavailable rather than comparing against a partial fetch.
+// actions/checkout keeps the token in an http.extraheader the scratch repository does not
+// inherit, so a private remote reports unavailable rather than comparing a partial fetch.
function originUrl() {
const server = process.env.GITHUB_SERVER_URL;
const repo = process.env.GITHUB_REPOSITORY;
@@ -43058,9 +43056,6 @@ function originUrl() {
}
return `${server}/${repo}`;
}
-// The merge ref is not guaranteed to be present or current: GitHub recomputes it
-// asynchronously after a push. Requiring the second parent to equal the head SHA
-// rejects a stale ref rather than reading it as this pull request's changes.
async function localChangedFiles(pr, signal) {
const gitDir = await scratchRepo(signal);
const fetched = await git(gitDir, [
@@ -43082,22 +43077,21 @@ async function localChangedFiles(pr, signal) {
if (head.code !== 0) {
throw new Unavailable('no-second-parent', firstLine(head.err));
}
+ // GitHub recomputes the merge ref asynchronously after a push, so a ref whose second
+ // parent is not the head SHA describes an earlier push.
const headSha = head.out.trim();
if (headSha !== pr.head.sha) {
throw new Unavailable('stale-merge-ref', `^2=${headSha.slice(0, 8)}, head=${pr.head.sha.slice(0, 8)}`);
}
- // --no-renames so a rename arrives as a delete plus an add, which is the shape
- // the API path builds by hand from `previous_filename`. -z because git quotes a
- // path holding a newline or a non-ASCII byte in the default format.
- const diff = await git(gitDir, ['diff', '--no-renames', '--name-only', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal);
+ // The same flags the action's own git path uses, so the comparison measures what
+ // dropping the API call would select. --no-renames matches the add-plus-delete shape
+ // the API path builds from `previous_filename`.
+ const diff = await git(gitDir, ['diff', '--no-renames', '--name-status', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal);
if (diff.code !== 0) {
throw new Unavailable('diff-failed', firstLine(diff.err));
}
- return diff.out.split('\0').filter(Boolean);
+ return (0, git_1.parseGitDiffOutput)(diff.out);
}
-// A queue branch can differ by thousands of paths, which is neither readable in a log
-// line nor worth carrying as an event property. The count answers how far apart the two
-// answers are, and the sample answers what kind of path is involved.
function difference(from, against) {
const sample = [];
let count = 0;
@@ -43112,9 +43106,12 @@ function difference(from, against) {
}
return { count, sample };
}
-function compare(api, local) {
+function compare(input, api, gitFiles) {
+ const local = new Set(gitFiles.map(f => f.filename));
const onlyInApi = difference(api, local);
const onlyInGit = difference(local, api);
+ const apiKeys = (0, filter_1.firedKeys)(input.apiResults);
+ const gitKeys = (0, filter_1.firedKeys)(input.filter.match(gitFiles));
return {
verdict: onlyInApi.count === 0 && onlyInGit.count === 0 ? 'match' : 'mismatch',
reason: null,
@@ -43122,7 +43119,9 @@ function compare(api, local) {
apiCount: api.size,
gitCount: local.size,
onlyInApi,
- onlyInGit
+ onlyInGit,
+ keysLost: missing(apiKeys, gitKeys),
+ keysGained: missing(gitKeys, apiKeys)
};
}
async function budgeted(work, ms) {
@@ -43136,11 +43135,11 @@ async function budgeted(work, ms) {
});
return Promise.race([work(controller.signal), expiry]).finally(() => clearTimeout(timer));
}
-async function compareWithMergeCommit(apiFiles, pr) {
- const api = new Set(apiFiles.map(f => f.filename));
+async function compareWithMergeCommit(input) {
+ const api = new Set(input.apiFiles.map(f => f.filename));
try {
- const gitFiles = await budgeted(async (signal) => localChangedFiles(pr, signal), BUDGET_MS);
- return compare(api, new Set(gitFiles));
+ const gitFiles = await budgeted(async (signal) => localChangedFiles(input.pr, signal), BUDGET_MS);
+ return compare(input, api, gitFiles);
}
catch (error) {
return {
@@ -43150,15 +43149,16 @@ async function compareWithMergeCommit(apiFiles, pr) {
apiCount: api.size,
gitCount: null,
onlyInApi: { count: 0, sample: [] },
- onlyInGit: { count: 0, sample: [] }
+ onlyInGit: { count: 0, sample: [] },
+ keysLost: [],
+ keysGained: []
};
}
}
-// Without this the only record of a divergence is a log line in one job of one run,
-// which is unreadable at the volume that makes the comparison worth running.
-async function capture(apiKey, result, pr, durationMs) {
+async function capture(apiKey, input, result, durationMs) {
var _a;
const repo = process.env.GITHUB_REPOSITORY || null;
+ const pr = input.pr;
const properties = {
repo,
verdict: result.verdict,
@@ -43170,18 +43170,18 @@ async function capture(apiKey, result, pr, durationMs) {
only_in_api_count: result.onlyInApi.count,
only_in_git: result.onlyInGit.sample,
only_in_git_count: result.onlyInGit.count,
- // pulls/{n}/files truncates silently, so record both sides of the tell: what the
- // API returned, and what the pull request payload says it should have been. The
- // count has to come from the payload, because `api_count` counts a rename twice:
- // the API path expands each renamed row into an add plus a delete.
- api_truncated: pr.changed_files >= API_FILE_CAP,
+ selection_changed: result.keysLost.length > 0 || result.keysGained.length > 0,
+ keys_lost: result.keysLost,
+ keys_gained: result.keysGained,
+ // `pr_changed_files` reads stale on a pull request whose base moved, so it is
+ // recorded beside the API's own row count rather than used as the truncation tell.
+ api_rows: input.apiRows,
+ api_truncated: input.apiTruncated,
pr_changed_files: pr.changed_files,
pr_number: pr.number,
head_sha: pr.head.sha,
head_ref: pr.head.ref,
base_ref: pr.base.ref,
- // Queue branches carry the cumulative batch diff and page far more than a human
- // pull request, so they are the population worth reading separately.
branch_class: pr.head.ref.startsWith('trunk-merge/') ? 'trunk-merge' : 'pull-request',
is_fork: ((_a = pr.head.repo) === null || _a === void 0 ? void 0 : _a.full_name) !== repo,
duration_ms: durationMs,
@@ -43199,7 +43199,6 @@ async function capture(apiKey, result, pr, durationMs) {
distinct_id: repo || 'paths-filter-shadow',
properties
}),
- // Whatever the comparison did not spend, so the step's ceiling stays the budget.
signal: AbortSignal.timeout(Math.max(CAPTURE_FLOOR_MS, BUDGET_MS - durationMs))
});
if (!res.ok) {
@@ -43212,18 +43211,15 @@ function summarize(result) {
}
if (result.verdict === 'mismatch') {
return (`MISMATCH api=${result.apiCount} git=${result.gitCount} ` +
- `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)}`);
+ `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)} ` +
+ `keysLost=${JSON.stringify(result.keysLost)} keysGained=${JSON.stringify(result.keysGained)}`);
}
return `match (${result.apiCount} files)`;
}
-// Never throws: the filter's real answer is already computed by the time this runs,
-// so nothing here is worth failing a CI job over.
-//
-// The token gates the comparison itself, not just the capture. Every workflow that
-// detects changes runs this action, so a comparison whose result cannot be recorded
-// is a merge-ref fetch on the critical path of a gate job in exchange for a log line
-// nobody reads. Fork pull requests get no secrets, so they take this path too.
-async function report(apiFiles, pr) {
+// Never throws: the filter's real answer is already computed by the time this runs. The
+// token gates the comparison itself, so a run that cannot record its result does not pay
+// for a merge-ref fetch. Fork pull requests get no secrets and take that path too.
+async function report(input) {
const apiKey = process.env.PATHS_FILTER_SHADOW_POSTHOG_TOKEN;
if (!apiKey) {
return;
@@ -43231,12 +43227,12 @@ async function report(apiFiles, pr) {
try {
core.startGroup('Shadow: merge-commit change detection');
const startedAt = Date.now();
- const result = await compareWithMergeCommit(apiFiles, pr);
+ const result = await compareWithMergeCommit(input);
const durationMs = Date.now() - startedAt;
- // core.info even for a mismatch: a warning becomes an annotation on the run summary
- // and the checks page, which reads as a problem with the pull request.
+ // core.info even for a mismatch, because a warning becomes an annotation on the
+ // checks page and reads as a problem with the pull request.
core.info(`shadow: ${summarize(result)} in ${durationMs}ms`);
- await capture(apiKey, result, pr, durationMs).catch(error => {
+ await capture(apiKey, input, result, durationMs).catch(error => {
core.info(`shadow: capture skipped (${messageOf(error)})`);
});
}
diff --git a/.depot/actions/paths-filter/src/filter.ts b/.depot/actions/paths-filter/src/filter.ts
index 2e100b834ecc..b29f3b5de6fd 100644
--- a/.depot/actions/paths-filter/src/filter.ts
+++ b/.depot/actions/paths-filter/src/filter.ts
@@ -38,6 +38,12 @@ export interface FilterResults {
[key: string]: File[]
}
+// A key gates a job on whether any file matched it, so its answer is `length > 0` and
+// nothing finer. Both the action's outputs and the shadow comparison read it through here.
+export function firedKeys(results: FilterResults): Set<string> {
+ return new Set(Object.keys(results).filter(key => results[key].length > 0))
+}
+
export class Filter {
rules: {[key: string]: FilterRuleItem[]} = {}
diff --git a/.depot/actions/paths-filter/src/main.ts b/.depot/actions/paths-filter/src/main.ts
index cec7f6628895..df01def7e538 100644
--- a/.depot/actions/paths-filter/src/main.ts
+++ b/.depot/actions/paths-filter/src/main.ts
@@ -4,7 +4,7 @@ import * as github from '@actions/github'
import {GetResponseDataTypeFromEndpointMethod} from '@octokit/types'
import {PullRequest, PushEvent} from '@octokit/webhooks-types'
-import {Filter, FilterResults} from './filter'
+import {Filter, FilterResults, firedKeys} from './filter'
import {File, ChangeStatus} from './file'
import * as git from './git'
import * as shadow from './shadow'
@@ -34,10 +34,13 @@ async function run(): Promise<void> {
}
const filter = new Filter(filtersYaml)
- const files = await getChangedFiles(token, base, ref, initialFetchDepth)
+ const {files, api} = await getChangedFiles(token, base, ref, initialFetchDepth)
core.info(`Detected ${files.length} changed files`)
const results = filter.match(files)
exportResults(results, listFiles)
+ if (api) {
+ await shadow.report({filter, apiFiles: files, apiResults: results, ...api})
+ }
} catch (error) {
core.setFailed(getErrorMessage(error))
}
@@ -59,14 +62,27 @@ function getConfigFileContent(configPath: string): string {
return fs.readFileSync(configPath, {encoding: 'utf8'})
}
-async function getChangedFiles(token: string, base: string, ref: string, initialFetchDepth: number): Promise<File[]> {
+// `api` is present only when the list came from the pull request files API, and carries
+// what the shadow comparison needs to describe that call. The shadow runs from `run()`,
+// which already holds the filter and its results, so detection stays free of it.
+interface ChangedFiles {
+ files: File[]
+ api?: {apiRows: number; apiTruncated: boolean; pr: PullRequest}
+}
+
+async function getChangedFiles(
+ token: string,
+ base: string,
+ ref: string,
+ initialFetchDepth: number
+): Promise<ChangedFiles> {
// if base is 'HEAD' only local uncommitted changes will be detected
// This is the simplest case as we don't need to fetch more commits or evaluate current/before refs
if (base === git.HEAD) {
if (ref) {
core.warning(`'ref' input parameter is ignored when 'base' is set to HEAD`)
}
- return await git.getChangesOnHead()
+ return {files: await git.getChangesOnHead()}
}
switch (github.context.eventName) {
@@ -84,9 +100,8 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
}
const pr = github.context.payload.pull_request as PullRequest
if (token) {
- const apiFiles = await getChangedFilesFromApi(token, pr)
- await shadow.report(apiFiles, pr)
- return apiFiles
+ const {files, apiRows, apiTruncated} = await getChangedFilesFromApi(token, pr)
+ return {files, api: {apiRows, apiTruncated, pr}}
}
if (github.context.eventName === 'pull_request_target') {
// pull_request_target is executed in context of base branch and GITHUB_SHA points to last commit in base branch
@@ -98,11 +113,11 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
const baseSha = github.context.payload.pull_request?.base.sha
const defaultBranch = github.context.payload.repository?.default_branch
const currentRef = await git.getCurrentRef()
- return await git.getChanges(base || baseSha || defaultBranch, currentRef)
+ return {files: await git.getChanges(base || baseSha || defaultBranch, currentRef)}
}
}
- return getChangedFilesFromGit(base, ref, initialFetchDepth)
+ return {files: await getChangedFilesFromGit(base, ref, initialFetchDepth)}
}
async function getChangedFilesFromGit(base: string, head: string, initialFetchDepth: number): Promise<File[]> {
@@ -167,13 +182,21 @@ async function getChangedFilesFromGit(base: string, head: string, initialFetchDe
return await git.getChangesSinceMergeBase(base, head, initialFetchDepth)
}
+// The API truncates at this many rows and says nothing when it does.
+const API_FILE_CAP = 3000
+
// Uses github REST api to get list of files changed in PR
-async function getChangedFilesFromApi(token: string, pullRequest: PullRequest): Promise<File[]> {
+// Truncation is judged on API rows, not on `files`, which expands a rename into two.
+async function getChangedFilesFromApi(
+ token: string,
+ pullRequest: PullRequest
+): Promise<{files: File[]; apiRows: number; apiTruncated: boolean}> {
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`)
try {
const client = github.getOctokit(token)
const per_page = 100
const files: File[] = []
+ let apiRows = 0
core.info(`Invoking listFiles(pull_number: ${pullRequest.number}, per_page: ${per_page})`)
for await (const response of client.paginate.iterator(
@@ -190,6 +213,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
core.info(`Received ${response.data.length} items`)
for (const row of response.data as GetResponseDataTypeFromEndpointMethod<typeof client.rest.pulls.listFiles>) {
+ apiRows++
core.info(`[${row.status}] ${row.filename}`)
// There's no obvious use-case for detection of renames
// Therefore we treat it as if rename detection in git diff was turned off.
@@ -215,7 +239,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
}
}
- return files
+ return {files, apiRows, apiTruncated: apiRows >= API_FILE_CAP}
} finally {
core.endGroup()
}
@@ -223,12 +247,11 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
function exportResults(results: FilterResults, format: ExportFormat): void {
core.info('Results:')
- const changes = []
+ const fired = firedKeys(results)
for (const [key, files] of Object.entries(results)) {
- const value = files.length > 0
+ const value = fired.has(key)
core.startGroup(`Filter ${key} = ${value}`)
- if (files.length > 0) {
- changes.push(key)
+ if (value) {
core.info('Matching files:')
for (const file of files) {
core.info(`${file.filename} [${file.status}]`)
@@ -247,7 +270,7 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
}
if (results['changes'] === undefined) {
- const changesJson = JSON.stringify(changes)
+ const changesJson = JSON.stringify([...fired])
core.info(`Changes output set to ${changesJson}`)
core.setOutput('changes', changesJson)
} else {
diff --git a/.depot/actions/paths-filter/src/shadow.ts b/.depot/actions/paths-filter/src/shadow.ts
index abcfcb3b975e..95200462c4c1 100644
--- a/.depot/actions/paths-filter/src/shadow.ts
+++ b/.depot/actions/paths-filter/src/shadow.ts
@@ -6,45 +6,33 @@ import * as core from '@actions/core'
import {PullRequest} from '@octokit/webhooks-types'
import {File} from './file'
+import {Filter, FilterResults, firedKeys} from './filter'
+import {parseGitDiffOutput} from './git'
-// Compares the API's changed-file list against the same list derived locally from
-// the pull request's merge commit, and reports disagreement without acting on it.
-// The API result stays authoritative, so a wrong local answer can only produce a
-// log line. Removing the API call later is only safe once this has run quiet
-// across the shapes no offline sample can reach: very large diffs, and ones GitHub
-// has not finished computing a merge ref for.
-//
-// Detecting changes from `base.sha..HEAD` instead reports every commit the branch
-// picked up when the base was merged into it as the pull request's own work, which
-// is wrong by thousands of files on a branch that has taken master in. The merge
-// commit's first parent is the base GitHub actually merged against, so
-// `HEAD^1..HEAD` is the pull request's own changes and matches the API.
+// Compares the API's changed-file list against the same list derived from the pull
+// request's merge commit, and reports disagreement without acting on it. The API
+// result stays authoritative, so a wrong local answer can only produce a log line.
const MERGE_REF_FETCH_DEPTH = 2
const POSTHOG_HOST = 'https://us.i.posthog.com'
const EVENT_NAME = 'paths_filter_shadow_compared'
// A change-detection job is on the critical path of every workflow, so the comparison
-// and the capture that follows it share one wall-clock budget, and give up rather than
-// holding the job to its timeout-minutes. The git-level low-speed settings cover a
-// stalled transfer; the budget covers everything else.
+// and its capture share one wall-clock budget rather than holding the job to its
+// timeout-minutes.
const BUDGET_MS = 20000
const CAPTURE_FLOOR_MS = 500
const LIST_CAP = 50
-// A queue branch carries the cumulative batch diff, so the path list can be far larger
-// than a human pull request's. execFile's 1 MB default would fail those as a diff error,
-// which drops the population the comparison most needs to measure.
+// A queue branch carries the cumulative batch diff, which execFile's 1 MB default would
+// fail as a diff error.
const MAX_GIT_OUTPUT_BYTES = 64 * 1024 * 1024
const DETAIL_CAP = 200
-// The API caps pulls/{n}/files at this many entries and says nothing when it truncates.
-const API_FILE_CAP = 3000
-
type Verdict = 'match' | 'mismatch' | 'unavailable'
-// A closed set, because this is the field the comparison is grouped by once the events
-// land. Git's own words go in `detail`, which is free text and unbounded.
+// Closed, because this is the field the events are grouped by. Git's own words go in
+// `detail`, which is unbounded.
type Reason =
| 'no-scratch-repo'
| 'no-origin-url'
@@ -74,6 +62,17 @@ interface ShadowResult {
gitCount: number | null
onlyInApi: Difference
onlyInGit: Difference
+ keysLost: string[]
+ keysGained: string[]
+}
+
+export interface ShadowInput {
+ filter: Filter
+ apiFiles: File[]
+ apiResults: FilterResults
+ apiRows: number
+ apiTruncated: boolean
+ pr: PullRequest
}
interface GitResult {
@@ -82,21 +81,16 @@ interface GitResult {
err: string
}
-// Every git call that reads or writes history names the scratch repository. `--depth`
-// and `--filter` rewrite `.git/shallow` and the promisor config of whatever repository
-// they run in, and steps later in the same job read history from the workspace checkout:
-// ci-dagster and ci-e2e-playwright resolve `git merge-base HEAD^2 origin/<base>` after
-// this action returns, and an empty merge base there silently drops their schema cache.
+// `--depth` and `--filter` rewrite `.git/shallow` and the promisor config of whatever
+// repository they run in, so every call names the scratch repository. ci-dagster and
+// ci-e2e-playwright read history from the workspace checkout after this action returns.
async function git(gitDir: string, args: string[], signal: AbortSignal): Promise<GitResult> {
return run(['--git-dir', gitDir, ...args], signal)
}
-// The signal is what makes the wall-clock budget real. `@actions/exec` gives no handle
-// on the child process, so a fetch the budget gave up on keeps running and holds the
-// action's process open until it finishes, past the budget it was supposed to obey.
-//
-// stdout is returned raw. A caller that reads a path list must not trim it, because a
-// tracked path can begin with a space, and that path sorts first in the -z output.
+// execFile rather than `@actions/exec`, which gives no handle on the child process, so a
+// fetch the budget gave up on would hold the action open until it finished. stdout is
+// returned raw because a tracked path can begin with a space.
async function run(args: string[], signal: AbortSignal): Promise<GitResult> {
return new Promise(resolve => {
execFile('git', args, {signal, maxBuffer: MAX_GIT_OUTPUT_BYTES}, (error, stdout, stderr) => {
@@ -113,6 +107,10 @@ function messageOf(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
+function missing(from: Set<string>, against: Set<string>): string[] {
+ return [...from].filter(key => !against.has(key)).sort()
+}
+
async function scratchRepo(signal: AbortSignal): Promise<string> {
const gitDir = path.join(process.env.RUNNER_TEMP || os.tmpdir(), 'paths-filter-shadow.git')
const init = await run(['init', '--bare', '--quiet', gitDir], signal)
@@ -122,9 +120,8 @@ async function scratchRepo(signal: AbortSignal): Promise<string> {
return gitDir
}
-// The workspace remote carries no credentials of its own: actions/checkout keeps the
-// token in an http.extraheader the scratch repository does not inherit. A private
-// remote therefore reports unavailable rather than comparing against a partial fetch.
+// actions/checkout keeps the token in an http.extraheader the scratch repository does not
+// inherit, so a private remote reports unavailable rather than comparing a partial fetch.
function originUrl(): string {
const server = process.env.GITHUB_SERVER_URL
const repo = process.env.GITHUB_REPOSITORY
@@ -134,10 +131,7 @@ function originUrl(): string {
return `${server}/${repo}`
}
-// The merge ref is not guaranteed to be present or current: GitHub recomputes it
-// asynchronously after a push. Requiring the second parent to equal the head SHA
-// rejects a stale ref rather than reading it as this pull request's changes.
-async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<string[]> {
+async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<File[]> {
const gitDir = await scratchRepo(signal)
const fetched = await git(
@@ -164,24 +158,23 @@ async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<
if (head.code !== 0) {
throw new Unavailable('no-second-parent', firstLine(head.err))
}
+ // GitHub recomputes the merge ref asynchronously after a push, so a ref whose second
+ // parent is not the head SHA describes an earlier push.
const headSha = head.out.trim()
if (headSha !== pr.head.sha) {
throw new Unavailable('stale-merge-ref', `^2=${headSha.slice(0, 8)}, head=${pr.head.sha.slice(0, 8)}`)
}
- // --no-renames so a rename arrives as a delete plus an add, which is the shape
- // the API path builds by hand from `previous_filename`. -z because git quotes a
- // path holding a newline or a non-ASCII byte in the default format.
- const diff = await git(gitDir, ['diff', '--no-renames', '--name-only', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal)
+ // The same flags the action's own git path uses, so the comparison measures what
+ // dropping the API call would select. --no-renames matches the add-plus-delete shape
+ // the API path builds from `previous_filename`.
+ const diff = await git(gitDir, ['diff', '--no-renames', '--name-status', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal)
if (diff.code !== 0) {
throw new Unavailable('diff-failed', firstLine(diff.err))
}
- return diff.out.split('\0').filter(Boolean)
+ return parseGitDiffOutput(diff.out)
}
-// A queue branch can differ by thousands of paths, which is neither readable in a log
-// line nor worth carrying as an event property. The count answers how far apart the two
-// answers are, and the sample answers what kind of path is involved.
function difference(from: Set<string>, against: Set<string>): Difference {
const sample: string[] = []
let count = 0
@@ -197,9 +190,12 @@ function difference(from: Set<string>, against: Set<string>): Difference {
return {count, sample}
}
-function compare(api: Set<string>, local: Set<string>): ShadowResult {
+function compare(input: ShadowInput, api: Set<string>, gitFiles: File[]): ShadowResult {
+ const local = new Set(gitFiles.map(f => f.filename))
const onlyInApi = difference(api, local)
const onlyInGit = difference(local, api)
+ const apiKeys = firedKeys(input.apiResults)
+ const gitKeys = firedKeys(input.filter.match(gitFiles))
return {
verdict: onlyInApi.count === 0 && onlyInGit.count === 0 ? 'match' : 'mismatch',
reason: null,
@@ -207,7 +203,9 @@ function compare(api: Set<string>, local: Set<string>): ShadowResult {
apiCount: api.size,
gitCount: local.size,
onlyInApi,
- onlyInGit
+ onlyInGit,
+ keysLost: missing(apiKeys, gitKeys),
+ keysGained: missing(gitKeys, apiKeys)
}
}
@@ -223,11 +221,11 @@ async function budgeted<T>(work: (signal: AbortSignal) => Promise<T>, ms: number
return Promise.race([work(controller.signal), expiry]).finally(() => clearTimeout(timer))
}
-export async function compareWithMergeCommit(apiFiles: File[], pr: PullRequest): Promise<ShadowResult> {
- const api = new Set(apiFiles.map(f => f.filename))
+export async function compareWithMergeCommit(input: ShadowInput): Promise<ShadowResult> {
+ const api = new Set(input.apiFiles.map(f => f.filename))
try {
- const gitFiles = await budgeted(async signal => localChangedFiles(pr, signal), BUDGET_MS)
- return compare(api, new Set(gitFiles))
+ const gitFiles = await budgeted(async signal => localChangedFiles(input.pr, signal), BUDGET_MS)
+ return compare(input, api, gitFiles)
} catch (error) {
return {
verdict: 'unavailable',
@@ -236,15 +234,16 @@ export async function compareWithMergeCommit(apiFiles: File[], pr: PullRequest):
apiCount: api.size,
gitCount: null,
onlyInApi: {count: 0, sample: []},
- onlyInGit: {count: 0, sample: []}
+ onlyInGit: {count: 0, sample: []},
+ keysLost: [],
+ keysGained: []
}
}
}
-// Without this the only record of a divergence is a log line in one job of one run,
-// which is unreadable at the volume that makes the comparison worth running.
-async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, durationMs: number): Promise<void> {
+async function capture(apiKey: string, input: ShadowInput, result: ShadowResult, durationMs: number): Promise<void> {
const repo = process.env.GITHUB_REPOSITORY || null
+ const pr = input.pr
const properties = {
repo,
verdict: result.verdict,
@@ -256,18 +255,18 @@ async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, du
only_in_api_count: result.onlyInApi.count,
only_in_git: result.onlyInGit.sample,
only_in_git_count: result.onlyInGit.count,
- // pulls/{n}/files truncates silently, so record both sides of the tell: what the
- // API returned, and what the pull request payload says it should have been. The
- // count has to come from the payload, because `api_count` counts a rename twice:
- // the API path expands each renamed row into an add plus a delete.
- api_truncated: pr.changed_files >= API_FILE_CAP,
+ selection_changed: result.keysLost.length > 0 || result.keysGained.length > 0,
+ keys_lost: result.keysLost,
+ keys_gained: result.keysGained,
+ // `pr_changed_files` reads stale on a pull request whose base moved, so it is
+ // recorded beside the API's own row count rather than used as the truncation tell.
+ api_rows: input.apiRows,
+ api_truncated: input.apiTruncated,
pr_changed_files: pr.changed_files,
pr_number: pr.number,
head_sha: pr.head.sha,
head_ref: pr.head.ref,
base_ref: pr.base.ref,
- // Queue branches carry the cumulative batch diff and page far more than a human
- // pull request, so they are the population worth reading separately.
branch_class: pr.head.ref.startsWith('trunk-merge/') ? 'trunk-merge' : 'pull-request',
is_fork: pr.head.repo?.full_name !== repo,
duration_ms: durationMs,
@@ -285,7 +284,6 @@ async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, du
distinct_id: repo || 'paths-filter-shadow',
properties
}),
- // Whatever the comparison did not spend, so the step's ceiling stays the budget.
signal: AbortSignal.timeout(Math.max(CAPTURE_FLOOR_MS, BUDGET_MS - durationMs))
})
if (!res.ok) {
@@ -300,20 +298,17 @@ function summarize(result: ShadowResult): string {
if (result.verdict === 'mismatch') {
return (
`MISMATCH api=${result.apiCount} git=${result.gitCount} ` +
- `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)}`
+ `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)} ` +
+ `keysLost=${JSON.stringify(result.keysLost)} keysGained=${JSON.stringify(result.keysGained)}`
)
}
return `match (${result.apiCount} files)`
}
-// Never throws: the filter's real answer is already computed by the time this runs,
-// so nothing here is worth failing a CI job over.
-//
-// The token gates the comparison itself, not just the capture. Every workflow that
-// detects changes runs this action, so a comparison whose result cannot be recorded
-// is a merge-ref fetch on the critical path of a gate job in exchange for a log line
-// nobody reads. Fork pull requests get no secrets, so they take this path too.
-export async function report(apiFiles: File[], pr: PullRequest): Promise<void> {
+// Never throws: the filter's real answer is already computed by the time this runs. The
+// token gates the comparison itself, so a run that cannot record its result does not pay
+// for a merge-ref fetch. Fork pull requests get no secrets and take that path too.
+export async function report(input: ShadowInput): Promise<void> {
const apiKey = process.env.PATHS_FILTER_SHADOW_POSTHOG_TOKEN
if (!apiKey) {
return
@@ -321,14 +316,14 @@ export async function report(apiFiles: File[], pr: PullRequest): Promise<void> {
try {
core.startGroup('Shadow: merge-commit change detection')
const startedAt = Date.now()
- const result = await compareWithMergeCommit(apiFiles, pr)
+ const result = await compareWithMergeCommit(input)
const durationMs = Date.now() - startedAt
- // core.info even for a mismatch: a warning becomes an annotation on the run summary
- // and the checks page, which reads as a problem with the pull request.
+ // core.info even for a mismatch, because a warning becomes an annotation on the
+ // checks page and reads as a problem with the pull request.
core.info(`shadow: ${summarize(result)} in ${durationMs}ms`)
- await capture(apiKey, result, pr, durationMs).catch(error => {
+ await capture(apiKey, input, result, durationMs).catch(error => {
core.info(`shadow: capture skipped (${messageOf(error)})`)
})
} catch (error) {
diff --git a/.github/actions/paths-filter/README.md b/.github/actions/paths-filter/README.md
index cb2b746d89a6..81e8ff92a1c3 100644
--- a/.github/actions/paths-filter/README.md
+++ b/.github/actions/paths-filter/README.md
@@ -81,6 +81,10 @@ Without the variable the action does no extra work. Set it in one workflow that
every pull request; that keeps the merge-ref fetch off the critical path of the other
gating jobs. This is temporary, and goes away with the decision it exists to inform.
+The event carries the differing paths and, in `selection_changed` and `keys_lost`, which
+filter keys answer differently on the two lists. The keys are what gate a job, so they are
+what the decision reads; the paths are there to explain a flip.
+
## Rebuilding after source changes
The action runs the committed `dist/index.js` bundle. After editing anything under `src/`,
diff --git a/.github/actions/paths-filter/__tests__/shadow.test.ts b/.github/actions/paths-filter/__tests__/shadow.test.ts
index 257a62d706fe..367fff5b7e37 100644
--- a/.github/actions/paths-filter/__tests__/shadow.test.ts
+++ b/.github/actions/paths-filter/__tests__/shadow.test.ts
@@ -1,7 +1,8 @@
import {PullRequest} from '@octokit/webhooks-types'
-import {ChangeStatus} from '../src/file'
-import {compareWithMergeCommit} from '../src/shadow'
+import {ChangeStatus, File} from '../src/file'
+import {Filter} from '../src/filter'
+import {ShadowInput, compareWithMergeCommit} from '../src/shadow'
const cp = jest.requireMock('child_process') as {execFile: jest.Mock}
@@ -22,6 +23,26 @@ type ExecFileArgs = [
const pullRequest = {number: 42, head: {sha: HEAD}} as PullRequest
+const filter = new Filter(`
+backend:
+ - 'posthog/**'
+frontend:
+ - 'frontend/**'
+`)
+
+// The action matches the API list once in `run()` and hands the result to the shadow, so
+// a test builds the same pairing here.
+function input(withFilter: Filter, apiFiles: File[]): ShadowInput {
+ return {
+ filter: withFilter,
+ apiFiles,
+ apiResults: withFilter.match(apiFiles),
+ apiRows: apiFiles.length,
+ apiTruncated: false,
+ pr: pullRequest
+ }
+}
+
function stubGit(...stdouts: string[]): void {
for (const stdout of stdouts) {
cp.execFile.mockImplementationOnce((...args: ExecFileArgs) => args[3](null, stdout, ''))
@@ -40,12 +61,13 @@ describe('shadow merge-commit comparison', () => {
cp.execFile.mockReset()
})
- // A git call that forgets the scratch dir runs against the job workspace, where a
- // --depth or --filter fetch drops the schema cache of every later step in the job.
+ // A git call against the job workspace drops the schema cache of every later step.
test('never runs git against the job workspace', async () => {
- stubGit('', '', HEAD, 'a.ts\0')
+ stubGit('', '', HEAD, 'M\0posthog/a.py\0')
- const result = await compareWithMergeCommit([{filename: 'a.ts', status: ChangeStatus.Modified}], pullRequest)
+ const result = await compareWithMergeCommit(
+ input(filter, [{filename: 'posthog/a.py', status: ChangeStatus.Modified}])
+ )
expect(result.verdict).toBe('match')
expect(argvOf(0)).toContain(GIT_DIR)
@@ -54,41 +76,39 @@ describe('shadow merge-commit comparison', () => {
}
})
- // Losing this guard scores a merge ref from an earlier push as this pull request's
- // changes, which fills the measurement with mismatches that mean nothing.
+ // Without this guard an earlier push's merge ref reads as this pull request's changes.
test('refuses a stale merge ref instead of comparing against it', async () => {
stubGit('', '', OTHER_SHA)
- const result = await compareWithMergeCommit([{filename: 'a.ts', status: ChangeStatus.Modified}], pullRequest)
+ const result = await compareWithMergeCommit(
+ input(filter, [{filename: 'posthog/a.py', status: ChangeStatus.Modified}])
+ )
expect(result.verdict).toBe('unavailable')
expect(result.reason).toBe('stale-merge-ref')
})
- // Losing --no-renames reports one path where the API path reports two, so every
- // rename reads as a mismatch.
+ // Without --no-renames every rename reads as a mismatch.
test('matches a rename that the API reported as two entries', async () => {
- stubGit('', '', HEAD, 'old.ts\0new.ts\0')
+ stubGit('', '', HEAD, 'D\0posthog/old.py\0A\0posthog/new.py\0')
const result = await compareWithMergeCommit(
- [
- {filename: 'new.ts', status: ChangeStatus.Added},
- {filename: 'old.ts', status: ChangeStatus.Deleted}
- ],
- pullRequest
+ input(filter, [
+ {filename: 'posthog/new.py', status: ChangeStatus.Added},
+ {filename: 'posthog/old.py', status: ChangeStatus.Deleted}
+ ])
)
expect(result.verdict).toBe('match')
expect(cp.execFile.mock.calls.map(c => c[1])).toContainEqual(expect.arrayContaining(['--no-renames']))
})
- // An exec with no handle on the child leaves the fetch running after the budget gives
- // up, and the action's process stays open until git exits.
+ // Without a handle on the child, an abandoned fetch holds the action open until git exits.
test('stops git when the budget expires', async () => {
cp.execFile.mockImplementation(() => undefined)
jest.useFakeTimers()
- const pending = compareWithMergeCommit([], pullRequest)
+ const pending = compareWithMergeCommit(input(filter, []))
await jest.advanceTimersByTimeAsync(PAST_ANY_BUDGET_MS)
const result = await pending
@@ -98,4 +118,44 @@ describe('shadow merge-commit comparison', () => {
expect(options.signal.aborted).toBe(true)
jest.useRealTimers()
})
+
+ // Comparing the file lists instead of the keys reports every dropped path as consequential.
+ test.each([
+ ['the dropped path is the only one holding a key', 'M\0frontend/b.ts\0', ['backend']],
+ ['a surviving path holds the same key', 'M\0posthog/b.py\0M\0frontend/b.ts\0', []]
+ ])('reports keys lost when %s', async (_case, diff, keysLost) => {
+ stubGit('', '', HEAD, diff)
+
+ const result = await compareWithMergeCommit(
+ input(filter, [
+ {filename: 'posthog/a.py', status: ChangeStatus.Modified},
+ {filename: 'posthog/b.py', status: ChangeStatus.Modified},
+ {filename: 'frontend/b.ts', status: ChangeStatus.Modified}
+ ])
+ )
+
+ expect(result.verdict).toBe('mismatch')
+ expect(result.keysLost).toEqual(keysLost)
+ expect(result.keysGained).toEqual([])
+ })
+
+ // Reading the -z fields in the wrong order turns every path into a status letter.
+ test('carries each file status through to a status-scoped rule', async () => {
+ const scoped = new Filter(`
+added_only:
+ - added: 'posthog/**'
+`)
+ stubGit('', '', HEAD, 'A\0posthog/new.py\0D\0posthog/gone.py\0')
+
+ const result = await compareWithMergeCommit(
+ input(scoped, [
+ {filename: 'posthog/new.py', status: ChangeStatus.Added},
+ {filename: 'posthog/gone.py', status: ChangeStatus.Deleted}
+ ])
+ )
+
+ expect(result.verdict).toBe('match')
+ expect(result.keysLost).toEqual([])
+ expect(result.keysGained).toEqual([])
+ })
})
diff --git a/.github/actions/paths-filter/dist/index.js b/.github/actions/paths-filter/dist/index.js
index 1115cb186a4f..7debf5e327a7 100644
--- a/.github/actions/paths-filter/dist/index.js
+++ b/.github/actions/paths-filter/dist/index.js
@@ -42189,6 +42189,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Filter = void 0;
+exports.firedKeys = firedKeys;
const jsyaml = __importStar(__nccwpck_require__(4281));
const picomatch_1 = __importDefault(__nccwpck_require__(4006));
// Minimatch options used in all matchers
@@ -42203,6 +42204,11 @@ function isNegatedPattern(pattern) {
function positivePattern(pattern) {
return isNegatedPattern(pattern) ? pattern.slice(1) : pattern;
}
+// A key gates a job on whether any file matched it, so its answer is `length > 0` and
+// nothing finer. Both the action's outputs and the shadow comparison read it through here.
+function firedKeys(results) {
+ return new Set(Object.keys(results).filter(key => results[key].length > 0));
+}
class Filter {
// Creates instance of Filter and load rules from YAML if it's provided
constructor(yaml) {
@@ -42708,10 +42714,13 @@ async function run() {
return;
}
const filter = new filter_1.Filter(filtersYaml);
- const files = await getChangedFiles(token, base, ref, initialFetchDepth);
+ const { files, api } = await getChangedFiles(token, base, ref, initialFetchDepth);
core.info(`Detected ${files.length} changed files`);
const results = filter.match(files);
exportResults(results, listFiles);
+ if (api) {
+ await shadow.report({ filter, apiFiles: files, apiResults: results, ...api });
+ }
}
catch (error) {
core.setFailed(getErrorMessage(error));
@@ -42737,7 +42746,7 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
if (ref) {
core.warning(`'ref' input parameter is ignored when 'base' is set to HEAD`);
}
- return await git.getChangesOnHead();
+ return { files: await git.getChangesOnHead() };
}
switch (github.context.eventName) {
// To keep backward compatibility, commits in GitHub pull request event
@@ -42754,9 +42763,8 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
}
const pr = github.context.payload.pull_request;
if (token) {
- const apiFiles = await getChangedFilesFromApi(token, pr);
- await shadow.report(apiFiles, pr);
- return apiFiles;
+ const { files, apiRows, apiTruncated } = await getChangedFilesFromApi(token, pr);
+ return { files, api: { apiRows, apiTruncated, pr } };
}
if (github.context.eventName === 'pull_request_target') {
// pull_request_target is executed in context of base branch and GITHUB_SHA points to last commit in base branch
@@ -42768,10 +42776,10 @@ async function getChangedFiles(token, base, ref, initialFetchDepth) {
const baseSha = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base.sha;
const defaultBranch = (_b = github.context.payload.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
const currentRef = await git.getCurrentRef();
- return await git.getChanges(base || baseSha || defaultBranch, currentRef);
+ return { files: await git.getChanges(base || baseSha || defaultBranch, currentRef) };
}
}
- return getChangedFilesFromGit(base, ref, initialFetchDepth);
+ return { files: await getChangedFilesFromGit(base, ref, initialFetchDepth) };
}
async function getChangedFilesFromGit(base, head, initialFetchDepth) {
var _a;
@@ -42820,13 +42828,17 @@ async function getChangedFilesFromGit(base, head, initialFetchDepth) {
core.info(`Changes will be detected between ${base} and ${head}`);
return await git.getChangesSinceMergeBase(base, head, initialFetchDepth);
}
+// The API truncates at this many rows and says nothing when it does.
+const API_FILE_CAP = 3000;
// Uses github REST api to get list of files changed in PR
+// Truncation is judged on API rows, not on `files`, which expands a rename into two.
async function getChangedFilesFromApi(token, pullRequest) {
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`);
try {
const client = github.getOctokit(token);
const per_page = 100;
const files = [];
+ let apiRows = 0;
core.info(`Invoking listFiles(pull_number: ${pullRequest.number}, per_page: ${per_page})`);
for await (const response of client.paginate.iterator(client.rest.pulls.listFiles.endpoint.merge({
owner: github.context.repo.owner,
@@ -42839,6 +42851,7 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
core.info(`Received ${response.data.length} items`);
for (const row of response.data) {
+ apiRows++;
core.info(`[${row.status}] ${row.filename}`);
// There's no obvious use-case for detection of renames
// Therefore we treat it as if rename detection in git diff was turned off.
@@ -42864,7 +42877,7 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
}
}
- return files;
+ return { files, apiRows, apiTruncated: apiRows >= API_FILE_CAP };
}
finally {
core.endGroup();
@@ -42872,12 +42885,11 @@ async function getChangedFilesFromApi(token, pullRequest) {
}
function exportResults(results, format) {
core.info('Results:');
- const changes = [];
+ const fired = (0, filter_1.firedKeys)(results);
for (const [key, files] of Object.entries(results)) {
- const value = files.length > 0;
+ const value = fired.has(key);
core.startGroup(`Filter ${key} = ${value}`);
- if (files.length > 0) {
- changes.push(key);
+ if (value) {
core.info('Matching files:');
for (const file of files) {
core.info(`${file.filename} [${file.status}]`);
@@ -42895,7 +42907,7 @@ function exportResults(results, format) {
core.endGroup();
}
if (results['changes'] === undefined) {
- const changesJson = JSON.stringify(changes);
+ const changesJson = JSON.stringify([...fired]);
core.info(`Changes output set to ${changesJson}`);
core.setOutput('changes', changesJson);
}
@@ -42976,35 +42988,24 @@ const child_process_1 = __nccwpck_require__(5317);
const os = __importStar(__nccwpck_require__(857));
const path = __importStar(__nccwpck_require__(6928));
const core = __importStar(__nccwpck_require__(7484));
-// Compares the API's changed-file list against the same list derived locally from
-// the pull request's merge commit, and reports disagreement without acting on it.
-// The API result stays authoritative, so a wrong local answer can only produce a
-// log line. Removing the API call later is only safe once this has run quiet
-// across the shapes no offline sample can reach: very large diffs, and ones GitHub
-// has not finished computing a merge ref for.
-//
-// Detecting changes from `base.sha..HEAD` instead reports every commit the branch
-// picked up when the base was merged into it as the pull request's own work, which
-// is wrong by thousands of files on a branch that has taken master in. The merge
-// commit's first parent is the base GitHub actually merged against, so
-// `HEAD^1..HEAD` is the pull request's own changes and matches the API.
+const filter_1 = __nccwpck_require__(9037);
+const git_1 = __nccwpck_require__(1243);
+// Compares the API's changed-file list against the same list derived from the pull
+// request's merge commit, and reports disagreement without acting on it. The API
+// result stays authoritative, so a wrong local answer can only produce a log line.
const MERGE_REF_FETCH_DEPTH = 2;
const POSTHOG_HOST = 'https://us.i.posthog.com';
const EVENT_NAME = 'paths_filter_shadow_compared';
// A change-detection job is on the critical path of every workflow, so the comparison
-// and the capture that follows it share one wall-clock budget, and give up rather than
-// holding the job to its timeout-minutes. The git-level low-speed settings cover a
-// stalled transfer; the budget covers everything else.
+// and its capture share one wall-clock budget rather than holding the job to its
+// timeout-minutes.
const BUDGET_MS = 20000;
const CAPTURE_FLOOR_MS = 500;
const LIST_CAP = 50;
-// A queue branch carries the cumulative batch diff, so the path list can be far larger
-// than a human pull request's. execFile's 1 MB default would fail those as a diff error,
-// which drops the population the comparison most needs to measure.
+// A queue branch carries the cumulative batch diff, which execFile's 1 MB default would
+// fail as a diff error.
const MAX_GIT_OUTPUT_BYTES = 64 * 1024 * 1024;
const DETAIL_CAP = 200;
-// The API caps pulls/{n}/files at this many entries and says nothing when it truncates.
-const API_FILE_CAP = 3000;
class Unavailable extends Error {
constructor(reason, detail) {
super(`${reason}: ${detail}`);
@@ -43012,20 +43013,15 @@ class Unavailable extends Error {
this.detail = detail;
}
}
-// Every git call that reads or writes history names the scratch repository. `--depth`
-// and `--filter` rewrite `.git/shallow` and the promisor config of whatever repository
-// they run in, and steps later in the same job read history from the workspace checkout:
-// ci-dagster and ci-e2e-playwright resolve `git merge-base HEAD^2 origin/<base>` after
-// this action returns, and an empty merge base there silently drops their schema cache.
+// `--depth` and `--filter` rewrite `.git/shallow` and the promisor config of whatever
+// repository they run in, so every call names the scratch repository. ci-dagster and
+// ci-e2e-playwright read history from the workspace checkout after this action returns.
async function git(gitDir, args, signal) {
return run(['--git-dir', gitDir, ...args], signal);
}
-// The signal is what makes the wall-clock budget real. `@actions/exec` gives no handle
-// on the child process, so a fetch the budget gave up on keeps running and holds the
-// action's process open until it finishes, past the budget it was supposed to obey.
-//
-// stdout is returned raw. A caller that reads a path list must not trim it, because a
-// tracked path can begin with a space, and that path sorts first in the -z output.
+// execFile rather than `@actions/exec`, which gives no handle on the child process, so a
+// fetch the budget gave up on would hold the action open until it finished. stdout is
+// returned raw because a tracked path can begin with a space.
async function run(args, signal) {
return new Promise(resolve => {
(0, child_process_1.execFile)('git', args, { signal, maxBuffer: MAX_GIT_OUTPUT_BYTES }, (error, stdout, stderr) => {
@@ -43039,6 +43035,9 @@ function firstLine(stderr) {
function messageOf(error) {
return error instanceof Error ? error.message : String(error);
}
+function missing(from, against) {
+ return [...from].filter(key => !against.has(key)).sort();
+}
async function scratchRepo(signal) {
const gitDir = path.join(process.env.RUNNER_TEMP || os.tmpdir(), 'paths-filter-shadow.git');
const init = await run(['init', '--bare', '--quiet', gitDir], signal);
@@ -43047,9 +43046,8 @@ async function scratchRepo(signal) {
}
return gitDir;
}
-// The workspace remote carries no credentials of its own: actions/checkout keeps the
-// token in an http.extraheader the scratch repository does not inherit. A private
-// remote therefore reports unavailable rather than comparing against a partial fetch.
+// actions/checkout keeps the token in an http.extraheader the scratch repository does not
+// inherit, so a private remote reports unavailable rather than comparing a partial fetch.
function originUrl() {
const server = process.env.GITHUB_SERVER_URL;
const repo = process.env.GITHUB_REPOSITORY;
@@ -43058,9 +43056,6 @@ function originUrl() {
}
return `${server}/${repo}`;
}
-// The merge ref is not guaranteed to be present or current: GitHub recomputes it
-// asynchronously after a push. Requiring the second parent to equal the head SHA
-// rejects a stale ref rather than reading it as this pull request's changes.
async function localChangedFiles(pr, signal) {
const gitDir = await scratchRepo(signal);
const fetched = await git(gitDir, [
@@ -43082,22 +43077,21 @@ async function localChangedFiles(pr, signal) {
if (head.code !== 0) {
throw new Unavailable('no-second-parent', firstLine(head.err));
}
+ // GitHub recomputes the merge ref asynchronously after a push, so a ref whose second
+ // parent is not the head SHA describes an earlier push.
const headSha = head.out.trim();
if (headSha !== pr.head.sha) {
throw new Unavailable('stale-merge-ref', `^2=${headSha.slice(0, 8)}, head=${pr.head.sha.slice(0, 8)}`);
}
- // --no-renames so a rename arrives as a delete plus an add, which is the shape
- // the API path builds by hand from `previous_filename`. -z because git quotes a
- // path holding a newline or a non-ASCII byte in the default format.
- const diff = await git(gitDir, ['diff', '--no-renames', '--name-only', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal);
+ // The same flags the action's own git path uses, so the comparison measures what
+ // dropping the API call would select. --no-renames matches the add-plus-delete shape
+ // the API path builds from `previous_filename`.
+ const diff = await git(gitDir, ['diff', '--no-renames', '--name-status', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal);
if (diff.code !== 0) {
throw new Unavailable('diff-failed', firstLine(diff.err));
}
- return diff.out.split('\0').filter(Boolean);
+ return (0, git_1.parseGitDiffOutput)(diff.out);
}
-// A queue branch can differ by thousands of paths, which is neither readable in a log
-// line nor worth carrying as an event property. The count answers how far apart the two
-// answers are, and the sample answers what kind of path is involved.
function difference(from, against) {
const sample = [];
let count = 0;
@@ -43112,9 +43106,12 @@ function difference(from, against) {
}
return { count, sample };
}
-function compare(api, local) {
+function compare(input, api, gitFiles) {
+ const local = new Set(gitFiles.map(f => f.filename));
const onlyInApi = difference(api, local);
const onlyInGit = difference(local, api);
+ const apiKeys = (0, filter_1.firedKeys)(input.apiResults);
+ const gitKeys = (0, filter_1.firedKeys)(input.filter.match(gitFiles));
return {
verdict: onlyInApi.count === 0 && onlyInGit.count === 0 ? 'match' : 'mismatch',
reason: null,
@@ -43122,7 +43119,9 @@ function compare(api, local) {
apiCount: api.size,
gitCount: local.size,
onlyInApi,
- onlyInGit
+ onlyInGit,
+ keysLost: missing(apiKeys, gitKeys),
+ keysGained: missing(gitKeys, apiKeys)
};
}
async function budgeted(work, ms) {
@@ -43136,11 +43135,11 @@ async function budgeted(work, ms) {
});
return Promise.race([work(controller.signal), expiry]).finally(() => clearTimeout(timer));
}
-async function compareWithMergeCommit(apiFiles, pr) {
- const api = new Set(apiFiles.map(f => f.filename));
+async function compareWithMergeCommit(input) {
+ const api = new Set(input.apiFiles.map(f => f.filename));
try {
- const gitFiles = await budgeted(async (signal) => localChangedFiles(pr, signal), BUDGET_MS);
- return compare(api, new Set(gitFiles));
+ const gitFiles = await budgeted(async (signal) => localChangedFiles(input.pr, signal), BUDGET_MS);
+ return compare(input, api, gitFiles);
}
catch (error) {
return {
@@ -43150,15 +43149,16 @@ async function compareWithMergeCommit(apiFiles, pr) {
apiCount: api.size,
gitCount: null,
onlyInApi: { count: 0, sample: [] },
- onlyInGit: { count: 0, sample: [] }
+ onlyInGit: { count: 0, sample: [] },
+ keysLost: [],
+ keysGained: []
};
}
}
-// Without this the only record of a divergence is a log line in one job of one run,
-// which is unreadable at the volume that makes the comparison worth running.
-async function capture(apiKey, result, pr, durationMs) {
+async function capture(apiKey, input, result, durationMs) {
var _a;
const repo = process.env.GITHUB_REPOSITORY || null;
+ const pr = input.pr;
const properties = {
repo,
verdict: result.verdict,
@@ -43170,18 +43170,18 @@ async function capture(apiKey, result, pr, durationMs) {
only_in_api_count: result.onlyInApi.count,
only_in_git: result.onlyInGit.sample,
only_in_git_count: result.onlyInGit.count,
- // pulls/{n}/files truncates silently, so record both sides of the tell: what the
- // API returned, and what the pull request payload says it should have been. The
- // count has to come from the payload, because `api_count` counts a rename twice:
- // the API path expands each renamed row into an add plus a delete.
- api_truncated: pr.changed_files >= API_FILE_CAP,
+ selection_changed: result.keysLost.length > 0 || result.keysGained.length > 0,
+ keys_lost: result.keysLost,
+ keys_gained: result.keysGained,
+ // `pr_changed_files` reads stale on a pull request whose base moved, so it is
+ // recorded beside the API's own row count rather than used as the truncation tell.
+ api_rows: input.apiRows,
+ api_truncated: input.apiTruncated,
pr_changed_files: pr.changed_files,
pr_number: pr.number,
head_sha: pr.head.sha,
head_ref: pr.head.ref,
base_ref: pr.base.ref,
- // Queue branches carry the cumulative batch diff and page far more than a human
- // pull request, so they are the population worth reading separately.
branch_class: pr.head.ref.startsWith('trunk-merge/') ? 'trunk-merge' : 'pull-request',
is_fork: ((_a = pr.head.repo) === null || _a === void 0 ? void 0 : _a.full_name) !== repo,
duration_ms: durationMs,
@@ -43199,7 +43199,6 @@ async function capture(apiKey, result, pr, durationMs) {
distinct_id: repo || 'paths-filter-shadow',
properties
}),
- // Whatever the comparison did not spend, so the step's ceiling stays the budget.
signal: AbortSignal.timeout(Math.max(CAPTURE_FLOOR_MS, BUDGET_MS - durationMs))
});
if (!res.ok) {
@@ -43212,18 +43211,15 @@ function summarize(result) {
}
if (result.verdict === 'mismatch') {
return (`MISMATCH api=${result.apiCount} git=${result.gitCount} ` +
- `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)}`);
+ `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)} ` +
+ `keysLost=${JSON.stringify(result.keysLost)} keysGained=${JSON.stringify(result.keysGained)}`);
}
return `match (${result.apiCount} files)`;
}
-// Never throws: the filter's real answer is already computed by the time this runs,
-// so nothing here is worth failing a CI job over.
-//
-// The token gates the comparison itself, not just the capture. Every workflow that
-// detects changes runs this action, so a comparison whose result cannot be recorded
-// is a merge-ref fetch on the critical path of a gate job in exchange for a log line
-// nobody reads. Fork pull requests get no secrets, so they take this path too.
-async function report(apiFiles, pr) {
+// Never throws: the filter's real answer is already computed by the time this runs. The
+// token gates the comparison itself, so a run that cannot record its result does not pay
+// for a merge-ref fetch. Fork pull requests get no secrets and take that path too.
+async function report(input) {
const apiKey = process.env.PATHS_FILTER_SHADOW_POSTHOG_TOKEN;
if (!apiKey) {
return;
@@ -43231,12 +43227,12 @@ async function report(apiFiles, pr) {
try {
core.startGroup('Shadow: merge-commit change detection');
const startedAt = Date.now();
- const result = await compareWithMergeCommit(apiFiles, pr);
+ const result = await compareWithMergeCommit(input);
const durationMs = Date.now() - startedAt;
- // core.info even for a mismatch: a warning becomes an annotation on the run summary
- // and the checks page, which reads as a problem with the pull request.
+ // core.info even for a mismatch, because a warning becomes an annotation on the
+ // checks page and reads as a problem with the pull request.
core.info(`shadow: ${summarize(result)} in ${durationMs}ms`);
- await capture(apiKey, result, pr, durationMs).catch(error => {
+ await capture(apiKey, input, result, durationMs).catch(error => {
core.info(`shadow: capture skipped (${messageOf(error)})`);
});
}
diff --git a/.github/actions/paths-filter/src/filter.ts b/.github/actions/paths-filter/src/filter.ts
index 2e100b834ecc..b29f3b5de6fd 100644
--- a/.github/actions/paths-filter/src/filter.ts
+++ b/.github/actions/paths-filter/src/filter.ts
@@ -38,6 +38,12 @@ export interface FilterResults {
[key: string]: File[]
}
+// A key gates a job on whether any file matched it, so its answer is `length > 0` and
+// nothing finer. Both the action's outputs and the shadow comparison read it through here.
+export function firedKeys(results: FilterResults): Set<string> {
+ return new Set(Object.keys(results).filter(key => results[key].length > 0))
+}
+
export class Filter {
rules: {[key: string]: FilterRuleItem[]} = {}
diff --git a/.github/actions/paths-filter/src/main.ts b/.github/actions/paths-filter/src/main.ts
index cec7f6628895..df01def7e538 100644
--- a/.github/actions/paths-filter/src/main.ts
+++ b/.github/actions/paths-filter/src/main.ts
@@ -4,7 +4,7 @@ import * as github from '@actions/github'
import {GetResponseDataTypeFromEndpointMethod} from '@octokit/types'
import {PullRequest, PushEvent} from '@octokit/webhooks-types'
-import {Filter, FilterResults} from './filter'
+import {Filter, FilterResults, firedKeys} from './filter'
import {File, ChangeStatus} from './file'
import * as git from './git'
import * as shadow from './shadow'
@@ -34,10 +34,13 @@ async function run(): Promise<void> {
}
const filter = new Filter(filtersYaml)
- const files = await getChangedFiles(token, base, ref, initialFetchDepth)
+ const {files, api} = await getChangedFiles(token, base, ref, initialFetchDepth)
core.info(`Detected ${files.length} changed files`)
const results = filter.match(files)
exportResults(results, listFiles)
+ if (api) {
+ await shadow.report({filter, apiFiles: files, apiResults: results, ...api})
+ }
} catch (error) {
core.setFailed(getErrorMessage(error))
}
@@ -59,14 +62,27 @@ function getConfigFileContent(configPath: string): string {
return fs.readFileSync(configPath, {encoding: 'utf8'})
}
-async function getChangedFiles(token: string, base: string, ref: string, initialFetchDepth: number): Promise<File[]> {
+// `api` is present only when the list came from the pull request files API, and carries
+// what the shadow comparison needs to describe that call. The shadow runs from `run()`,
+// which already holds the filter and its results, so detection stays free of it.
+interface ChangedFiles {
+ files: File[]
+ api?: {apiRows: number; apiTruncated: boolean; pr: PullRequest}
+}
+
+async function getChangedFiles(
+ token: string,
+ base: string,
+ ref: string,
+ initialFetchDepth: number
+): Promise<ChangedFiles> {
// if base is 'HEAD' only local uncommitted changes will be detected
// This is the simplest case as we don't need to fetch more commits or evaluate current/before refs
if (base === git.HEAD) {
if (ref) {
core.warning(`'ref' input parameter is ignored when 'base' is set to HEAD`)
}
- return await git.getChangesOnHead()
+ return {files: await git.getChangesOnHead()}
}
switch (github.context.eventName) {
@@ -84,9 +100,8 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
}
const pr = github.context.payload.pull_request as PullRequest
if (token) {
- const apiFiles = await getChangedFilesFromApi(token, pr)
- await shadow.report(apiFiles, pr)
- return apiFiles
+ const {files, apiRows, apiTruncated} = await getChangedFilesFromApi(token, pr)
+ return {files, api: {apiRows, apiTruncated, pr}}
}
if (github.context.eventName === 'pull_request_target') {
// pull_request_target is executed in context of base branch and GITHUB_SHA points to last commit in base branch
@@ -98,11 +113,11 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
const baseSha = github.context.payload.pull_request?.base.sha
const defaultBranch = github.context.payload.repository?.default_branch
const currentRef = await git.getCurrentRef()
- return await git.getChanges(base || baseSha || defaultBranch, currentRef)
+ return {files: await git.getChanges(base || baseSha || defaultBranch, currentRef)}
}
}
- return getChangedFilesFromGit(base, ref, initialFetchDepth)
+ return {files: await getChangedFilesFromGit(base, ref, initialFetchDepth)}
}
async function getChangedFilesFromGit(base: string, head: string, initialFetchDepth: number): Promise<File[]> {
@@ -167,13 +182,21 @@ async function getChangedFilesFromGit(base: string, head: string, initialFetchDe
return await git.getChangesSinceMergeBase(base, head, initialFetchDepth)
}
+// The API truncates at this many rows and says nothing when it does.
+const API_FILE_CAP = 3000
+
// Uses github REST api to get list of files changed in PR
-async function getChangedFilesFromApi(token: string, pullRequest: PullRequest): Promise<File[]> {
+// Truncation is judged on API rows, not on `files`, which expands a rename into two.
+async function getChangedFilesFromApi(
+ token: string,
+ pullRequest: PullRequest
+): Promise<{files: File[]; apiRows: number; apiTruncated: boolean}> {
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`)
try {
const client = github.getOctokit(token)
const per_page = 100
const files: File[] = []
+ let apiRows = 0
core.info(`Invoking listFiles(pull_number: ${pullRequest.number}, per_page: ${per_page})`)
for await (const response of client.paginate.iterator(
@@ -190,6 +213,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
core.info(`Received ${response.data.length} items`)
for (const row of response.data as GetResponseDataTypeFromEndpointMethod<typeof client.rest.pulls.listFiles>) {
+ apiRows++
core.info(`[${row.status}] ${row.filename}`)
// There's no obvious use-case for detection of renames
// Therefore we treat it as if rename detection in git diff was turned off.
@@ -215,7 +239,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
}
}
- return files
+ return {files, apiRows, apiTruncated: apiRows >= API_FILE_CAP}
} finally {
core.endGroup()
}
@@ -223,12 +247,11 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequest):
function exportResults(results: FilterResults, format: ExportFormat): void {
core.info('Results:')
- const changes = []
+ const fired = firedKeys(results)
for (const [key, files] of Object.entries(results)) {
- const value = files.length > 0
+ const value = fired.has(key)
core.startGroup(`Filter ${key} = ${value}`)
- if (files.length > 0) {
- changes.push(key)
+ if (value) {
core.info('Matching files:')
for (const file of files) {
core.info(`${file.filename} [${file.status}]`)
@@ -247,7 +270,7 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
}
if (results['changes'] === undefined) {
- const changesJson = JSON.stringify(changes)
+ const changesJson = JSON.stringify([...fired])
core.info(`Changes output set to ${changesJson}`)
core.setOutput('changes', changesJson)
} else {
diff --git a/.github/actions/paths-filter/src/shadow.ts b/.github/actions/paths-filter/src/shadow.ts
index abcfcb3b975e..95200462c4c1 100644
--- a/.github/actions/paths-filter/src/shadow.ts
+++ b/.github/actions/paths-filter/src/shadow.ts
@@ -6,45 +6,33 @@ import * as core from '@actions/core'
import {PullRequest} from '@octokit/webhooks-types'
import {File} from './file'
+import {Filter, FilterResults, firedKeys} from './filter'
+import {parseGitDiffOutput} from './git'
-// Compares the API's changed-file list against the same list derived locally from
-// the pull request's merge commit, and reports disagreement without acting on it.
-// The API result stays authoritative, so a wrong local answer can only produce a
-// log line. Removing the API call later is only safe once this has run quiet
-// across the shapes no offline sample can reach: very large diffs, and ones GitHub
-// has not finished computing a merge ref for.
-//
-// Detecting changes from `base.sha..HEAD` instead reports every commit the branch
-// picked up when the base was merged into it as the pull request's own work, which
-// is wrong by thousands of files on a branch that has taken master in. The merge
-// commit's first parent is the base GitHub actually merged against, so
-// `HEAD^1..HEAD` is the pull request's own changes and matches the API.
+// Compares the API's changed-file list against the same list derived from the pull
+// request's merge commit, and reports disagreement without acting on it. The API
+// result stays authoritative, so a wrong local answer can only produce a log line.
const MERGE_REF_FETCH_DEPTH = 2
const POSTHOG_HOST = 'https://us.i.posthog.com'
const EVENT_NAME = 'paths_filter_shadow_compared'
// A change-detection job is on the critical path of every workflow, so the comparison
-// and the capture that follows it share one wall-clock budget, and give up rather than
-// holding the job to its timeout-minutes. The git-level low-speed settings cover a
-// stalled transfer; the budget covers everything else.
+// and its capture share one wall-clock budget rather than holding the job to its
+// timeout-minutes.
const BUDGET_MS = 20000
const CAPTURE_FLOOR_MS = 500
const LIST_CAP = 50
-// A queue branch carries the cumulative batch diff, so the path list can be far larger
-// than a human pull request's. execFile's 1 MB default would fail those as a diff error,
-// which drops the population the comparison most needs to measure.
+// A queue branch carries the cumulative batch diff, which execFile's 1 MB default would
+// fail as a diff error.
const MAX_GIT_OUTPUT_BYTES = 64 * 1024 * 1024
const DETAIL_CAP = 200
-// The API caps pulls/{n}/files at this many entries and says nothing when it truncates.
-const API_FILE_CAP = 3000
-
type Verdict = 'match' | 'mismatch' | 'unavailable'
-// A closed set, because this is the field the comparison is grouped by once the events
-// land. Git's own words go in `detail`, which is free text and unbounded.
+// Closed, because this is the field the events are grouped by. Git's own words go in
+// `detail`, which is unbounded.
type Reason =
| 'no-scratch-repo'
| 'no-origin-url'
@@ -74,6 +62,17 @@ interface ShadowResult {
gitCount: number | null
onlyInApi: Difference
onlyInGit: Difference
+ keysLost: string[]
+ keysGained: string[]
+}
+
+export interface ShadowInput {
+ filter: Filter
+ apiFiles: File[]
+ apiResults: FilterResults
+ apiRows: number
+ apiTruncated: boolean
+ pr: PullRequest
}
interface GitResult {
@@ -82,21 +81,16 @@ interface GitResult {
err: string
}
-// Every git call that reads or writes history names the scratch repository. `--depth`
-// and `--filter` rewrite `.git/shallow` and the promisor config of whatever repository
-// they run in, and steps later in the same job read history from the workspace checkout:
-// ci-dagster and ci-e2e-playwright resolve `git merge-base HEAD^2 origin/<base>` after
-// this action returns, and an empty merge base there silently drops their schema cache.
+// `--depth` and `--filter` rewrite `.git/shallow` and the promisor config of whatever
+// repository they run in, so every call names the scratch repository. ci-dagster and
+// ci-e2e-playwright read history from the workspace checkout after this action returns.
async function git(gitDir: string, args: string[], signal: AbortSignal): Promise<GitResult> {
return run(['--git-dir', gitDir, ...args], signal)
}
-// The signal is what makes the wall-clock budget real. `@actions/exec` gives no handle
-// on the child process, so a fetch the budget gave up on keeps running and holds the
-// action's process open until it finishes, past the budget it was supposed to obey.
-//
-// stdout is returned raw. A caller that reads a path list must not trim it, because a
-// tracked path can begin with a space, and that path sorts first in the -z output.
+// execFile rather than `@actions/exec`, which gives no handle on the child process, so a
+// fetch the budget gave up on would hold the action open until it finished. stdout is
+// returned raw because a tracked path can begin with a space.
async function run(args: string[], signal: AbortSignal): Promise<GitResult> {
return new Promise(resolve => {
execFile('git', args, {signal, maxBuffer: MAX_GIT_OUTPUT_BYTES}, (error, stdout, stderr) => {
@@ -113,6 +107,10 @@ function messageOf(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
+function missing(from: Set<string>, against: Set<string>): string[] {
+ return [...from].filter(key => !against.has(key)).sort()
+}
+
async function scratchRepo(signal: AbortSignal): Promise<string> {
const gitDir = path.join(process.env.RUNNER_TEMP || os.tmpdir(), 'paths-filter-shadow.git')
const init = await run(['init', '--bare', '--quiet', gitDir], signal)
@@ -122,9 +120,8 @@ async function scratchRepo(signal: AbortSignal): Promise<string> {
return gitDir
}
-// The workspace remote carries no credentials of its own: actions/checkout keeps the
-// token in an http.extraheader the scratch repository does not inherit. A private
-// remote therefore reports unavailable rather than comparing against a partial fetch.
+// actions/checkout keeps the token in an http.extraheader the scratch repository does not
+// inherit, so a private remote reports unavailable rather than comparing a partial fetch.
function originUrl(): string {
const server = process.env.GITHUB_SERVER_URL
const repo = process.env.GITHUB_REPOSITORY
@@ -134,10 +131,7 @@ function originUrl(): string {
return `${server}/${repo}`
}
-// The merge ref is not guaranteed to be present or current: GitHub recomputes it
-// asynchronously after a push. Requiring the second parent to equal the head SHA
-// rejects a stale ref rather than reading it as this pull request's changes.
-async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<string[]> {
+async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<File[]> {
const gitDir = await scratchRepo(signal)
const fetched = await git(
@@ -164,24 +158,23 @@ async function localChangedFiles(pr: PullRequest, signal: AbortSignal): Promise<
if (head.code !== 0) {
throw new Unavailable('no-second-parent', firstLine(head.err))
}
+ // GitHub recomputes the merge ref asynchronously after a push, so a ref whose second
+ // parent is not the head SHA describes an earlier push.
const headSha = head.out.trim()
if (headSha !== pr.head.sha) {
throw new Unavailable('stale-merge-ref', `^2=${headSha.slice(0, 8)}, head=${pr.head.sha.slice(0, 8)}`)
}
- // --no-renames so a rename arrives as a delete plus an add, which is the shape
- // the API path builds by hand from `previous_filename`. -z because git quotes a
- // path holding a newline or a non-ASCII byte in the default format.
- const diff = await git(gitDir, ['diff', '--no-renames', '--name-only', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal)
+ // The same flags the action's own git path uses, so the comparison measures what
+ // dropping the API call would select. --no-renames matches the add-plus-delete shape
+ // the API path builds from `previous_filename`.
+ const diff = await git(gitDir, ['diff', '--no-renames', '--name-status', '-z', 'FETCH_HEAD^1', 'FETCH_HEAD'], signal)
if (diff.code !== 0) {
throw new Unavailable('diff-failed', firstLine(diff.err))
}
- return diff.out.split('\0').filter(Boolean)
+ return parseGitDiffOutput(diff.out)
}
-// A queue branch can differ by thousands of paths, which is neither readable in a log
-// line nor worth carrying as an event property. The count answers how far apart the two
-// answers are, and the sample answers what kind of path is involved.
function difference(from: Set<string>, against: Set<string>): Difference {
const sample: string[] = []
let count = 0
@@ -197,9 +190,12 @@ function difference(from: Set<string>, against: Set<string>): Difference {
return {count, sample}
}
-function compare(api: Set<string>, local: Set<string>): ShadowResult {
+function compare(input: ShadowInput, api: Set<string>, gitFiles: File[]): ShadowResult {
+ const local = new Set(gitFiles.map(f => f.filename))
const onlyInApi = difference(api, local)
const onlyInGit = difference(local, api)
+ const apiKeys = firedKeys(input.apiResults)
+ const gitKeys = firedKeys(input.filter.match(gitFiles))
return {
verdict: onlyInApi.count === 0 && onlyInGit.count === 0 ? 'match' : 'mismatch',
reason: null,
@@ -207,7 +203,9 @@ function compare(api: Set<string>, local: Set<string>): ShadowResult {
apiCount: api.size,
gitCount: local.size,
onlyInApi,
- onlyInGit
+ onlyInGit,
+ keysLost: missing(apiKeys, gitKeys),
+ keysGained: missing(gitKeys, apiKeys)
}
}
@@ -223,11 +221,11 @@ async function budgeted<T>(work: (signal: AbortSignal) => Promise<T>, ms: number
return Promise.race([work(controller.signal), expiry]).finally(() => clearTimeout(timer))
}
-export async function compareWithMergeCommit(apiFiles: File[], pr: PullRequest): Promise<ShadowResult> {
- const api = new Set(apiFiles.map(f => f.filename))
+export async function compareWithMergeCommit(input: ShadowInput): Promise<ShadowResult> {
+ const api = new Set(input.apiFiles.map(f => f.filename))
try {
- const gitFiles = await budgeted(async signal => localChangedFiles(pr, signal), BUDGET_MS)
- return compare(api, new Set(gitFiles))
+ const gitFiles = await budgeted(async signal => localChangedFiles(input.pr, signal), BUDGET_MS)
+ return compare(input, api, gitFiles)
} catch (error) {
return {
verdict: 'unavailable',
@@ -236,15 +234,16 @@ export async function compareWithMergeCommit(apiFiles: File[], pr: PullRequest):
apiCount: api.size,
gitCount: null,
onlyInApi: {count: 0, sample: []},
- onlyInGit: {count: 0, sample: []}
+ onlyInGit: {count: 0, sample: []},
+ keysLost: [],
+ keysGained: []
}
}
}
-// Without this the only record of a divergence is a log line in one job of one run,
-// which is unreadable at the volume that makes the comparison worth running.
-async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, durationMs: number): Promise<void> {
+async function capture(apiKey: string, input: ShadowInput, result: ShadowResult, durationMs: number): Promise<void> {
const repo = process.env.GITHUB_REPOSITORY || null
+ const pr = input.pr
const properties = {
repo,
verdict: result.verdict,
@@ -256,18 +255,18 @@ async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, du
only_in_api_count: result.onlyInApi.count,
only_in_git: result.onlyInGit.sample,
only_in_git_count: result.onlyInGit.count,
- // pulls/{n}/files truncates silently, so record both sides of the tell: what the
- // API returned, and what the pull request payload says it should have been. The
- // count has to come from the payload, because `api_count` counts a rename twice:
- // the API path expands each renamed row into an add plus a delete.
- api_truncated: pr.changed_files >= API_FILE_CAP,
+ selection_changed: result.keysLost.length > 0 || result.keysGained.length > 0,
+ keys_lost: result.keysLost,
+ keys_gained: result.keysGained,
+ // `pr_changed_files` reads stale on a pull request whose base moved, so it is
+ // recorded beside the API's own row count rather than used as the truncation tell.
+ api_rows: input.apiRows,
+ api_truncated: input.apiTruncated,
pr_changed_files: pr.changed_files,
pr_number: pr.number,
head_sha: pr.head.sha,
head_ref: pr.head.ref,
base_ref: pr.base.ref,
- // Queue branches carry the cumulative batch diff and page far more than a human
- // pull request, so they are the population worth reading separately.
branch_class: pr.head.ref.startsWith('trunk-merge/') ? 'trunk-merge' : 'pull-request',
is_fork: pr.head.repo?.full_name !== repo,
duration_ms: durationMs,
@@ -285,7 +284,6 @@ async function capture(apiKey: string, result: ShadowResult, pr: PullRequest, du
distinct_id: repo || 'paths-filter-shadow',
properties
}),
- // Whatever the comparison did not spend, so the step's ceiling stays the budget.
signal: AbortSignal.timeout(Math.max(CAPTURE_FLOOR_MS, BUDGET_MS - durationMs))
})
if (!res.ok) {
@@ -300,20 +298,17 @@ function summarize(result: ShadowResult): string {
if (result.verdict === 'mismatch') {
return (
`MISMATCH api=${result.apiCount} git=${result.gitCount} ` +
- `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)}`
+ `onlyInApi=${JSON.stringify(result.onlyInApi.sample)} onlyInGit=${JSON.stringify(result.onlyInGit.sample)} ` +
+ `keysLost=${JSON.stringify(result.keysLost)} keysGained=${JSON.stringify(result.keysGained)}`
)
}
return `match (${result.apiCount} files)`
}
-// Never throws: the filter's real answer is already computed by the time this runs,
-// so nothing here is worth failing a CI job over.
-//
-// The token gates the comparison itself, not just the capture. Every workflow that
-// detects changes runs this action, so a comparison whose result cannot be recorded
-// is a merge-ref fetch on the critical path of a gate job in exchange for a log line
-// nobody reads. Fork pull requests get no secrets, so they take this path too.
-export async function report(apiFiles: File[], pr: PullRequest): Promise<void> {
+// Never throws: the filter's real answer is already computed by the time this runs. The
+// token gates the comparison itself, so a run that cannot record its result does not pay
+// for a merge-ref fetch. Fork pull requests get no secrets and take that path too.
+export async function report(input: ShadowInput): Promise<void> {
const apiKey = process.env.PATHS_FILTER_SHADOW_POSTHOG_TOKEN
if (!apiKey) {
return
@@ -321,14 +316,14 @@ export async function report(apiFiles: File[], pr: PullRequest): Promise<void> {
try {
core.startGroup('Shadow: merge-commit change detection')
const startedAt = Date.now()
- const result = await compareWithMergeCommit(apiFiles, pr)
+ const result = await compareWithMergeCommit(input)
const durationMs = Date.now() - startedAt
- // core.info even for a mismatch: a warning becomes an annotation on the run summary
- // and the checks page, which reads as a problem with the pull request.
+ // core.info even for a mismatch, because a warning becomes an annotation on the
+ // checks page and reads as a problem with the pull request.
core.info(`shadow: ${summarize(result)} in ${durationMs}ms`)
- await capture(apiKey, result, pr, durationMs).catch(error => {
+ await capture(apiKey, input, result, durationMs).catch(error => {
core.info(`shadow: capture skipped (${messageOf(error)})`)
})
} catch (error) {