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

Don't link on deploy when api key is provided #4261

Merged
merged 2 commits into from
Aug 5, 2024
Merged

Conversation

DuncanUszkay1
Copy link
Contributor

@DuncanUszkay1 DuncanUszkay1 commented Aug 2, 2024

WHY are these changes introduced?

Fixes failing buildkites: https://buildkite.com/shopify/functions-platform-tests/builds/7325#01910f81-3ad3-4460-8d40-c577a22e4f1f

In non-interactive environments, CLI users pass in an api-key or client-id flag to indicate which app they want to use. When this is the case, logic in the CLI needs to not try and prompt the user to select an app, or the process will fail.

This code path was always setting enableLinkingPrompt to true, when really it should have been dependent on whether or not the api-key flag was passed in. This resulted in the CLI always trying to link the app with the remote app.

WHAT is this pull request doing?

I set the value of enableLinkingPrompt to equal !options.apiKey, similar to how the dev codepath handles this scenario:

enableLinkingPrompt: !options.apiKey,

How to test your changes?

  • Clear your config. The standard in OSX appears to be ~/Library/Preferences/shopify-cli-app-nodejs/config.json based on my own machine.
  • Run deploy with an api-key non-interactively (My preferred trick is to just add | cat at the end of the command)
  • The deploy will work with this change, but will fail with "you must select an app" afterwards

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Aug 2, 2024

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/advanced-edits
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/app-management

Copy link
Contributor

github-actions bot commented Aug 2, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.59% (+0.08% 🔼)
7904/10888
🟡 Branches
69.35% (+0% 🔼)
3879/5593
🟡 Functions
71.31% (+0.02% 🔼)
2075/2910
🟡 Lines
72.93% (+0.09% 🔼)
7469/10242
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / dev.ts
74.42% (-1.67% 🔻)
56.25% (-8.75% 🔻)
76.47%
69.44% (-3.06% 🔻)
🟢
... / select-store.ts
86% (-0.27% 🔻)
81.82% 85.71%
87.23% (-0.27% 🔻)
🔴
... / developer-platform-client.ts
54.84% (-5.16% 🔻)
36.84% (-6.02% 🔻)
77.78% (-2.22% 🔻)
52% (-5.14% 🔻)
🟢
... / ConcurrentOutput.tsx
98.39% (-1.61% 🔻)
90.91% (-4.55% 🔻)
100%
98.33% (-1.67% 🔻)

Test suite run success

1802 tests passing in 822 suites.

Report generated by 🧪jest coverage report action from 3b1ec3d

@DuncanUszkay1 DuncanUszkay1 marked this pull request as ready for review August 2, 2024 15:03

This comment has been minimized.

@@ -430,7 +430,7 @@ export async function ensureDeployContext(options: DeployContextOptions): Promis
const {reset, force, noRelease} = options
let developerPlatformClient = options.developerPlatformClient
// do the link here
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, true)
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, !options.apiKey)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Positional arguments here makes it hard to see, so here's a link to the API we're calling to demonstrate that the enableLinkingPrompt is what changed:

enableLinkingPrompt = false,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, multiple booleans are pretty bad. We should revisit the public API of fetchAppAndIdentifiers. Usually we'd use an options object in this sort of case. Thanks for the note!

Copy link
Contributor

@MitchDickinson MitchDickinson left a comment

Choose a reason for hiding this comment

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

The main goal with my PR is ensuring that, post-deploy, your TOML file is correctly configured and linked to the remote app. This requires a manual prompt usually, which is what broke the functions CI tests.

When providing the api key, it still feels like we should be able to link and update the TOML correctly. The prompting step is unnecessary because the user has provided the identifier. But the rest of the linking should be doable, right?

Doing the above would likely blow up the scope of this PR, so I'm ok shipping this to unblock functions, but we should at least queue up an issue to tackle the "proper" refactor later.

Approval conditional on getting that issue created (assuming folks agree) and tophatting working, but otherwise 🚢

@@ -430,7 +430,7 @@ export async function ensureDeployContext(options: DeployContextOptions): Promis
const {reset, force, noRelease} = options
let developerPlatformClient = options.developerPlatformClient
// do the link here
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, true)
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, !options.apiKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this logic something we only want to apply for deploy? For example, release also works the same way. fetchAppAndIdentifiers has access to options so in theory we could do this logic inside of fetchAppAndIdentifiers if we wanted to apply this business logic to anyone who is trying to use this method.

No strong opinions...just asking...

@DuncanUszkay1
Copy link
Contributor Author

Tophatted against this bug, found no regressions.

@MitchDickinson
Copy link
Contributor

Tophatted and it worked 🎩 ✅

@DuncanUszkay1
Copy link
Contributor Author

DuncanUszkay1 commented Aug 2, 2024

but we should at least queue up an issue to tackle the "proper" refactor later

Sounds good- just created an issue on the same repository the original bug came from: https://github.com/Shopify/develop-app-inner-loop/issues/2001

@DuncanUszkay1 DuncanUszkay1 added this pull request to the merge queue Aug 2, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to Branch Protection failures Aug 2, 2024
You're not authorized to push to this branch. Visit "About protected branches" for more information.
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