Skip to content

Commit f078482

Browse files
omsmithbrcrista
andauthored
add global-json-file input (#276)
* support specifying global.json location with global-json-file input * add test workflow jobs for global.json usage * fix typo in global-json-file description Co-authored-by: Brian Cristante <[email protected]> Co-authored-by: Brian Cristante <[email protected]>
1 parent 0fb87b1 commit f078482

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

.github/workflows/workflow.yml

+26
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,32 @@ jobs:
163163
shell: pwsh
164164
run: __tests__/verify-dotnet.ps1 3.1 2.2
165165

166+
test-setup-global-json-specified-and-version:
167+
runs-on: ${{ matrix.operating-system }}
168+
strategy:
169+
fail-fast: false
170+
matrix:
171+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
172+
steps:
173+
- name: Checkout
174+
uses: actions/checkout@v3
175+
- name: Clear toolcache
176+
shell: pwsh
177+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
178+
- name: Write global.json
179+
shell: bash
180+
run: |
181+
mkdir subdirectory
182+
echo '{"sdk":{"version": "2.2","rollForward": "latestFeature"}}' > ./subdirectory/global.json
183+
- name: Setup dotnet
184+
uses: ./
185+
with:
186+
dotnet-version: 3.1
187+
global-json-file: ./subdirectory/global.json
188+
- name: Verify dotnet
189+
shell: pwsh
190+
run: __tests__/verify-dotnet.ps1 2.2 3.1
191+
166192
test-proxy:
167193
runs-on: ubuntu-latest
168194
container:

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ steps:
5151
include-prerelease: true
5252
- run: dotnet build <my project>
5353
```
54+
global.json in a subdirectory:
55+
```yml
56+
steps:
57+
- uses: actions/checkout@v3
58+
- uses: actions/setup-dotnet@v2
59+
with:
60+
global-json-file: csharp/global.json
61+
- run: dotnet build <my project>
62+
working-directory: csharp
63+
```
5464

5565
Matrix Testing:
5666
```yaml

action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ branding:
77
inputs:
88
dotnet-version:
99
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'
10+
global-json-file:
11+
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
1012
source-url:
1113
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'
1214
owner:

dist/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -9115,11 +9115,21 @@ function run() {
91159115
//
91169116
// dotnet-version is optional, but needs to be provided for most use cases.
91179117
// If supplied, install / use from the tool cache.
9118+
// global-version-file may be specified to point to a specific global.json
9119+
// and will be used to install an additional version.
91189120
// If not supplied, look for version in ./global.json.
91199121
// If a valid version still can't be identified, nothing will be installed.
91209122
// Proxy, auth, (etc) are still set up, even if no version is identified
91219123
//
91229124
let versions = core.getMultilineInput('dotnet-version');
9125+
const globalJsonFileInput = core.getInput('global-json-file');
9126+
if (globalJsonFileInput) {
9127+
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
9128+
if (!fs.existsSync(globalJsonPath)) {
9129+
throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`);
9130+
}
9131+
versions.push(getVersionFromGlobalJson(globalJsonPath));
9132+
}
91239133
if (!versions.length) {
91249134
// Try to fall back to global.json
91259135
core.debug('No version found, trying to find version from global.json');

src/setup-dotnet.ts

+14
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@ export async function run() {
99
//
1010
// dotnet-version is optional, but needs to be provided for most use cases.
1111
// If supplied, install / use from the tool cache.
12+
// global-version-file may be specified to point to a specific global.json
13+
// and will be used to install an additional version.
1214
// If not supplied, look for version in ./global.json.
1315
// If a valid version still can't be identified, nothing will be installed.
1416
// Proxy, auth, (etc) are still set up, even if no version is identified
1517
//
1618
let versions = core.getMultilineInput('dotnet-version');
19+
20+
const globalJsonFileInput = core.getInput('global-json-file');
21+
if (globalJsonFileInput) {
22+
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
23+
if (!fs.existsSync(globalJsonPath)) {
24+
throw new Error(
25+
`The specified global.json file '${globalJsonFileInput}' does not exist`
26+
);
27+
}
28+
versions.push(getVersionFromGlobalJson(globalJsonPath));
29+
}
30+
1731
if (!versions.length) {
1832
// Try to fall back to global.json
1933
core.debug('No version found, trying to find version from global.json');

0 commit comments

Comments
 (0)