Skip to content

Commit

Permalink
support specifying global.json location with global-json-file input
Browse files Browse the repository at this point in the history
  • Loading branch information
omsmith committed Apr 12, 2022
1 parent 9283a8c commit e2031f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -51,6 +51,16 @@ steps:
include-prerelease: true
- run: dotnet build <my project>
```
global.json in a subdirectory:
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
global-json-file: csharp/global.json
- run: dotnet build <my project>
working-directory: csharp
```

Matrix Testing:
```yaml
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -7,6 +7,8 @@ branding:
inputs:
dotnet-version:
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x'
global-json-file:
description: 'Optional global.json location, if your global.json it''t located in the root of the repo.'
source-url:
description: 'Optional package source for which to set up authentication. Will consult any existing NuGet.config in the root of the repo and provide a temporary NuGet.config using the NUGET_AUTH_TOKEN environment variable as a ClearTextPassword'
owner:
Expand Down
8 changes: 8 additions & 0 deletions dist/index.js
Expand Up @@ -9120,6 +9120,14 @@ function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified
//
let versions = core.getMultilineInput('dotnet-version');
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
if (!fs.existsSync(globalJsonPath)) {
throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`);
}
versions.push(getVersionFromGlobalJson(globalJsonPath));
}
if (!versions.length) {
// Try to fall back to global.json
core.debug('No version found, trying to find version from global.json');
Expand Down
12 changes: 12 additions & 0 deletions src/setup-dotnet.ts
Expand Up @@ -14,6 +14,18 @@ export async function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified
//
let versions = core.getMultilineInput('dotnet-version');

const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
if (!fs.existsSync(globalJsonPath)) {
throw new Error(
`The specified global.json file '${globalJsonFileInput}' does not exist`
);
}
versions.push(getVersionFromGlobalJson(globalJsonPath));
}

if (!versions.length) {
// Try to fall back to global.json
core.debug('No version found, trying to find version from global.json');
Expand Down

0 comments on commit e2031f2

Please sign in to comment.