Skip to content

Commit

Permalink
v1.55.0 (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
Que3216 authored Sep 20, 2024
2 parents 1c005ab + 02ca48e commit 13dd870
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
if [ "$(git diff --ignore-space-at-eol --text out/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --ignore-space-at-eol --text out/
echo ""
echo "Run 'yarn build' locally and commit the changes. If this doesn't work then delete your `.parcel-cache` directory before running 'yarn build'."
echo ""
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN yarn --frozen-lockfile

COPY tsconfig.base.json tsconfig.json ./

COPY scripts/post-step.sh /app
COPY scripts/main-post-step.sh /app

COPY src src

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ outputs: {}
runs:
using: "docker"
image: "docker://ghcr.io/alwaysmeticulous/report-diffs-action:releases-v1"
post-entrypoint: "/app/post-step.sh"
post-entrypoint: "/app/main-post-step.sh"
env:
API_TOKEN: ${{ inputs.api-token }}
GITHUB_TOKEN: ${{ inputs.github-token }}
Expand Down
2 changes: 1 addition & 1 deletion cloud-compute/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ outputs: {}
runs:
using: node20
main: "../out/cloud-compute.entrypoint.js"
post: "../out/post-step.entrypoint.js"
post: "../out/cloud-compute.post-step.entrypoint.js"
branding:
color: purple
icon: camera
110 changes: 61 additions & 49 deletions out/cloud-compute.entrypoint.js

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions out/cloud-compute.post-step.entrypoint.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions out/main.post-step.entrypoint.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"distDir": "dist",
"outputFormat": "esmodule"
},
"post": {
"source": "src/post-step.entrypoint.ts",
"main-post": {
"source": "src/main.post-step.entrypoint.ts",
"includeNodeModules": true,
"distDir": "out",
"sourceMap": false,
Expand All @@ -26,6 +26,13 @@
"distDir": "out",
"sourceMap": false,
"outputFormat": "commonjs"
},
"cloud-compute-post": {
"source": "src/cloud-compute.post-step.entrypoint.ts",
"includeNodeModules": true,
"distDir": "out",
"sourceMap": false,
"outputFormat": "commonjs"
}
},
"files": [
Expand Down
3 changes: 3 additions & 0 deletions scripts/main-post-step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

node /app/out/main.post-step.entrypoint.js
3 changes: 0 additions & 3 deletions scripts/post-step.sh

This file was deleted.

27 changes: 27 additions & 0 deletions src/actions/cloud-compute/post-step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createClient, getProject } from "@alwaysmeticulous/client";
import { runPostStep } from "../../common/run-post-step";
import { getInCloudActionInputs } from "./get-inputs";

export const runCloudComputePostStep = async (): Promise<void> => {
const { projectTargets, githubToken } = getInCloudActionInputs();

const projectTargetsToRun = projectTargets.filter((target) => !target.skip);

await Promise.all(
projectTargetsToRun.map(async (target) => {
const client = createClient({ apiToken: target.apiToken });

const project = await getProject(client);

if (!project) {
throw new Error(`Project for target ${target.name} not found.`);
}

return runPostStep({
apiToken: target.apiToken,
githubToken,
testSuiteOrProjectId: project.id,
});
})
);
};
21 changes: 14 additions & 7 deletions src/actions/cloud-compute/run-test-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import { defer, METICULOUS_LOGGER_NAME } from "@alwaysmeticulous/common";
import { executeRemoteTestRun } from "@alwaysmeticulous/remote-replay-launcher";
import log from "loglevel";
import { throwIfCannotConnectToOrigin } from "../../common/check-connection";
import { METICULIOUS_APP_URL } from "../../common/constants";
import { tryTriggerTestsWorkflowOnBase } from "../../common/ensure-base-exists.utils";
import { shortCommitSha } from "../../common/environment.utils";
import { getBaseAndHeadCommitShas } 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 {
getPrefixedLogger,
initLogger,
shortSha,
} from "../../common/logger.utils";
import { getPrefixedLogger, shortSha } from "../../common/logger.utils";
import { getOctokitOrFail } from "../../common/octokit";
import { updateStatusComment } from "../../common/update-status-comment";
import { DEBUG_MODE_KEEP_TUNNEL_OPEN_DURATION } from "./consts";
Expand Down Expand Up @@ -159,8 +156,18 @@ export const runOneTestRun = async ({
event,
owner,
repo,
body: `🤖 Meticulous is running in debug mode. Secure tunnel to ${appUrl} created: ${url} user: \`${basicAuthUser}\` password: \`${basicAuthPassword}\`.\n\n
Tunnel will be live for up to ${DEBUG_MODE_KEEP_TUNNEL_OPEN_DURATION.toHuman()}. Cancel the workflow run to close the tunnel early.`,
body:
`🤖 Meticulous is running in debug mode. Secure tunnel to ${appUrl} created: ${url} user: \`${basicAuthUser}\` password: \`${basicAuthPassword}\`.\n\n` +
`Tunnel will be live for up to ${DEBUG_MODE_KEEP_TUNNEL_OPEN_DURATION.toHuman()}. Cancel the workflow run to close the tunnel early.\n\n` +
`Please open this tunnel in your browser (and enter the username and password when prompted) and check that you are serving your application correctly.\n\n` +
`If you wish to run Meticulous tests locally against this tunnel using the Meticulous CLI then you can use the environment variables \`METICULOUS_TUNNEL_USERNAME\` and \`METICULOUS_TUNNEL_PASSWORD\`. For example:\n\n` +
`\`\`\`bash\n` +
`METICULOUS_TUNNEL_USERNAME="${basicAuthUser}" METICULOUS_TUNNEL_PASSWORD="${basicAuthPassword}" npx @alwaysmeticulous/cli simulate \\\n` +
` --sessionId="<a session id to replay>" \\\n` +
` --appUrl="${url}" \\\n` +
` --apiToken="<your API token>"\n` +
`\`\`\`\n\n` +
`To find a test session to replay and to find your API token: visit the 'Selected Sessions' tab or 'All Sessions' tab on your [Meticulous project page](${METICULIOUS_APP_URL}), click on a session and select the 'Simulate' tab.`,
testSuiteId: `__meticulous_debug_${testRunId}__`,
shortHeadSha: shortCommitSha(headSha),
createIfDoesNotExist: true,
Expand Down
12 changes: 12 additions & 0 deletions src/actions/main/post-step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { runPostStep } from "../../common/run-post-step";
import { getMainActionInputs } from "./get-inputs";

export const runMainActionPostStep = async (): Promise<void> => {
const { apiToken, githubToken, testSuiteId } = getMainActionInputs();

return runPostStep({
apiToken,
githubToken,
testSuiteOrProjectId: testSuiteId,
});
};
8 changes: 8 additions & 0 deletions src/cloud-compute.post-step.entrypoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { warning } from "@actions/core";
import { runCloudComputePostStep } from "./actions/cloud-compute/post-step";

runCloudComputePostStep().catch((error) => {
// We're just emitting telemetry in this post step, so log a warning but don't fail
const message = error instanceof Error ? error.message : `${error}`;
warning(message);
});
4 changes: 3 additions & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const DOCS_URL = "https://app.meticulous.ai/docs/github-actions-v2";
export const METICULIOUS_APP_URL = "https://app.meticulous.ai";

export const DOCS_URL = `${METICULIOUS_APP_URL}/docs/github-actions-v2`;

export const METICULOUS_DEBUGGING_PR_TAG = "[meticulous debug]";
58 changes: 37 additions & 21 deletions src/common/run-post-step.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { getInput } from "@actions/core";
import { context } from "@actions/github";
import { createClient, emitTelemetry } from "@alwaysmeticulous/client";
import { getInputFromEnv } from "./get-input-from-env";
import { getOctokitOrFail } from "./octokit";

export const runPostStep = async (): Promise<void> => {
const apiToken = getActionInput("api-token");
const githubToken = getActionInput("github-token");
export const runPostStep = async ({
apiToken,
githubToken,
testSuiteOrProjectId,
}: {
apiToken: string;
githubToken: string;
/**
* The test suite or project ID to use find the comment in the PR.
*/
testSuiteOrProjectId: string | null;
}): Promise<void> => {
const octokit = getOctokitOrFail(githubToken);
const workflow = await octokit.rest.actions.getWorkflowRun({
owner: context.repo.owner,
Expand Down Expand Up @@ -35,11 +42,12 @@ export const runPostStep = async (): Promise<void> => {
issue_number: context.payload.pull_request.number,
per_page: 1000,
});
values["report_diffs_action.saw_comment"] = prComments.data.some(
(c) =>
c.body?.includes(
"<!--- alwaysmeticulous/report-diffs-action/status-comment"
) && new Date(c.updated_at).getTime() >= workflowStartTime.getTime()
values["report_diffs_action.saw_comment"] = prComments.data.some((c) =>
isPrCommentFromAction({
prComment: c,
testSuiteOrProjectId,
workflowStartTime,
})
)
? 1
: 0;
Expand All @@ -49,17 +57,25 @@ export const runPostStep = async (): Promise<void> => {
await emitTelemetry({ client, values });
};

/**
* This method checks the input from the action in two different ways because we don't know if we are the post step
* for the main action or the cloud-compute one so we need to support both.
*/
const getActionInput = (name: string) => {
const isPrCommentFromAction = ({
prComment,
testSuiteOrProjectId,
workflowStartTime,
}: {
prComment: { body?: string; updated_at: string };
testSuiteOrProjectId: string | null;
workflowStartTime: Date;
}): boolean => {
if (!prComment.body) {
return false;
}

return (
getInput(name) ||
getInputFromEnv({
name: name,
required: true,
type: "string",
})
prComment.body?.includes(getCommentIdentifier(testSuiteOrProjectId)) &&
new Date(prComment.updated_at).getTime() >= workflowStartTime.getTime()
);
};

const getCommentIdentifier = (testSuiteOrProjectId: string | null) => {
return `<!--- alwaysmeticulous/report-diffs-action/status-comment/${testSuiteOrProjectId}`;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { warning } from "@actions/core";
import { runPostStep } from "./common/run-post-step";
import { runMainActionPostStep } from "./actions/main/post-step";

runPostStep().catch((error) => {
runMainActionPostStep().catch((error) => {
// We're just emitting telemetry in this post step, so log a warning but don't fail
const message = error instanceof Error ? error.message : `${error}`;
warning(message);
Expand Down

0 comments on commit 13dd870

Please sign in to comment.