Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding of head commit #441

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ inputs:
additional-ports:
description: Ports the client needs to access the application in addition to the one in the app URL, as a list of comma-separated values
required: false
head-sha:
description: |
Override the head commit SHA that we are analysing instead of using the one inferred automatically by Meticulous. This normally should not be set, but is useful in some scenarios.
required: false

outputs: {}
runs:
Expand All @@ -80,6 +84,7 @@ runs:
TEST_SUITE_ID: ${{ inputs.test-suite-id }}
METICULOUS_TELEMETRY_SAMPLE_RATE: "0.01"
ADDITIONAL_PORTS: ${{ inputs.additional-ports }}
HEAD_SHA: ${{ inputs.head-sha }}
branding:
color: purple
icon: camera
4 changes: 4 additions & 0 deletions cloud-compute/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: |
The URL to execute the tests against. This URL should serve the code from the current commit (e.g. a localhost URL served up by a local server).
required: true
head-sha:
description: |
Override the head commit SHA that we are analysing instead of using the one inferred automatically by Meticulous. This normally should not be set, but is useful in some scenarios.
required: false

outputs: {}
runs:
Expand Down
8 changes: 4 additions & 4 deletions out/cloud-compute.entrypoint.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/actions/cloud-compute/cloud-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const runMeticulousTestsCloudComputeAction = async (): Promise<void> => {
setLogLevel("trace");
}

const { apiToken, githubToken, appUrl } = getInCloudActionInputs();
const { apiToken, githubToken, appUrl, headSha } = getInCloudActionInputs();
const { payload } = context;
const event = getCodeChangeEvent(context.eventName, payload);
const { owner, repo } = context.repo;
Expand All @@ -61,6 +61,7 @@ export const runMeticulousTestsCloudComputeAction = async (): Promise<void> => {

const { base, head } = await getBaseAndHeadCommitShas(event, {
useDeploymentUrl: false,
headSha,
});

const { shaToCompareAgainst } = await safeEnsureBaseTestsExists({
Expand Down
2 changes: 2 additions & 0 deletions src/actions/cloud-compute/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export const getInCloudActionInputs = () => {
const apiToken = getInput("api-token", { required: true });
const githubToken = getInput("github-token", { required: true });
const appUrl = getInput("app-url", { required: true });
const headSha = getInput("head-sha");

return {
apiToken,
githubToken,
appUrl,
headSha,
};
};
2 changes: 2 additions & 0 deletions src/actions/main/__tests__/get-inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const keys = [
"USE_DEPLOYMENT_URL",
"ALLOWED_ENVIRONMENTS",
"ADDITIONAL_PORTS",
"HEAD_SHA",
];

const EXPECTED_DEFAULT_VALUES = {
Expand All @@ -30,6 +31,7 @@ const EXPECTED_DEFAULT_VALUES = {
testsFile: null,
testSuiteId: null,
additionalPorts: null,
headSha: null,
};

describe("getMainActionInputs", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/actions/main/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const getMainActionInputs = () => {
required: false,
type: "string",
});
const headSha = getInputFromEnv({
name: "head-sha",
required: false,
type: "string",
});

if (appUrl != null && appUrl != "" && useDeploymentUrl === true) {
throw new Error("Cannot use both app-url and use-deployment-url");
Expand Down Expand Up @@ -99,5 +104,6 @@ export const getMainActionInputs = () => {
testSuiteId,
allowedEnvironments,
additionalPorts,
headSha,
};
};
2 changes: 2 additions & 0 deletions src/actions/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const runMeticulousTestsAction = async (): Promise<void> => {
allowedEnvironments,
testSuiteId,
additionalPorts,
headSha,
} = getMainActionInputs();
const { payload } = context;
const event = getCodeChangeEvent(context.eventName, payload);
Expand All @@ -79,6 +80,7 @@ export const runMeticulousTestsAction = async (): Promise<void> => {

const { base, head } = await getBaseAndHeadCommitShas(event, {
useDeploymentUrl,
headSha,
});
const environment = getEnvironment({ event, head });

Expand Down
11 changes: 7 additions & 4 deletions src/common/get-base-and-head-commit-shas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ interface BaseAndHeadCommitShas {

export const getBaseAndHeadCommitShas = async (
event: CodeChangeEvent,
options: { useDeploymentUrl: boolean }
options: {
useDeploymentUrl: boolean;
headSha: string | null;
}
): Promise<BaseAndHeadCommitShas> => {
if (event.type === "pull_request") {
const head = event.payload.pull_request.head.sha;
const head = options.headSha || event.payload.pull_request.head.sha;
const base = event.payload.pull_request.base.sha;
const baseRef = event.payload.pull_request.base.ref;
if (options.useDeploymentUrl) {
Expand All @@ -34,13 +37,13 @@ export const getBaseAndHeadCommitShas = async (
if (event.type === "push") {
return {
base: event.payload.before,
head: event.payload.after,
head: options.headSha || event.payload.after,
};
}
if (event.type === "workflow_dispatch") {
return {
base: null,
head: context.sha,
head: options.headSha || context.sha,
};
}
return assertNever(event);
Expand Down
Loading