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

fix: honor --auth option #6838

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Sep 25, 2024

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes https://linear.app/netlify/issue/FRB-1343/internal-server-error-on-netlify-builds-via-bitbucket-pipeline-missing

Our --auth CLI option handling seems a bit hit and miss. We had a lot of optional argument and @ts-expect-error around code that was dealing with tokens - this removes all of those, adjust types to require token from CLI toggle being passed in to helper functions (do note that this doesn't fully ensure type safety, because options.auth has type any, but at least it ensures that something is passed in instead of being optional)


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@pieh pieh force-pushed the michalpiechowiak/frb-1343-internal-server-error-on-netlify-builds-via-bitbucket branch from 067e6ae to 4fcd76d Compare September 25, 2024 11:02
@pieh pieh force-pushed the michalpiechowiak/frb-1343-internal-server-error-on-netlify-builds-via-bitbucket branch 2 times, most recently from ec0f91a to e64e30c Compare September 25, 2024 11:39
@@ -382,7 +382,7 @@ const uploadDeployBlobs = async ({
packagePath,
deployId,
siteId,
token,
token: token === null ? undefined : 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.

token here is of type string | null, while runCoreSteps expect it to be string | undefined

Overall at this stage there should be a token always, otherwise we would bail much earlier, but stuff like this is annoying with TS and probably would need more refactoring to not have to deal with null / undefined cases.

@@ -394,8 +394,7 @@ export const getConfiguration = (workingDir) => {
export const deploy = async (options: OptionValues, command: BaseCommand) => {
const { api, cachedConfig, site, siteInfo } = command.netlify
const { id: siteId } = site
// @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0.
const [token] = await getToken()
const [token] = await command.authenticate(options.auth)
Copy link
Contributor Author

@pieh pieh Sep 25, 2024

Choose a reason for hiding this comment

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

Note that this one will have a potential change in behavior - by using command.authenticate (like almost all the other commands, except for status, login, logout and build) - this will start auth flow if user is not logged in (or didn't provide token via env var or --auth), while previously it would result in getting no token (and presumably getting failures later down the road?)

After fixing up bunch of related TypeScript elsewhere, using the getToken that could be null (previously it would be just any) it would complain about token being possibly null in

const { body: registeredIntegration, statusCode } = await fetch(
`${getIntegrationAPIUrl()}/${accountId}/integrations?site_id=${siteId}`,
{
headers: {
'netlify-token': token,
},
},
).then(async (res) => {

so I assume this should be required that token is present before executing the rest of this command?

cc @netlify/ecosystem-pod-composable-tooling

This comment was marked as outdated.

This comment was marked as outdated.

@@ -953,6 +954,71 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
})
})

test('should upload blobs when saved into .netlify directory and using --auth flag', async (t) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test alone was failing (at least in GHA) without code changes done in 2nd commit

@pieh pieh marked this pull request as ready for review September 25, 2024 12:11
@pieh pieh requested a review from a team as a code owner September 25, 2024 12:11
@pieh pieh force-pushed the michalpiechowiak/frb-1343-internal-server-error-on-netlify-builds-via-bitbucket branch from e64e30c to a39900b Compare September 25, 2024 15:06
@serhalp
Copy link
Contributor

serhalp commented Oct 8, 2024

@pieh is this something we want to get over the finish line?

@sarahetter sarahetter removed the request for review from a team November 26, 2024 16:13
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.

2 participants