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 multiple API tokens and app urls to be specified #499

Merged
merged 13 commits into from
Sep 4, 2024

Conversation

edoardopirovano
Copy link
Contributor

@edoardopirovano edoardopirovano commented Aug 23, 2024

This hasn't been fully tested yet, but putting it up for review so it can potentially be merged while I'm on holiday if needed.

Copy link

vercel bot commented Aug 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
report-diffs-action ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 4:09pm

Copy link

alwaysmeticulous bot commented Aug 23, 2024

✅ Meticulous spotted zero visual differences across 8 screens tested: view results.

Expected differences? Click here. Test suite: public-tests. Last updated for commit 829dde1. This comment will update as new commits are pushed.

@edoardopirovano edoardopirovano marked this pull request as ready for review August 23, 2024 15:20
@edoardopirovano edoardopirovano requested a review from a team August 23, 2024 15:20
Comment on lines 43 to 53
const { apiToken: apiTokenInput, appUrl: appUrlInput } =
getInCloudActionInputs();
const apiTokens = apiTokenInput.split(",").map((token) => token.trim());
const appUrls = appUrlInput.split(",").map((token) => token.trim());
while (appUrls.length < apiTokens.length) {
// If the number of app URLs is less than the number of API tokens, the
// last URL will be used for all remaining projects. This allow for
// more concise inputs when one app URL is to be used many times. In
// particular in the common case of one app URL for all projects.
appUrls.push(appUrls[appUrls.length - 1]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Since this is input parsing logic I'd push this down into getInCloudActionInputs to keep it separate from the main code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also update the docs here: https://github.com/alwaysmeticulous/report-diffs-action/blob/main/cloud-compute/action.yml.

That said wondering what the best API is for us here? We should work that out before shipping. Some notes here https://www.notion.so/API-for-multi-project-cloud-compute-action-75afd0edf8694bd7be54b305e4a63c30?pvs=4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking we should do this:

- name: Run Meticulous tests
        uses: alwaysmeticulous/report-diffs-action/cloud-compute@v1
        with:
          # Important: remember to add the '|' character below: GitHub doesn't support complex action inputs, so we're actually passed the sub YAML as a string.
          projects_yaml: |
             admin_portal:
                api_token: ${{ secrets.METICULOUS_ADMIN_PORTAL_API_TOKEN }}
                app_url: https://localhost:3000/
                skip: ${{ steps.changed-admin-portal-files.outputs.any_changed == 'false' }}
             customer_portal:
                api_token: ${{ secrets.METICULOUS_CUSTOMER_PORTAL_API_TOKEN }}
                app_url: https://localhost:3000/
                skip: ${{ steps.changed-customer-portal-files.outputs.any_changed == 'false' }}

One thing I find useful on API design is always to try the API out / write out how user would use it. Much easier to iterate on correct API when looking at example usages across common use cases than by looking at the type definition of the API.

}
});
if (failureMessage) {
setFailed(failureMessage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the common case of just using one action we should probably keep the failure message as a clean as we can, similar to before e.g.

failures.push({ runNumber: index + 1, message })`
const message = failures.length === 1 ? failures[0].message : ...;

if (result.status === "rejected") {
const message =
result.reason instanceof Error ? result.reason.message : `${error}`;
failureMessage += `Run #${index + 1} failed: ${message}\n`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how often this case would get hit (maybe quite rare?), but it could make sense to give some context.
Also maybe Run -> Test run so user doesn't think this is a retry number. And in the common case of just using one action we should probably keep the failure message as a clean as we can, similar to before e.g.

if (apiTokens.length > 1) {
  failureMessage += `Test run #${index + 1} against '${appUrls[index]}' with token '${apiTokens.slice(0, 3)}...': ${message}`;
} else {
  failureMessage = message;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if we're not already logging it, maybe also:

logger.error(`[Test run #${index + 1}]`, result.reason);

const { payload } = context;
const event = getCodeChangeEvent(context.eventName, payload);
const { owner, repo } = context.repo;
const isDebugPRRun = isDebugPullRequestRun(event);
const octokit = getOctokitOrFail(githubToken);
const logger = log.getLogger(METICULOUS_LOGGER_NAME);
const logger = getPrefixedLogger(`Run #${runNumber}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice!

[nit] Just in case user things this means retries

Suggested change
const logger = getPrefixedLogger(`Run #${runNumber}`);
const logger = getPrefixedLogger(`Test run #${runNumber}`);

).forEach((result, index) => {
if (result.status === "rejected") {
const message =
result.reason instanceof Error ? result.reason.message : `${error}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result.reason instanceof Error ? result.reason.message : `${error}`;
result.reason instanceof Error ? result.reason.message : `${result.reason}`;

(error doesn't exist)

src/actions/cloud-compute/cloud-compute.ts Show resolved Hide resolved
keepTunnelOpenPromise.resolve();
}, DEBUG_MODE_KEEP_TUNNEL_OPEN_DURAION.as("milliseconds"));
}
testSuiteId: "__meticulous_debug__",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably tag this comment with the project ID too as this won't work in multi-project setups. Looks like this already doesn't work well on multi-project PRs.

Copy link

github-actions bot commented Aug 28, 2024

✅ Meticulous spotted zero visual differences across 8 screens tested: view results.

Test suite: test Meticulous with deployment url. Last updated for commit 829dde1. This comment will update as new commits are pushed.

Copy link

github-actions bot commented Aug 28, 2024

✅ Meticulous spotted zero visual differences across 8 screens tested: view results.

Test suite: test Meticulous with app url. Last updated for commit 829dde1. This comment will update as new commits are pushed.

Copy link
Contributor

@Que3216 Que3216 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor Author

@edoardopirovano edoardopirovano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the new syntax looks good to me! Just a few small nits on your commits @alexivanov 🙂

admin:
api-token: {{ secrets.METICULOUS_ADMIN_API_TOKEN }}
app-url: "http://localhost:4000"
skip: {{ secrets.METICULOUS_APP_API_TOKEN }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is a bad copy paste? Should probably be an example of using the output from a previous step to determine whether to run it or not?

// This is used to simplify some of the logging and error handling.
const isSingleTestRunExecution =
projectTargetsToRun.length === 1 &&
projectTargetsToRun[0].name === "default";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we should use projectTargets (before the filtering is applied) here. If we have more than one project in the config, I think it's nice to be explicit in the logging about which one the logs are coming from even if a particular run only executed one.

if (!project) {
throw new Error(
`Could not retrieve project data${
isSingleTestRunExecution ? "" : `for project ${testRunId}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isSingleTestRunExecution ? "" : `for project ${testRunId}`
isSingleTestRunExecution ? "" : ` for project ${testRunId}`

@@ -0,0 +1,5 @@
import { Duration } from "luxon";

export const DEBUG_MODE_KEEP_TUNNEL_OPEN_DURAION = Duration.fromObject({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const DEBUG_MODE_KEEP_TUNNEL_OPEN_DURAION = Duration.fromObject({
export const DEBUG_MODE_KEEP_TUNNEL_OPEN_DURATION = Duration.fromObject({

@edoardopirovano edoardopirovano merged commit f3281ad into main Sep 4, 2024
10 checks passed
@edoardopirovano edoardopirovano deleted the edoardo/multiple-app-tokens branch September 4, 2024 16:20
edoardopirovano added a commit that referenced this pull request Sep 4, 2024
edoardopirovano added a commit that referenced this pull request Sep 4, 2024
edoardopirovano added a commit that referenced this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants