Skip to content

Commit

Permalink
Release v1.43.0 (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexivanov committed Jun 12, 2024
2 parents f9dc05e + a506d34 commit 4e2d8e8
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 144 deletions.
5 changes: 0 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ 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 @@ -84,7 +80,6 @@ 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
21 changes: 8 additions & 13 deletions out/cloud-compute.entrypoint.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@alwaysmeticulous/client": "^2.128.0",
"@alwaysmeticulous/client": "^2.131.0",
"@alwaysmeticulous/common": "^2.127.0",
"@alwaysmeticulous/remote-replay-launcher": "^2.129.0",
"@alwaysmeticulous/remote-replay-launcher": "^2.131.0",
"//": "Upgrading `replay-orchestrator-launcher`? Consider bumping the environment version `LOGICAL_ENVIRONMENT_VERSION` in `constants.ts` if the new version includes visible changes.",
"@alwaysmeticulous/replay-orchestrator-launcher": "^2.128.0",
"@alwaysmeticulous/replay-orchestrator-launcher": "^2.131.0",
"@alwaysmeticulous/sentry": "^2.127.0",
"@sentry/node": "^7.107.0",
"lodash.debounce": "^4.0.8",
Expand All @@ -68,7 +68,7 @@
"jest": "^27.4.5",
"parcel": "^2.12.0",
"prettier": "^2.8.7",
"rimraf": "^5.0.0",
"rimraf": "^5.0.7",
"ts-jest": "^27.1.1",
"typescript": "^4.9.5",
"yaml": "^2.4.1"
Expand Down
49 changes: 28 additions & 21 deletions src/actions/cloud-compute/cloud-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { Duration } from "luxon";
import { throwIfCannotConnectToOrigin } from "../../common/check-connection";
import { safeEnsureBaseTestsExists } from "../../common/ensure-base-exists.utils";
import { shortCommitSha } from "../../common/environment.utils";
import { getBaseAndHeadCommitShas } from "../../common/get-base-and-head-commit-shas";
import { getHeadCommitShaFromRepo } from "../../common/get-base-and-head-commit-shas";
import { getCodeChangeEvent } from "../../common/get-code-change-event";
import { isDebugPullRequestRun } from "../../common/is-debug-pr-run";
import { initLogger, setLogLevel, shortSha } from "../../common/logger.utils";
import { getOctokitOrFail } from "../../common/octokit";
import { updateStatusComment } from "../../common/update-status-comment";
import { getCloudComputeBaseTestRun } from "./get-cloud-compute-base-test-run";
import { getInCloudActionInputs } from "./get-inputs";

const DEBUG_MODE_KEEP_TUNNEL_OPEN_DURAION = Duration.fromObject({
Expand Down Expand Up @@ -42,7 +43,12 @@ export const runMeticulousTestsCloudComputeAction = async (): Promise<void> => {
setLogLevel("trace");
}

const { apiToken, githubToken, appUrl, headSha } = getInCloudActionInputs();
const {
apiToken,
githubToken,
appUrl,
headSha: headShaFromInput,
} = getInCloudActionInputs();
const { payload } = context;
const event = getCodeChangeEvent(context.eventName, payload);
const { owner, repo } = context.repo;
Expand All @@ -59,32 +65,38 @@ export const runMeticulousTestsCloudComputeAction = async (): Promise<void> => {
return;
}

const { base, head } = await getBaseAndHeadCommitShas(event, {
useDeploymentUrl: false,
headSha,
// Compute the HEAD commit SHA to use when creating a test run.
// In a PR workflow this will by default be process.env.GITHUB_SHA (the temporary merge commit) or
// sometimes the head commit of the PR.
// Users can also explicitly provide the head commit SHA to use as input. This is useful when the action is not
// run with the code checked out.
// Our backend is responsible for computing the correct BASE commit to create the test run for.
const head = headShaFromInput || getHeadCommitShaFromRepo();

// Compute the base commit SHA to compare to for the HEAD commit.
// This will usually be the merge base of the PR head and base commit. In some cases it can be an older main branch commit,
// for example when running in a monorepo setup.
const { baseCommitSha, baseTestRun } = await getCloudComputeBaseTestRun({
apiToken,
headCommitSha: head,
});

const { shaToCompareAgainst } = await safeEnsureBaseTestsExists({
event,
apiToken,
base,
useCloudReplayEnvironmentVersion: true,
base: baseCommitSha,
context,
octokit,
// We don't need to fetch the base test run again if we already have it.
getBaseTestRun: async () => baseTestRun,
});

if (shaToCompareAgainst != null && event.type === "pull_request") {
if (shaToCompareAgainst != null) {
logger.info(
`Comparing visual snapshots for the commit head of this PR, ${shortSha(
`Comparing visual snapshots for the commit ${shortSha(
head
)}, against ${shortSha(shaToCompareAgainst)}`
);
} else if (shaToCompareAgainst != null) {
logger.info(
`Comparing visual snapshots for commit ${shortSha(
head
)} against commit ${shortSha(shaToCompareAgainst)}`
);
} else {
logger.info(`Generating visual snapshots for commit ${shortSha(head)}`);
}
Expand Down Expand Up @@ -160,16 +172,11 @@ Tunnel will be live for up to ${DEBUG_MODE_KEEP_TUNNEL_OPEN_DURAION.toHuman()}.
};

// We use MERGE_COMMIT_SHA as the deployment is created for the merge commit.
// Our backend is responsible for computing the correct HEAD and BASE commits to create the test run for.
const mergeCommitSha = process.env.GITHUB_SHA;
if (!mergeCommitSha) {
throw new Error("GITHUB_SHA is not set.");
}

await executeRemoteTestRun({
apiToken,
appUrl,
commitSha: mergeCommitSha,
commitSha: head,
environment: "github-actions",
onTunnelCreated,
onTestRunCreated,
Expand Down
19 changes: 19 additions & 0 deletions src/actions/cloud-compute/get-cloud-compute-base-test-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
createClient,
getGitHubCloudReplayBaseTestRun,
GitHubBaseTestRunResponse,
} from "@alwaysmeticulous/client";

export const getCloudComputeBaseTestRun = async ({
apiToken,
headCommitSha,
}: {
apiToken: string;
headCommitSha: string;
}): Promise<GitHubBaseTestRunResponse> => {
const client = createClient({ apiToken });
return await getGitHubCloudReplayBaseTestRun({
client,
headCommitSha,
});
};
2 changes: 0 additions & 2 deletions src/actions/main/__tests__/get-inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const keys = [
"USE_DEPLOYMENT_URL",
"ALLOWED_ENVIRONMENTS",
"ADDITIONAL_PORTS",
"HEAD_SHA",
];

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

describe("getMainActionInputs", () => {
Expand Down
6 changes: 0 additions & 6 deletions src/actions/main/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ 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 @@ -104,6 +99,5 @@ export const getMainActionInputs = () => {
testSuiteId,
allowedEnvironments,
additionalPorts,
headSha,
};
};
13 changes: 10 additions & 3 deletions src/actions/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { setFailed } from "@actions/core";
import { context } from "@actions/github";
import {
createClient,
getLatestTestRunResults,
} from "@alwaysmeticulous/client";
import {
DEFAULT_EXECUTION_OPTIONS,
METICULOUS_LOGGER_NAME,
Expand Down Expand Up @@ -61,7 +65,6 @@ export const runMeticulousTestsAction = async (): Promise<void> => {
allowedEnvironments,
testSuiteId,
additionalPorts,
headSha,
} = getMainActionInputs();
const { payload } = context;
const event = getCodeChangeEvent(context.eventName, payload);
Expand All @@ -80,17 +83,21 @@ export const runMeticulousTestsAction = async (): Promise<void> => {

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

const { shaToCompareAgainst } = await safeEnsureBaseTestsExists({
event,
apiToken,
base,
useCloudReplayEnvironmentVersion: false,
context,
octokit,
getBaseTestRun: async ({ baseSha }) =>
await getLatestTestRunResults({
client: createClient({ apiToken }),
commitSha: baseSha,
logicalEnvironmentVersion: LOGICAL_ENVIRONMENT_VERSION,
}),
});

if (shaToCompareAgainst != null && event.type === "pull_request") {
Expand Down
19 changes: 4 additions & 15 deletions src/common/ensure-base-exists.utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { warning as ghWarning } from "@actions/core";
import { Context } from "@actions/github/lib/context";
import { GitHub } from "@actions/github/lib/utils";
import {
createClient,
getLatestTestRunResults,
} from "@alwaysmeticulous/client";
import { TestRun } from "@alwaysmeticulous/client";
import { METICULOUS_LOGGER_NAME } from "@alwaysmeticulous/common";
import log from "loglevel";
import { Duration } from "luxon";
import { LOGICAL_ENVIRONMENT_VERSION } from "../actions/main/utils/constants";
import { CodeChangeEvent } from "../types";
import { DOCS_URL } from "./constants";
import {
Expand Down Expand Up @@ -47,18 +43,17 @@ export const safeEnsureBaseTestsExists: typeof ensureBaseTestsExists = async (

export const ensureBaseTestsExists = async ({
event,
apiToken,
base, // from the PR event
context,
useCloudReplayEnvironmentVersion,
octokit,
getBaseTestRun,
}: {
event: CodeChangeEvent;
apiToken: string;
base: string | null;
useCloudReplayEnvironmentVersion: boolean;
context: Context;
octokit: InstanceType<typeof GitHub>;
getBaseTestRun: (options: { baseSha: string }) => Promise<TestRun | null>;
}): Promise<{ shaToCompareAgainst: string | null }> => {
const logger = log.getLogger(METICULOUS_LOGGER_NAME);

Expand All @@ -68,13 +63,7 @@ export const ensureBaseTestsExists = async ({
return { shaToCompareAgainst: null };
}

const testRun = await getLatestTestRunResults({
client: createClient({ apiToken }),
commitSha: base,
...(useCloudReplayEnvironmentVersion
? { useCloudReplayEnvironmentVersion: true }
: { logicalEnvironmentVersion: LOGICAL_ENVIRONMENT_VERSION }),
});
const testRun = await getBaseTestRun({ baseSha: base });

if (testRun != null) {
logger.info(`Tests already exist for commit ${base} (${testRun.id})`);
Expand Down
15 changes: 8 additions & 7 deletions src/common/get-base-and-head-commit-shas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export const getBaseAndHeadCommitShas = async (
event: CodeChangeEvent,
options: {
useDeploymentUrl: boolean;
headSha: string | null;
}
): Promise<BaseAndHeadCommitShas> => {
if (event.type === "pull_request") {
const head = options.headSha || event.payload.pull_request.head.sha;
const head = 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 @@ -37,13 +36,13 @@ export const getBaseAndHeadCommitShas = async (
if (event.type === "push") {
return {
base: event.payload.before,
head: options.headSha || event.payload.after,
head: event.payload.after,
};
}
if (event.type === "workflow_dispatch") {
return {
base: null,
head: options.headSha || context.sha,
head: context.sha,
};
}
return assertNever(event);
Expand Down Expand Up @@ -92,6 +91,10 @@ const tryGetMergeBaseOfHeadCommit = (
}
};

export const getHeadCommitShaFromRepo = (): string => {
return execSync("git rev-list --max-count=1 HEAD").toString().trim();
};

const tryGetMergeBaseOfTemporaryMergeCommit = (
pullRequestHeadSha: string,
pullRequestBaseSha: string
Expand All @@ -108,9 +111,7 @@ const tryGetMergeBaseOfTemporaryMergeCommit = (
try {
markGitDirectoryAsSafe();

const headCommitSha = execSync("git rev-list --max-count=1 HEAD")
.toString()
.trim();
const headCommitSha = getHeadCommitShaFromRepo();
if (headCommitSha !== mergeCommitSha) {
logger.info(
`The head commit SHA (${headCommitSha}) does not equal GITHUB_SHA environment variable (${mergeCommitSha}).
Expand Down
16 changes: 8 additions & 8 deletions tests/react-bmi-calculator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2912,11 +2912,11 @@ brace-expansion@^2.0.1:
balanced-match "^1.0.0"

braces@^3.0.2, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

browser-process-hrtime@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -4424,10 +4424,10 @@ filesize@^8.0.6:
resolved "https://registry.yarnpkg.com/filesize/-/filesize-8.0.7.tgz#695e70d80f4e47012c132d57a059e80c6b580bd8"
integrity sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down
Loading

0 comments on commit 4e2d8e8

Please sign in to comment.