Skip to content

Commit 1479235

Browse files
authored
Merge pull request #3100 from github/mbg/config-version
Store and check action version in `Config`
2 parents 0d058cd + 0487de3 commit 1479235

12 files changed

+171
-10
lines changed

lib/analyze-action-post.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild-action.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resolve-environment-action.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/start-proxy-action-post.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ test("load code quality config", async (t) => {
199199

200200
// And the config we expect it to result in
201201
const expectedConfig: configUtils.Config = {
202+
version: actionsUtil.getActionVersion(),
202203
analysisKinds: [AnalysisKind.CodeQuality],
203204
languages: [KnownLanguage.actions],
204205
buildMode: undefined,
@@ -273,6 +274,55 @@ test("loading config saves config", async (t) => {
273274
});
274275
});
275276

277+
test("loading config with version mismatch throws", async (t) => {
278+
return await withTmpDir(async (tempDir) => {
279+
const logger = getRunnerLogger(true);
280+
281+
const codeql = createStubCodeQL({
282+
async betterResolveLanguages() {
283+
return {
284+
extractors: {
285+
javascript: [{ extractor_root: "" }],
286+
python: [{ extractor_root: "" }],
287+
},
288+
};
289+
},
290+
});
291+
292+
// Sanity check the saved config file does not already exist
293+
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
294+
295+
// Sanity check that getConfig returns undefined before we have called initConfig
296+
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);
297+
298+
// Stub `getActionVersion` to return some nonsense.
299+
const getActionVersionStub = sinon
300+
.stub(actionsUtil, "getActionVersion")
301+
.returns("does-not-exist");
302+
303+
await configUtils.initConfig(
304+
createTestInitConfigInputs({
305+
languagesInput: "javascript,python",
306+
tempDir,
307+
codeql,
308+
workspacePath: tempDir,
309+
logger,
310+
}),
311+
);
312+
313+
// Restore `getActionVersion`.
314+
getActionVersionStub.restore();
315+
316+
// The saved config file should now exist
317+
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
318+
319+
// Trying to read the configuration should now throw an error.
320+
await t.throwsAsync(configUtils.getConfig(tempDir, logger), {
321+
instanceOf: ConfigurationError,
322+
});
323+
});
324+
});
325+
276326
test("load input outside of workspace", async (t) => {
277327
return await withTmpDir(async (tempDir) => {
278328
try {
@@ -389,6 +439,7 @@ test("load non-empty input", async (t) => {
389439

390440
// And the config we expect it to parse to
391441
const expectedConfig: configUtils.Config = {
442+
version: actionsUtil.getActionVersion(),
392443
analysisKinds: [AnalysisKind.CodeScanning],
393444
languages: [KnownLanguage.javascript],
394445
buildMode: BuildMode.None,

0 commit comments

Comments
 (0)