Include action/post-action suffix in getDisplayActionName

This commit is contained in:
Michael B. Gale
2026-10-21 16:45:27 +01:00
parent 64ec5d5f67
commit 00434f00f4
4 changed files with 31 additions and 27 deletions

View File

@@ -19,24 +19,26 @@ import { getErrorMessage } from "./util";
setupTests(test);
for (const [key, displayName] of Object.entries(
statusReport.ACTION_DISPLAY_NAMES,
)) {
test(`getDisplayActionName - '${displayName}' instead of '${key}'`, (t) => {
const expectedActionDisplayNames: Record<ActionName, string> = {
[ActionName.Analyze]: "analyze action",
[ActionName.AnalyzePost]: "analyze post-action",
[ActionName.Autobuild]: "autobuild action",
[ActionName.Init]: "init action",
[ActionName.InitPost]: "init post-action",
[ActionName.ResolveEnvironment]: "resolve-environment action",
[ActionName.SetupCodeQL]: "setup-codeql action",
[ActionName.StartProxy]: "start-proxy action",
[ActionName.StartProxyPost]: "start-proxy post-action",
[ActionName.UploadSarif]: "upload-sarif action",
[ActionName.UploadSarifPost]: "upload-sarif post-action",
};
for (const [key, displayName] of Object.entries(expectedActionDisplayNames)) {
test(`getDisplayActionName - '${displayName}' for '${key}'`, (t) => {
t.is(statusReport.getDisplayActionName(key as ActionName), displayName);
});
}
test("getDisplayActionName - returns action name", (t) => {
for (const actionName of Object.values(ActionName)) {
if (statusReport.ACTION_DISPLAY_NAMES[actionName]) {
continue;
}
t.is(statusReport.getDisplayActionName(actionName), actionName);
}
});
interface RunInActionsTestOpts {
runFn?: () => Promise<any>;
expectedErrorMessage?: string;
@@ -109,7 +111,7 @@ const runInActionsMacro = makeMacro({
if (expectFailure) {
t.true(
setFailed.calledOnceWithExactly(
`${statusReport.getDisplayActionName(name)} action failed: ${opts?.expectedErrorMessage}`,
`${statusReport.getDisplayActionName(name)} failed: ${opts?.expectedErrorMessage}`,
),
);
t.true(

View File

@@ -192,7 +192,7 @@ export async function runInActions(action: Action) {
await action.run(actionState);
} catch (error) {
core.setFailed(
`${getDisplayActionName(action.name)} action failed: ${getErrorMessage(error)}`,
`${getDisplayActionName(action.name)} failed: ${getErrorMessage(error)}`,
);
const statusReportError =

View File

@@ -67,10 +67,10 @@ export enum ActionName {
/** A partial mapping from `ActionName` to names for actions whose display name is not the `ActionName` value. */
export const ACTION_DISPLAY_NAMES: Partial<Record<ActionName, string>> = {
[ActionName.Analyze]: "analyze",
[ActionName.AnalyzePost]: "analyze post-action",
[ActionName.InitPost]: "init post",
[ActionName.StartProxyPost]: "start-proxy post-action",
[ActionName.UploadSarifPost]: "upload-sarif post-action",
[ActionName.AnalyzePost]: "analyze",
[ActionName.InitPost]: "init",
[ActionName.StartProxyPost]: "start-proxy",
[ActionName.UploadSarifPost]: "upload-sarif",
};
/** Decides if {@link name} refers to a post-action. */
@@ -83,9 +83,10 @@ export function isPostAction(name: ActionName) {
* for actions which have a different display name in {@link ACTION_DISPLAY_NAMES}.
*/
export function getDisplayActionName(actionName: ActionName): string {
const suffix = isPostAction(actionName) ? "post-action" : "action";
const displayName = ACTION_DISPLAY_NAMES[actionName];
return displayName ?? actionName;
return `${displayName ?? actionName} ${suffix}`;
}
/**