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

get git sha on install #61

Merged
merged 5 commits into from
Aug 10, 2023
Merged

get git sha on install #61

merged 5 commits into from
Aug 10, 2023

Conversation

justinwoo
Copy link
Contributor

We should try to get the git sha of the root and add it to the reporting data if possible

if (allowTopLevel(dependencyInfo.rootPackage)) {
const gitSha = await getGitSha()
logIfVerbose(`Injecting sha to parent: ${gitSha}`)
dependencyInfo.parent.gitSha = gitSha
Copy link
Contributor

Choose a reason for hiding this comment

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

allowTopLevel on its own does not guarantee that parent == root. I think this logic would work if skipTraversal && allowTopLevel but we probably need to be a little more general.

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 think then i should actually update this to make use of parentIsRoot and fix up parentIsRoot to be safe to use with optionals, realizing that the sha can only be retrieved from the actual root package.

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 updated the condition now that it should check parent is root and allowTopLevel is enabled. i updated the definition of parentIsRoot above to be safe: https://github.com/scarf-sh/scarf-js/pull/61/files#diff-7f51467a2b2b5a7527294c07a9a35c8f3195ad9e4ced1ab2c5d1450a75840713R77

@@ -226,6 +242,18 @@ async function getDependencyInfo (packageJSONOverride) {
})
}

async function getGitSha () {
const promise = new Promise((resolve, reject) => {
exec(`cd ${rootPath} && git rev-parse HEAD`, { timeout: execTimeout, maxBuffer: 1024 * 1024 * 1024 }, processGitRevParseOutput(resolve, reject))
Copy link
Contributor

Choose a reason for hiding this comment

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

Going to the rootPath is only sometimes what we'd want. I think we should be going to the package importing scarf-js, ie the parentPath rather than the rootPath. This does handle Superset's specific use case but this will actually grab the wrong SHA in other cases.

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 think then we should be probably only doing this on demand when the parent is the root, since you don't get git shas from node_modules installs

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I didn't realize that. Ok yeah then perhaps let's explicitly check for that and document that behavior in case we want to update that later.

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 at least updated the function name that this only gets the root path git sha

Copy link
Contributor

@aviaviavi aviaviavi left a comment

Choose a reason for hiding this comment

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

🚢

@aviaviavi aviaviavi merged commit 0196d2e into master Aug 10, 2023
6 checks passed
@aviaviavi aviaviavi deleted the get-git-sha-on-install branch August 10, 2023 17:19
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