Skip to content

Commit a717db1

Browse files
committed
Emit warning for unrecognised repo properties with our common prefix
1 parent 1dbebad commit a717db1

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

lib/init-action.js

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

src/feature-flags/properties.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as sinon from "sinon";
44
import * as api from "../api-client";
55
import { getRunnerLogger } from "../logging";
66
import { parseRepositoryNwo } from "../repository";
7-
import { setupTests } from "../testing-utils";
7+
import { RecordingLogger, setupTests } from "../testing-utils";
88

99
import * as properties from "./properties";
1010

@@ -197,3 +197,38 @@ test.serial(
197197
);
198198
},
199199
);
200+
201+
test.serial(
202+
"loadPropertiesFromApi warns if a repository property name starts with the common prefix, but is not recognised by us",
203+
async (t) => {
204+
process.env["GITHUB_EVENT_NAME"] = "push";
205+
const propertyName: string = `${properties.GITHUB_CODEQL_PROPERTY_PREFIX}unknown`;
206+
sinon.stub(api, "getRepositoryProperties").resolves({
207+
headers: {},
208+
status: 200,
209+
url: "",
210+
data: [
211+
{
212+
property_name: propertyName,
213+
value: "true",
214+
},
215+
] satisfies properties.GitHubPropertiesResponse,
216+
});
217+
const logger = new RecordingLogger();
218+
const warningSpy = sinon.spy(logger, "warning");
219+
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
220+
const response = await properties.loadPropertiesFromApi(
221+
logger,
222+
mockRepositoryNwo,
223+
);
224+
t.deepEqual(response, {});
225+
t.true(warningSpy.calledOnce);
226+
t.assert(
227+
warningSpy.firstCall.args[0]
228+
.toString()
229+
.startsWith(
230+
`Found a repository property named '${propertyName}', which looks like a CodeQL Action repository property`,
231+
),
232+
);
233+
},
234+
);

src/feature-flags/properties.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import { isDynamicWorkflow } from "../actions-util";
12
import { getRepositoryProperties } from "../api-client";
23
import { Logger } from "../logging";
34
import { RepositoryNwo } from "../repository";
45

6+
/** The common prefix that we expect all of our repository properties to have. */
7+
export const GITHUB_CODEQL_PROPERTY_PREFIX = "github-codeql-";
8+
59
/**
610
* Enumerates repository property names that have some meaning to us.
711
*/
@@ -123,6 +127,16 @@ export async function loadPropertiesFromApi(
123127

124128
if (isKnownPropertyName(property.property_name)) {
125129
setProperty(properties, property.property_name, property.value, logger);
130+
} else if (
131+
property.property_name.startsWith(GITHUB_CODEQL_PROPERTY_PREFIX) &&
132+
!isDynamicWorkflow()
133+
) {
134+
logger.warning(
135+
`Found a repository property named '${property.property_name}', ` +
136+
"which looks like a CodeQL Action repository property, " +
137+
"but which is not understood by this version of the CodeQL Action. " +
138+
"Do you need to update to a newer version?",
139+
);
126140
}
127141
}
128142

0 commit comments

Comments
 (0)