apify-test-tools 0.10.2-beta.4 → 0.10.2-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/checkout-restore-dependencies/action.yaml +43 -3
- package/.github/cli/apify-test-tools.mjs +125 -127
- package/.github/scripts/run-with-apify-tokens.mjs +1 -1
- package/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml +7 -0
- package/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +4 -1
- package/README.md +72 -73
- package/bin/affected-actors.ts +132 -91
- package/bin/build.ts +0 -2
- package/bin/diff-changes.ts +7 -6
- package/bin/diff-json-schema.ts +5 -6
- package/bin/git.ts +21 -55
- package/bin/main.ts +7 -97
- package/bin/slack.ts +14 -27
- package/bin/types.ts +6 -0
- package/dist/bin/affected-actors.d.ts +23 -22
- package/dist/bin/affected-actors.d.ts.map +1 -1
- package/dist/bin/affected-actors.js +108 -60
- package/dist/bin/affected-actors.js.map +1 -1
- package/dist/bin/build.d.ts +0 -1
- package/dist/bin/build.d.ts.map +1 -1
- package/dist/bin/build.js +0 -2
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/diff-changes.d.ts +4 -3
- package/dist/bin/diff-changes.d.ts.map +1 -1
- package/dist/bin/diff-changes.js +4 -4
- package/dist/bin/diff-changes.js.map +1 -1
- package/dist/bin/diff-json-schema.d.ts +2 -2
- package/dist/bin/diff-json-schema.d.ts.map +1 -1
- package/dist/bin/diff-json-schema.js +1 -4
- package/dist/bin/diff-json-schema.js.map +1 -1
- package/dist/bin/git.d.ts +6 -9
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +20 -48
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/main.js +7 -77
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +2 -7
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +12 -18
- package/dist/bin/slack.js.map +1 -1
- package/dist/bin/types.d.ts +5 -0
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/test/bundle/cli-bundle.test.js +14 -16
- package/dist/test/bundle/cli-bundle.test.js.map +1 -1
- package/dist/test/e2e/cli-bundle.e2e.test.js +22 -63
- package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -1
- package/dist/test/e2e/git-build-release.e2e.test.d.ts +2 -0
- package/dist/test/e2e/git-build-release.e2e.test.d.ts.map +1 -0
- package/dist/test/e2e/git-build-release.e2e.test.js +87 -0
- package/dist/test/e2e/git-build-release.e2e.test.js.map +1 -0
- package/dist/test/e2e/helpers.d.ts +37 -0
- package/dist/test/e2e/helpers.d.ts.map +1 -0
- package/dist/test/e2e/helpers.js +57 -0
- package/dist/test/e2e/helpers.js.map +1 -0
- package/dist/test/unit/bin/affected-actors-cli.test.d.ts +2 -0
- package/dist/test/unit/bin/affected-actors-cli.test.d.ts.map +1 -0
- package/dist/test/unit/bin/affected-actors-cli.test.js +161 -0
- package/dist/test/unit/bin/affected-actors-cli.test.js.map +1 -0
- package/dist/test/unit/bin/affected-actors.test.js +65 -78
- package/dist/test/unit/bin/affected-actors.test.js.map +1 -1
- package/dist/test/unit/bin/build-cli.test.js +5 -13
- package/dist/test/unit/bin/build-cli.test.js.map +1 -1
- package/dist/test/unit/bin/compiled-cli.d.ts +6 -0
- package/dist/test/unit/bin/compiled-cli.d.ts.map +1 -0
- package/dist/test/unit/bin/compiled-cli.js +16 -0
- package/dist/test/unit/bin/compiled-cli.js.map +1 -0
- package/dist/test/unit/bin/diff-changes.test.js +55 -55
- package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
- package/dist/test/unit/bin/diff.test.js +25 -28
- package/dist/test/unit/bin/diff.test.js.map +1 -1
- package/dist/test/unit/bin/git.test.js +29 -97
- package/dist/test/unit/bin/git.test.js.map +1 -1
- package/dist/test/unit/bin/slack.test.js +6 -27
- package/dist/test/unit/bin/slack.test.js.map +1 -1
- package/dist/test/unit/should-built-and-test.test.js +18 -21
- package/dist/test/unit/should-built-and-test.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/test/bundle/cli-bundle.test.ts +14 -24
- package/test/e2e/cli-bundle.e2e.test.ts +39 -84
- package/test/e2e/git-build-release.e2e.test.ts +113 -0
- package/test/e2e/helpers.ts +82 -0
- package/test/unit/bin/affected-actors-cli.test.ts +193 -0
- package/test/unit/bin/affected-actors.test.ts +83 -85
- package/test/unit/bin/build-cli.test.ts +6 -12
- package/test/unit/bin/compiled-cli.ts +17 -0
- package/test/unit/bin/diff-changes.test.ts +55 -55
- package/test/unit/bin/diff.test.ts +25 -28
- package/test/unit/bin/git.test.ts +37 -120
- package/test/unit/bin/slack.test.ts +6 -30
- package/test/unit/should-built-and-test.test.ts +19 -22
package/bin/affected-actors.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { type ChangedActors, getChangedActors } from './diff-changes.js';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
findCommitSha,
|
|
4
4
|
getChangedFilesBetween,
|
|
5
5
|
getChangelogAdditions,
|
|
6
|
-
getCommits,
|
|
7
6
|
getCommitsBetween,
|
|
8
|
-
|
|
7
|
+
getMergeBase,
|
|
9
8
|
resolveCommitSha,
|
|
10
9
|
resolveReleaseBaseCommit,
|
|
11
10
|
} from './git.js';
|
|
12
11
|
import { logger } from './logger.js';
|
|
13
|
-
import type { ActorConfig, Commit } from './types.js';
|
|
12
|
+
import type { ActorConfig, Commit, GitRange } from './types.js';
|
|
14
13
|
import { readConfigFile } from './utils/config/load-config.js';
|
|
15
14
|
|
|
16
15
|
// The range always ends at the checked-out commit: check out what you want to inspect
|
|
17
16
|
const HEAD = 'HEAD';
|
|
18
17
|
|
|
19
18
|
interface AffectedActorsOptions {
|
|
20
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Base usually points to the master branch
|
|
21
|
+
* Only what HEAD changes compared to base counts, like `git diff base...HEAD` or GitHub's "Files changed" tab:
|
|
22
|
+
* the branch's own changes, not what it merged in from base.
|
|
23
|
+
*/
|
|
21
24
|
base?: string;
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
24
|
-
* ignored when it isn't
|
|
26
|
+
* With `base` it's the last validated commit of the branch: Actors that didn't change after it are left out.
|
|
27
|
+
* It's ignored when it is HEAD (a rerun) or isn't in the local history. Without `base` everything after it
|
|
28
|
+
* counts, and it must be an ancestor of HEAD (e.g. the last release).
|
|
25
29
|
*/
|
|
26
30
|
since?: string;
|
|
27
31
|
/** Glob relative to the repo root. Matching files count as changes even when .dockerignore lists them. */
|
|
@@ -30,77 +34,113 @@ interface AffectedActorsOptions {
|
|
|
30
34
|
ignore: string[];
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
/** The JSON document `get-affected-actors` prints. Versioned, since other commands and workflows consume it. */
|
|
33
38
|
interface AffectedActors {
|
|
34
|
-
|
|
39
|
+
version: 1;
|
|
40
|
+
head: string;
|
|
41
|
+
/** The commits, changed files and changelog describe the whole range, `--since` with `--base` only narrows the Actors. */
|
|
35
42
|
commits: Commit[];
|
|
36
43
|
changedFiles: string[];
|
|
37
44
|
changelog: string | null;
|
|
38
|
-
/**
|
|
39
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Actors with at least one functional change. They need a new build and tests. Only the names: the config file
|
|
47
|
+
* stays the source of truth for the rest.
|
|
48
|
+
*/
|
|
49
|
+
functionallyChangedActors: { actorFullName: string }[];
|
|
40
50
|
/** Actors whose changes are all cosmetic (README, CHANGELOG, cosmetic .actor JSON). They only need a release build. */
|
|
41
|
-
cosmeticallyChangedActors:
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface CommitRange {
|
|
45
|
-
commits: Commit[];
|
|
46
|
-
fromRef: string;
|
|
47
|
-
toRef: string;
|
|
51
|
+
cosmeticallyChangedActors: { actorFullName: string }[];
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
const getBranchRange = async (base: string, since: string | undefined): Promise<CommitRange> => {
|
|
52
|
-
const commits = await getCommits({ sourceBranch: HEAD, targetBranch: base, baseCommit: since });
|
|
53
|
-
return { commits, fromRef: `${commits[0].sha}~`, toRef: commits[commits.length - 1].sha };
|
|
54
|
-
};
|
|
54
|
+
const names = (configs: ActorConfig[]) => configs.map(({ actorFullName }) => ({ actorFullName }));
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
const
|
|
58
|
-
const sinceSha = await
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/** The branch's last validated commit, unless it can't narrow anything down. */
|
|
57
|
+
const findValidatedSha = async (since: string, headSha: string): Promise<string | undefined> => {
|
|
58
|
+
const sinceSha = await findCommitSha(since);
|
|
59
|
+
if (!sinceSha) {
|
|
60
|
+
logger.info(
|
|
61
|
+
`Last validated commit ${since} is not in the local history (force-push?), checking the whole branch`,
|
|
62
|
+
);
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (sinceSha === headSha) {
|
|
66
|
+
logger.info('Last validated commit is HEAD, so this is a rerun: checking the whole branch from scratch');
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return sinceSha;
|
|
61
70
|
};
|
|
62
71
|
|
|
63
72
|
/**
|
|
64
|
-
* This is
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
73
|
+
* This is Juan's magical algorithm where we need just 2 git diffs to determine functional changes on Actors.
|
|
74
|
+
*
|
|
75
|
+
* Naively, we could just check branch HEAD changes vs base or parent of first commit and be done but
|
|
76
|
+
* we do this jiu-jitsu code to apply 2 optimizations:
|
|
77
|
+
* 1. On our PR branch, we track last validated commit (since) that was tested and so we only need to test new commits.
|
|
78
|
+
* 2. We also merge changes from the base branch (usually master) and we can consider those already validated as well.
|
|
79
|
+
*
|
|
80
|
+
* But there is annoying problem: even if both our branch and base are validated, they could have novel interactions and
|
|
81
|
+
* we need to retest those.
|
|
82
|
+
*
|
|
83
|
+
* So we look at:
|
|
84
|
+
* 1. The changes introduced by our branch since the last validated commit (`since..HEAD`).
|
|
85
|
+
* 2. The changes introduced by the branch compared to the base branch (`base...HEAD`). The important part is that this
|
|
86
|
+
* diff does check the whole branch, discarding the last validated commit (since) so it checks those novel interactions problem.
|
|
87
|
+
*
|
|
88
|
+
* The magic is that both need to contain changes for an Actor to be retested:
|
|
89
|
+
* 1. If we have changes only in since..HEAD (and not in base...HEAD), it means those changes came from merging the base alone
|
|
90
|
+
* which is already validated and there were actually no real changes introduced by our branch alone.
|
|
91
|
+
* 2. If we have changes only in base...HEAD (and not in since..HEAD), it means there are no new changes on our branch
|
|
92
|
+
* since it was last validated. base...HEAD has changes that we already validated.
|
|
93
|
+
*
|
|
94
|
+
* This enables to simply do those 2 diffs for each Actor's context separately and only Actors that have changes
|
|
95
|
+
* in both diffs need to be retested.
|
|
70
96
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
97
|
+
* THIS ASSUMES BRANCH IS UP TO DATE WITH BASE WHEN IT MERGES, which we currently require. Only then is HEAD what lands on
|
|
98
|
+
* base, and base's commits validated. Otherwise what lands is HEAD combined with base's newer commits, which nobody
|
|
99
|
+
* tested, however the Actors are picked.
|
|
100
|
+
*
|
|
101
|
+
* In each example the branch's functional change to Actor A was validated at `since`, then one more push follows:
|
|
102
|
+
*
|
|
103
|
+
* Example scenarios:
|
|
104
|
+
* - Our own branch only: a commit changes A's README and B's code.
|
|
105
|
+
* `since..HEAD`: A cosmetic, B functional. `base...HEAD`: A and B functional.
|
|
106
|
+
* → A cosmetic, B functional: only B is tested, A's code is still the validated one.
|
|
107
|
+
* - Cosmetic merge: the branch merges base, which only changed READMEs and the CHANGELOG.
|
|
108
|
+
* `since..HEAD`: every Actor cosmetic (CHANGELOG counts for all). `base...HEAD`: A functional, since the merged
|
|
109
|
+
* files now match base and drop out of it.
|
|
110
|
+
* → A cosmetic, the other Actors left out: nothing is tested.
|
|
111
|
+
* - Functional merge: the branch merges base, which changed code of A and of C.
|
|
112
|
+
* `since..HEAD`: A and C functional. `base...HEAD`: A functional.
|
|
113
|
+
* → A functional, C left out: A is tested, since base's change can interact with the branch's, while C only has
|
|
114
|
+
* base's change, which base already validated.
|
|
75
115
|
*/
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
116
|
+
const intersectChangedInBranchVsSince = (branch: ChangedActors, sinceValidated: ChangedActors): ChangedActors => {
|
|
117
|
+
const narrowed: ChangedActors = { functional: [], cosmetic: [] };
|
|
118
|
+
// All checks are done for each Actor separately, that's cleanest and most accurate
|
|
119
|
+
for (const actor of [...branch.functional, ...branch.cosmetic]) {
|
|
120
|
+
// base...HEAD
|
|
121
|
+
const changedFunctionallyOnBranch = branch.functional.includes(actor);
|
|
122
|
+
// since..HEAD
|
|
123
|
+
const changedFunctionallySince = sinceValidated.functional.includes(actor);
|
|
124
|
+
|
|
125
|
+
// changedSince is used for release. Release cares also about cosmetic.
|
|
126
|
+
const changedSince = changedFunctionallySince || sinceValidated.cosmetic.includes(actor);
|
|
127
|
+
|
|
128
|
+
// Nothing changed since the last validation, so the branch's change to this Actor is already validated
|
|
129
|
+
if (!changedSince) continue;
|
|
82
130
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
testFilesGlob,
|
|
92
|
-
});
|
|
93
|
-
logger.info(
|
|
94
|
-
own.functional.length > 0
|
|
95
|
-
? `[MERGE-FROM-TARGET-OPTIMIZATION]: Branch has ${own.functional.length} functional changes, cannot optimize, we continue with full check`
|
|
96
|
-
: '[MERGE-FROM-TARGET-OPTIMIZATION]: Branch itself has no functional changes, skipping tests',
|
|
97
|
-
);
|
|
98
|
-
return own;
|
|
131
|
+
// As we said, only intersection counts as functional, otherwise it's cosmetic
|
|
132
|
+
if (changedFunctionallyOnBranch && changedFunctionallySince) {
|
|
133
|
+
narrowed.functional.push(actor);
|
|
134
|
+
} else {
|
|
135
|
+
narrowed.cosmetic.push(actor);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return narrowed;
|
|
99
139
|
};
|
|
100
140
|
|
|
101
141
|
/**
|
|
102
|
-
* Finds the Actors whose context changed in the given range. `base` selects the branch's own
|
|
103
|
-
* (a PR), `since` the
|
|
142
|
+
* Finds the Actors whose context changed in the given range. `base` selects the branch's own changes
|
|
143
|
+
* (a PR), `since` the changes after a known commit (a release, or the last validated commit of a PR).
|
|
104
144
|
*/
|
|
105
145
|
export const getAffectedActors = async ({
|
|
106
146
|
base,
|
|
@@ -115,43 +155,44 @@ export const getAffectedActors = async ({
|
|
|
115
155
|
throw new Error('Pass --base, --since, or both to select the commits to inspect.');
|
|
116
156
|
}
|
|
117
157
|
|
|
118
|
-
const headSha = await resolveCommitSha(HEAD);
|
|
119
|
-
const { commits, fromRef, toRef } = base ? await getBranchRange(base, since) : await getRangeSince(headSha, since!);
|
|
120
158
|
const actorConfigs = await readConfigFile({ actors, ignore });
|
|
159
|
+
const getChangedInRange = async (range: GitRange) => {
|
|
160
|
+
const changedFiles = await getChangedFilesBetween(range.fromRef, range.toRef);
|
|
161
|
+
return {
|
|
162
|
+
changedFiles,
|
|
163
|
+
changedActors: await getChangedActors({
|
|
164
|
+
filepathsChanged: changedFiles,
|
|
165
|
+
actorConfigs,
|
|
166
|
+
range,
|
|
167
|
+
testFilesGlob,
|
|
168
|
+
}),
|
|
169
|
+
};
|
|
170
|
+
};
|
|
121
171
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
headSha,
|
|
130
|
-
commits,
|
|
131
|
-
changedFiles,
|
|
132
|
-
changelog: await getChangelogAdditions(fromRef, toRef, changedFiles),
|
|
133
|
-
functionallyChangedActors: own && own.functional.length === 0 ? [] : changed.functional,
|
|
134
|
-
cosmeticallyChangedActors: own && own.functional.length + own.cosmetic.length === 0 ? [] : changed.cosmetic,
|
|
172
|
+
const headSha = await resolveCommitSha(HEAD);
|
|
173
|
+
const rangeVsBase: GitRange = {
|
|
174
|
+
// merge base = PR, release base = push to master (release)
|
|
175
|
+
fromRef: base ? await getMergeBase(base, HEAD) : await resolveReleaseBaseCommit(since!),
|
|
176
|
+
toRef: headSha,
|
|
135
177
|
};
|
|
136
|
-
};
|
|
137
178
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
headSha
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
179
|
+
// Falls back to rangeVsBase.fromRef when there's no (usable) last validated commit — same as
|
|
180
|
+
// intersecting the branch's changes with themselves, which is a no-op (see this function's docs).
|
|
181
|
+
const validatedSha = base && since ? await findValidatedSha(since, headSha) : undefined;
|
|
182
|
+
const sinceFromRef = validatedSha ?? rangeVsBase.fromRef;
|
|
183
|
+
|
|
184
|
+
const { changedFiles, changedActors: changedVsBase } = await getChangedInRange(rangeVsBase);
|
|
185
|
+
const { changedActors: changedSinceActors } = await getChangedInRange({ fromRef: sinceFromRef, toRef: headSha });
|
|
186
|
+
// See this function's docs to understand the algorithm: only intersection counts as functional, otherwise it's cosmetic.
|
|
187
|
+
const changedActors = intersectChangedInBranchVsSince(changedVsBase, changedSinceActors);
|
|
188
|
+
|
|
148
189
|
return {
|
|
149
190
|
version: 1,
|
|
150
191
|
head: headSha,
|
|
151
|
-
commits,
|
|
192
|
+
commits: await getCommitsBetween(rangeVsBase.fromRef, rangeVsBase.toRef),
|
|
152
193
|
changedFiles,
|
|
153
|
-
changelog,
|
|
154
|
-
functionallyChangedActors: names(
|
|
155
|
-
cosmeticallyChangedActors: names(
|
|
194
|
+
changelog: await getChangelogAdditions(rangeVsBase.fromRef, rangeVsBase.toRef, changedFiles),
|
|
195
|
+
functionallyChangedActors: names(changedActors.functional),
|
|
196
|
+
cosmeticallyChangedActors: names(changedActors.cosmetic),
|
|
156
197
|
};
|
|
157
198
|
};
|
package/bin/build.ts
CHANGED
|
@@ -14,8 +14,6 @@ type BuildPrActorOptions = {
|
|
|
14
14
|
|
|
15
15
|
// Fixed version number used to build from local source files, since there is no real version to track.
|
|
16
16
|
export const LOCAL_SOURCE_VERSION_NUMBER = '0.98';
|
|
17
|
-
// Version that build-for-test builds, so tests never touch the version users run
|
|
18
|
-
export const TEST_VERSION_NUMBER = '0.99';
|
|
19
17
|
// Stands for each Actor's default version: the one its default build tag points to
|
|
20
18
|
export const DEFAULT_VERSION_KEYWORD = 'default';
|
|
21
19
|
|
package/bin/diff-changes.ts
CHANGED
|
@@ -3,13 +3,14 @@ import picomatch from 'picomatch';
|
|
|
3
3
|
import { isCosmeticOnlyJsonSchemaChange } from './diff-json-schema.js';
|
|
4
4
|
import { type DockerIgnoreMatcher, loadDockerIgnore } from './dockerignore.js';
|
|
5
5
|
import { logger } from './logger.js';
|
|
6
|
-
import type { ActorConfig,
|
|
6
|
+
import type { ActorConfig, GitRange } from './types.js';
|
|
7
7
|
import { type RelativeDir, RelativeFile } from './utils/path/repo-relative.js';
|
|
8
8
|
|
|
9
9
|
interface ShouldBuildAndTestOptions {
|
|
10
10
|
filepathsChanged: string[];
|
|
11
11
|
actorConfigs: ActorConfig[];
|
|
12
|
-
|
|
12
|
+
/** The range the files changed in, to compare `.actor` JSON files across. */
|
|
13
|
+
range: GitRange;
|
|
13
14
|
// Glob relative to the repo root. Matching files count as changes even when .dockerignore lists them.
|
|
14
15
|
testFilesGlob?: string;
|
|
15
16
|
}
|
|
@@ -52,7 +53,7 @@ type FileChangeForActor =
|
|
|
52
53
|
const classifyFileChange = async (
|
|
53
54
|
changedFile: RelativeFile,
|
|
54
55
|
actorConfig: ActorConfig,
|
|
55
|
-
|
|
56
|
+
range: GitRange,
|
|
56
57
|
dockerIgnoreMatcher: DockerIgnoreMatcher,
|
|
57
58
|
isTestFile: (filePath: string) => boolean,
|
|
58
59
|
): Promise<FileChangeForActor> => {
|
|
@@ -91,7 +92,7 @@ const classifyFileChange = async (
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
if (lowercaseFilePath.endsWith('.json') && isUnderActorDotDir) {
|
|
94
|
-
const isCosmetic = await isCosmeticOnlyJsonSchemaChange(
|
|
95
|
+
const isCosmetic = await isCosmeticOnlyJsonSchemaChange(range, changedFile.path);
|
|
95
96
|
if (isCosmetic) return { impact: 'cosmetic', semanticallyVerified: true };
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -175,7 +176,7 @@ export interface ChangedActors {
|
|
|
175
176
|
export const getChangedActors = async ({
|
|
176
177
|
filepathsChanged,
|
|
177
178
|
actorConfigs,
|
|
178
|
-
|
|
179
|
+
range,
|
|
179
180
|
testFilesGlob,
|
|
180
181
|
}: ShouldBuildAndTestOptions): Promise<ChangedActors> => {
|
|
181
182
|
const actorsChangedMap = new Map<string, ActorChangeEntry>();
|
|
@@ -192,7 +193,7 @@ export const getChangedActors = async ({
|
|
|
192
193
|
continue;
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
const change = await classifyFileChange(filePath, actorConfig,
|
|
196
|
+
const change = await classifyFileChange(filePath, actorConfig, range, dockerIgnoreMatcher, isTestFile);
|
|
196
197
|
if (change.impact !== 'outside-context' && isTestFile(originalFilePath)) {
|
|
197
198
|
testFilesInContext.add(originalFilePath);
|
|
198
199
|
}
|
package/bin/diff-json-schema.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from './logger.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GitRange } from './types.js';
|
|
3
3
|
import { runGitCommand } from './utils.js';
|
|
4
4
|
|
|
5
5
|
const COSMETIC_JSON_FIELD_NAMES = new Set([
|
|
@@ -29,11 +29,10 @@ const isCosmeticObjectChange = (oldVal: unknown, newVal: unknown, currentKey?: s
|
|
|
29
29
|
* Returns true if the two JSON strings differ only in cosmetic fields
|
|
30
30
|
* (title, description, example, enumTitles, sectionCaption, sectionDescription).
|
|
31
31
|
*/
|
|
32
|
-
export const isCosmeticOnlyJsonSchemaChange = async (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
export const isCosmeticOnlyJsonSchemaChange = async (
|
|
33
|
+
{ fromRef: oldRef, toRef: newRef }: GitRange,
|
|
34
|
+
changedFilepath: string,
|
|
35
|
+
): Promise<boolean> => {
|
|
37
36
|
const [oldJson, newJson] = await Promise.all([
|
|
38
37
|
runGitCommand(['show', `${oldRef}:${changedFilepath}`])
|
|
39
38
|
.then(JSON.parse)
|
package/bin/git.ts
CHANGED
|
@@ -9,8 +9,8 @@ const GIT_LOG_FORMAT = ['%H', '%aN<%aE>', '%aD', '%s'].join(GIT_FORMAT_SEPARATOR
|
|
|
9
9
|
* Gets the list of changed files between the given commits (inclusive), so it diffs from the parent of the oldest.
|
|
10
10
|
*/
|
|
11
11
|
export const getChangedFiles = async (commits: Commit[]) => {
|
|
12
|
-
// getCommits never returns an empty list (
|
|
13
|
-
//
|
|
12
|
+
// getCommits never returns an empty list (it throws on an empty range, and the rerun check returns all
|
|
13
|
+
// commits when the base commit is the branch HEAD), so this signals a programmer error
|
|
14
14
|
if (commits.length === 0) {
|
|
15
15
|
throw new Error('Cannot get changed files: the commit list is empty. This should never happen.');
|
|
16
16
|
}
|
|
@@ -35,59 +35,22 @@ export const getChangedFilesBetween = async (fromRef: string, toRef: string) =>
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* The commit `git diff base...head` compares against: where `head` forked from `base`, or the last commit of `base`
|
|
39
|
+
* that `head` merged in. The diff from it holds only what `head` itself changed, like GitHub's "Files changed" tab.
|
|
40
|
+
* With criss-cross merges there are several such commits and git picks one.
|
|
41
41
|
*/
|
|
42
|
-
export const
|
|
43
|
-
|
|
44
|
-
await runGitCommand(['log', '--merges', '--pretty=format:%H', `${targetBranch}..${sourceBranch}`], {
|
|
45
|
-
operation: 'find merge commits on the source branch that are absent from the target branch',
|
|
46
|
-
})
|
|
47
|
-
)
|
|
48
|
-
.split('\n')
|
|
49
|
-
.filter(Boolean);
|
|
42
|
+
export const getMergeBase = async (base: string, head: string): Promise<string> =>
|
|
43
|
+
runGitCommand(['merge-base', base, head], { operation: `find where ${head} forked from ${base}` });
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let mergeBase: string;
|
|
61
|
-
try {
|
|
62
|
-
mergeBase = await runGitCommand(['merge-base', parent, targetBranch], {
|
|
63
|
-
operation: 'check whether a merge parent is reachable from the target branch',
|
|
64
|
-
});
|
|
65
|
-
} catch (error) {
|
|
66
|
-
// Exit code 1 on merge-base means the histories have no common ancestor.
|
|
67
|
-
if (error instanceof GitCommandError && error.exitCode === 1) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
if (mergeBase === parent) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns all files touched by non-merge commits on the branch (full history, ignoring baseCommit).
|
|
82
|
-
* Used to check whether the branch itself has any functional changes, independent of what master merged in.
|
|
83
|
-
*/
|
|
84
|
-
export const getBranchOnlyChangedFiles = async (sourceBranch: string, targetBranch: string): Promise<string[]> => {
|
|
85
|
-
const output = await runGitCommand(
|
|
86
|
-
['log', '--no-merges', '--name-only', '--pretty=format:', `${targetBranch}..${sourceBranch}`],
|
|
87
|
-
{ operation: 'list files changed by non-merge commits on the source branch' },
|
|
88
|
-
);
|
|
89
|
-
return output.split('\n').filter(Boolean);
|
|
90
|
-
};
|
|
45
|
+
/** Resolves a ref to a commit, or undefined when it isn't in the local history (e.g. it was force-pushed away). */
|
|
46
|
+
export const findCommitSha = async (ref: string): Promise<string | undefined> =>
|
|
47
|
+
runGitCommand(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], {
|
|
48
|
+
operation: `look up ${ref} in local Git history`,
|
|
49
|
+
}).catch((error: unknown) => {
|
|
50
|
+
// --quiet suppresses Git's error text for a missing commit, but Git still exits with code 1
|
|
51
|
+
if (error instanceof GitCommandError && error.exitCode === 1) return undefined;
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
91
54
|
|
|
92
55
|
const SHA_REGEX = /^[0-9a-f]{40}$/i;
|
|
93
56
|
|
|
@@ -120,8 +83,8 @@ export const getCommitsBetween = async (fromRef: string, toRef: string): Promise
|
|
|
120
83
|
const output = await runGitCommand(['log', `--pretty=format:${GIT_LOG_FORMAT}`, `${fromRef}..${toRef}`], {
|
|
121
84
|
operation: 'list commits reachable from the source ref but absent from the target ref',
|
|
122
85
|
});
|
|
123
|
-
|
|
124
|
-
const commits =
|
|
86
|
+
// An empty range (e.g. `x..x`) prints nothing
|
|
87
|
+
const commits = output.split('\n').filter(Boolean).map(parseCommit);
|
|
125
88
|
commits.reverse();
|
|
126
89
|
return commits;
|
|
127
90
|
};
|
|
@@ -137,6 +100,9 @@ export const getCommits = async ({
|
|
|
137
100
|
}: Pick<Config, 'sourceBranch' | 'targetBranch' | 'baseCommit'>): Promise<Commit[]> => {
|
|
138
101
|
const baseCommitSha = parseBaseCommit(baseCommit);
|
|
139
102
|
const commits = await getCommitsBetween(targetBranch, sourceBranch);
|
|
103
|
+
if (commits.length === 0) {
|
|
104
|
+
throw new Error(`${sourceBranch} has no commits that are not on ${targetBranch}.`);
|
|
105
|
+
}
|
|
140
106
|
|
|
141
107
|
// The last validated (base) commit being the branch HEAD means nothing new was pushed since the last
|
|
142
108
|
// validation — the dev reran the workflow (or force-pushed to the same state) to trigger a clean test
|
package/bin/main.ts
CHANGED
|
@@ -6,13 +6,13 @@ import yargs, { type Options } from 'yargs';
|
|
|
6
6
|
// eslint-disable-next-line import/extensions --- With .js, it cannot find types
|
|
7
7
|
import { hideBin } from 'yargs/helpers';
|
|
8
8
|
|
|
9
|
-
import { getAffectedActors
|
|
10
|
-
import { buildActors, DEFAULT_VERSION_KEYWORD, deleteOldBuilds
|
|
9
|
+
import { getAffectedActors } from './affected-actors.js';
|
|
10
|
+
import { buildActors, DEFAULT_VERSION_KEYWORD, deleteOldBuilds } from './build.js';
|
|
11
11
|
import { runBuildsFromLocal } from './build-from-local.js';
|
|
12
|
-
import { getChangedFiles, getCommits
|
|
12
|
+
import { getChangedFiles, getCommits } from './git.js';
|
|
13
13
|
import { logger, logLevels } from './logger.js';
|
|
14
14
|
import { writeJson } from './output.js';
|
|
15
|
-
import {
|
|
15
|
+
import { notifyToSlack } from './slack.js';
|
|
16
16
|
import { parseBuildInput, parseReleaseChanges, readStdin } from './stdin-input.js';
|
|
17
17
|
import { reportTestResults } from './test-report.js';
|
|
18
18
|
import { readConfigFile } from './utils/config/load-config.js';
|
|
@@ -101,14 +101,7 @@ const buildOptions = {
|
|
|
101
101
|
},
|
|
102
102
|
} as const satisfies Record<string, Options>;
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
const buildForTestOptions = {
|
|
106
|
-
'target-branch': { type: 'string', demandOption: true },
|
|
107
|
-
'base-commit': { type: 'string' },
|
|
108
|
-
'test-files-glob': { type: 'string' },
|
|
109
|
-
} as const satisfies Record<string, Options>;
|
|
110
|
-
|
|
111
|
-
/** Where `release` and `notify-release` post the release. */
|
|
104
|
+
/** Where `notify-release` posts the release. */
|
|
112
105
|
const releaseSlackOptions = {
|
|
113
106
|
'report-slack-channel': { type: 'string', describe: 'Channel for the full report: commits and changed files' },
|
|
114
107
|
'release-slack-channel': { type: 'string', describe: 'Channel for the changelog additions only' },
|
|
@@ -172,7 +165,7 @@ await yargs()
|
|
|
172
165
|
'Find the Actors whose context changed in a commit range ending at the checked-out HEAD',
|
|
173
166
|
(y) => y.options(affectedRangeOptions).options(actorSelectionOptions),
|
|
174
167
|
async (args) => {
|
|
175
|
-
writeJson(
|
|
168
|
+
writeJson(await getAffectedActors(args));
|
|
176
169
|
},
|
|
177
170
|
)
|
|
178
171
|
.command(
|
|
@@ -207,96 +200,13 @@ await yargs()
|
|
|
207
200
|
writeJson(builds);
|
|
208
201
|
},
|
|
209
202
|
)
|
|
210
|
-
.command(
|
|
211
|
-
'build-for-test',
|
|
212
|
-
'Build the Actors the checked-out branch changed functionally, for testing',
|
|
213
|
-
(y) =>
|
|
214
|
-
y
|
|
215
|
-
.options(buildForTestOptions)
|
|
216
|
-
.options(actorSelectionOptions)
|
|
217
|
-
.options(repoUrlOptions)
|
|
218
|
-
.options(dryRunOptions),
|
|
219
|
-
async (config) => {
|
|
220
|
-
logger.info(
|
|
221
|
-
'[BUILD-FOR-TEST]: Same as get-affected-actors --base <target-branch> [--since <base-commit>] ' +
|
|
222
|
-
`| jq '{ actors: .functionallyChangedActors }' | build --version-number ${TEST_VERSION_NUMBER}`,
|
|
223
|
-
);
|
|
224
|
-
// Cosmetic-only changes don't need testing, so they don't need a build either
|
|
225
|
-
const { functionallyChangedActors } = await getAffectedActors({
|
|
226
|
-
base: config.targetBranch,
|
|
227
|
-
since: config.baseCommit,
|
|
228
|
-
testFilesGlob: config.testFilesGlob,
|
|
229
|
-
actors: config.actors,
|
|
230
|
-
ignore: config.ignore,
|
|
231
|
-
});
|
|
232
|
-
const builds = await buildActors({
|
|
233
|
-
actorConfigs: functionallyChangedActors,
|
|
234
|
-
versionNumber: TEST_VERSION_NUMBER,
|
|
235
|
-
repoUrl: config.repoUrl,
|
|
236
|
-
dryRun: config.dryRun,
|
|
237
|
-
});
|
|
238
|
-
writeJson(builds);
|
|
239
|
-
},
|
|
240
|
-
)
|
|
241
|
-
.command(
|
|
242
|
-
'release',
|
|
243
|
-
'Build the default version of the Actors changed since the last release and announce it on Slack',
|
|
244
|
-
(y) =>
|
|
245
|
-
y
|
|
246
|
-
.options(actorSelectionOptions)
|
|
247
|
-
.options(repoUrlOptions)
|
|
248
|
-
.options(dryRunOptions)
|
|
249
|
-
// The last commit that is already released, everything after it up to HEAD gets released.
|
|
250
|
-
// Required, see the README section "Releasing Actors" for how to set it for each merge strategy.
|
|
251
|
-
.option('base-commit', { type: 'string', demandOption: true })
|
|
252
|
-
.options(releaseSlackOptions),
|
|
253
|
-
async (args) => {
|
|
254
|
-
logger.info(
|
|
255
|
-
'[RELEASE]: Same as get-affected-actors --since <base-commit> > affected.json, then ' +
|
|
256
|
-
"jq '{ actors: (.functionallyChangedActors + .cosmeticallyChangedActors) }' affected.json " +
|
|
257
|
-
`| build --version-number ${DEFAULT_VERSION_KEYWORD}, then notify-release < affected.json`,
|
|
258
|
-
);
|
|
259
|
-
// Fail before anything else on a detached HEAD: there is no branch to release
|
|
260
|
-
await getCurrentBranch();
|
|
261
|
-
const { commits, changedFiles, changelog, functionallyChangedActors, cosmeticallyChangedActors } =
|
|
262
|
-
await getAffectedActors({
|
|
263
|
-
since: args.baseCommit,
|
|
264
|
-
actors: args.actors,
|
|
265
|
-
ignore: args.ignore,
|
|
266
|
-
});
|
|
267
|
-
if (commits.length === 0) {
|
|
268
|
-
logger.info(`HEAD is the base commit ${args.baseCommit}, there is nothing new to release`);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const { dryRun, reportSlackChannel, releaseSlackChannel } = args;
|
|
273
|
-
const builds = await buildActors({
|
|
274
|
-
// A release ships cosmetic changes (README, input schema descriptions, ...) too
|
|
275
|
-
actorConfigs: [...functionallyChangedActors, ...cosmeticallyChangedActors],
|
|
276
|
-
versionNumber: DEFAULT_VERSION_KEYWORD,
|
|
277
|
-
repoUrl: args.repoUrl,
|
|
278
|
-
dryRun,
|
|
279
|
-
});
|
|
280
|
-
logger.info(JSON.stringify(builds));
|
|
281
|
-
|
|
282
|
-
await announceRelease({
|
|
283
|
-
commits,
|
|
284
|
-
changedFiles,
|
|
285
|
-
changelog,
|
|
286
|
-
repoUrl: args.repoUrl,
|
|
287
|
-
dryRun,
|
|
288
|
-
reportSlackChannel,
|
|
289
|
-
releaseSlackChannel,
|
|
290
|
-
});
|
|
291
|
-
},
|
|
292
|
-
)
|
|
293
203
|
.command(
|
|
294
204
|
'notify-release',
|
|
295
205
|
'Announce a release on Slack, from the get-affected-actors output on stdin',
|
|
296
206
|
(y) => y.options(releaseSlackOptions).options(repoUrlOptions).options(dryRunOptions),
|
|
297
207
|
async (args) => {
|
|
298
208
|
const { commits, changedFiles, changelog } = parseReleaseChanges(await readStdin());
|
|
299
|
-
await
|
|
209
|
+
await notifyToSlack({
|
|
300
210
|
commits,
|
|
301
211
|
changedFiles,
|
|
302
212
|
changelog,
|