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

[build-tools] [ENG-13708] Upload outputs in public step #470

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

Conversation

radoslawkrzemien
Copy link
Contributor

Why

https://linear.app/expo/issue/ENG-13708/move-uploading-outputs-to-eas-build-and-public-step

How

Created outputs upload function based on the one existing in turtle, but accepting the logger and expoApiV2BaseUrl params.
Calling that function at the end of generic job in a new dedicated Complete job step, with the logger for that step.
Added mappings for that new step.

Test Plan

Automated tests mostly based on those from Turtle

Deployment plan

  1. Merge this PR
  2. Release new version of build-tools and eas-build-job
  3. Update eas-build-job in website, merge and deploy
  4. Update build-tools and eas-build-job in Turtle, merge and deploy

Copy link

linear bot commented Nov 21, 2024

Copy link
Contributor

@khamilowicz khamilowicz left a comment

Choose a reason for hiding this comment

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

LGTM, it would be nice to see a PR with updates to turtle.

@radoslawkrzemien
Copy link
Contributor Author

}

try {
const workflowJobId = nullthrows(ctx.job.builderEnvironment?.env?.__WORKFLOW_JOB_ID);
Copy link
Member

Choose a reason for hiding this comment

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

If the user maliciously changes the __WORKFLOW_JOB_ID value to some other workflow ID they won't be able to write outputs values for it because we validate it in WWW, right?

BTW It would be good to move it to job.workflowId so it can't be overridden by the user (not a part of this PR)

Comment on lines +37 to +45
await fetch(new URL(`workflows/${workflowJobId}`, expoApiV2BaseUrl).toString(), {
method: 'PATCH',
body: JSON.stringify({ outputs }),
headers: {
Authorization: `Bearer ${robotAccessToken}`,
'Content-Type': 'application/json',
},
timeout: 20000,
});
Copy link
Member

Choose a reason for hiding this comment

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

I believe that fetch won't throw if the status code is for example 500 by default. You need to check it manually. It will only throw on things like timeouts.

Suggested change
await fetch(new URL(`workflows/${workflowJobId}`, expoApiV2BaseUrl).toString(), {
method: 'PATCH',
body: JSON.stringify({ outputs }),
headers: {
Authorization: `Bearer ${robotAccessToken}`,
'Content-Type': 'application/json',
},
timeout: 20000,
});
const response = await fetch(new URL(`workflows/${workflowJobId}`, expoApiV2BaseUrl).toString(), {
method: 'PATCH',
body: JSON.stringify({ outputs }),
headers: {
Authorization: `Bearer ${robotAccessToken}`,
'Content-Type': 'application/json',
},
timeout: 20000,
});
if (!response.ok) {
throw new Error(...)
}

timeout: 20000,
});
} catch (err) {
logger.error({ err }, 'Failed to upload outputs');
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we fail the workflow run altogether when an error is thrown? If you expect outputs from this workflow in your other runs I guess it would be hard to debug later on if we mark this run as a success but some required inputs will be missing.

What we can do is retry outputs upload a couple of times and if it still fails throw an error and mark workflow as errored.

});
logger.info('Uploading outputs');

await fetch(new URL(`workflows/${workflowJobId}`, expoApiV2BaseUrl).toString(), {
Copy link
Member

Choose a reason for hiding this comment

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

do we want to add retries for it? I believe they would be useful

});
logger.info('Uploading outputs');

await fetch(new URL(`workflows/${workflowJobId}`, expoApiV2BaseUrl).toString(), {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used to use turtleFetch when it was located in turtle, but it's unavailable here so I replace it with the standard fetch, but you're right that we need something similar, if only just for retries

packages/build-tools/src/utils/outputs.ts Show resolved Hide resolved
return `${jsepEval(expression, interpolationContext)}`;
});

jobOutputs[outputKey] = outputValue;
Copy link
Member

Choose a reason for hiding this comment

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

the jobOutputs can be only of type string right?

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