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
add global-json-file input #276
Conversation
Hey @thboop - don't know if you're terribly involved with setup-dotnet, but I see you working on a lot of the first-party action ecosystem. Seems like the CODEOWNERS here is out of date, referring to a defunct team. Would you or someone else be able to review this? |
650fbeb
to
b9b4b0b
Compare
Thanks for taking a look @vsafonkin. Looks like I had missed regenerating the dist files. I've done that and committed the changes and believe it should get a successful build now. |
src/setup-dotnet.ts
Outdated
@@ -51,21 +49,47 @@ export async function run() { | |||
} | |||
} | |||
|
|||
function getVersionFromGlobalJson(globalJsonPath: string): string { | |||
let version: string = ''; | |||
function getVersionFromGlobalJson(hasVersions: boolean): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think the logic with hasVersions
variable is not clear enough and difficult from readability side because on the first sight it looks like we read globalJson file always.
I think it will be easier to read if we move the condition to parent function (run
)
Something like that (pseudocode, not tested)
let versions = core.getMultilineInput('dotnet-version');
const globalJsonFileInput = core.getInput('global-json-file');
if (versions.length === 0 || globalJsonFileInput) {
const globalJsonVersion = getVersionFromGlobalJson(globalJsonFileInput);
if (globalJsonVersion) {
versions.push(globalJsonVersion);
}
}
...
function getVersionFromGlobalJson(globalJsonFileInput: string | null): string | null {
This way it will be clearer that we read globalJsonFile only in case if 0 versions are specified or explicit global json file path is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's important that we throw if you specified global-json-file
but it doesn't exist. This is the least surprising behaviour (I could imagine trying to track down why the wrong version was being installed in my future if it didn't), and it aligns with the behaviour in setup-node.
I was also trying to maintain the existing debug output, but can take that as being unnecessary.
Perhaps just something like this (pseudo)? Changes a bit less, clutters the main path a bit more, but it will state the flow clearer.
let versions = core.getMultilineInput('dotnet-version');
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
if (!existsSync(globalJsonFileInput)) {
throw new Error('...');
}
versions.push(getVersionFromGlobalJson(globalJsonFileInput));
}
if (versions.length === 0) {
core.debug('No version found, trying to find version from global.json');
if (existsSync('global.json')) {
versions.push(getVersionFromGlobalJson('global.json'));
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, looks good to me! Thanks for proposing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omsmith @maxim-lobanov, do we definitely want to install dotnet version from global.json as additional version?
It's a bit of a contradiction the previous logic: if dotnet-version
is not supplied, look a version in global.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if it's specified we should definitely attempt to use it. In setup-node it's an error to specify both node-version
and node-version-file
, but it also only supports a single version in general.
Given dotnet supports multiple version, and we support that here with multiline dotnet-version
I thought it made sense not to make them mutually exclusive.
If I were to use both, I would probably treat my specified global.json file as my primary and dotnet-version as additional ones I'm installing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that if global-json-file
is defined, we can't ignore it silently. So we have two options if both dotnet-version
and global-json-file
are defined:
- Throw exception and fail task with message that options can't be mixed.
- Use both
dotnet-version
andglobal-json-file
values
The second option looks a bit more friendly and I don't see significant problems with it. But I agree that it is pretty rare case to use :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - I mean only case when both dotnet-version
and global-json-file
are specified.
If global-json-file
is not defined and dotnet-version
is defined, we shouldn't look at default global.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I've rebased and force-pushed the update since it's reverting most of the changes I'd done.
2dbc816
to
e2031f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is good for me. But I will leave it to @dmitry-shibanov @vsafonkin for their final review.
c718d55
to
444a936
Compare
Had a busy day yesterday. I've regenerated dist and squashed that into the first commit, and added tests for the happy path usage in
I was originally testing more combinations, including the standard global.json fallback, but the tests need both 2.x and 3.x installed to build the sample projects. So 88a8d99 just adds a test that has a specified global.json installing 2.x and the |
444a936
to
88a8d99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve #276
@brcrista, could you please review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with adding this input. @vsafonkin I'll defer to you on the implemenation. @omsmith, just one typo to fix and then we can merge. Thanks for the contribution!
Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
Thanks for taking the time to review |
Description:
Our workflow involves doing a checkout to the subdirectory of the workspace. This results in a similar situation to that described in #253, where the global.json is not present in the root of the workspace.
This PR proposes solving this with a
global-json-file
input, similar tonode-version-file
from actions/setup-node.node-version-file
,global-json-file
can be used alongsidedotnet-version
since multiple versions are already allowed.global-json-file
is specified, it is an error for it not to exist.global-json-file
is not specified./global.json
is still searched, but only ifdotnet-version
was not, and the debug message of No version found, trying to find version from global.json is still printed.I've updated the documentation with the new input.
I've not added tests as there is not an existing framework for specifying inputs and I did not feel I should significantly refactor anything to do so. The existing tests pass and show the fallback to
./global.json
still works as expected.Related issue:
Similar to #253
Check list:
Happy Friday and hope you have a good weekend!