Skip to content

Commit 3569a93

Browse files
author
Zachary Eisinger
authored
Honor specified nuget file location (#109)
* Honor specified nuget file location * Generate and verify nuget.config
1 parent 985d576 commit 3569a93

File tree

6 files changed

+71
-21
lines changed

6 files changed

+71
-21
lines changed

.github/workflows/workflow.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
uses: ./
4343
with:
4444
dotnet-version: 3.0.100
45+
# We are including this veriable to force the generation of the nuget config file to verify that it is created in the correct place
46+
source-url: https://api.nuget.org/v3/index.json
47+
env:
48+
NUGET_AUTH_TOKEN: NOTATOKEN
4549
- name: Verify dotnet
4650
if: runner.os != 'windows'
4751
run: __tests__/verify-dotnet.sh 3.0.100
@@ -70,6 +74,9 @@ jobs:
7074
uses: ./
7175
with:
7276
dotnet-version: 3.0.100
77+
source-url: https://api.nuget.org/v3/index.json
78+
env:
79+
NUGET_AUTH_TOKEN: NOTATOKEN
7380
- name: Verify dotnet
7481
run: __tests__/verify-dotnet.sh 3.0.100
7582

@@ -87,5 +94,8 @@ jobs:
8794
uses: ./
8895
with:
8996
dotnet-version: 3.0.100
97+
source-url: https://api.nuget.org/v3/index.json
98+
env:
99+
NUGET_AUTH_TOKEN: NOTATOKEN
90100
- name: Verify dotnet
91101
run: __tests__/verify-dotnet.sh 3.0.100

__tests__/authutil.test.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding=
7575
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
7676

7777
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
78-
process.env['RUNNER_TEMP'] = fakeSourcesDirForTesting;
7978
import * as auth from '../src/authutil';
8079

8180
describe('authutil tests', () => {
@@ -95,7 +94,9 @@ describe('authutil tests', () => {
9594
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
9695
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
9796
await auth.configAuthentication(
98-
'https://nuget.pkg.github.com/OwnerName/index.json'
97+
'https://nuget.pkg.github.com/OwnerName/index.json',
98+
'',
99+
fakeSourcesDirForTesting
99100
);
100101
expect(fs.existsSync(nugetConfigFile)).toBe(true);
101102
expect(
@@ -107,7 +108,9 @@ describe('authutil tests', () => {
107108
let thrown = false;
108109
try {
109110
await auth.configAuthentication(
110-
'https://nuget.pkg.github.com/OwnerName/index.json'
111+
'https://nuget.pkg.github.com/OwnerName/index.json',
112+
'',
113+
fakeSourcesDirForTesting
111114
);
112115
} catch {
113116
thrown = true;
@@ -119,7 +122,9 @@ describe('authutil tests', () => {
119122
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
120123
process.env['INPUT_OWNER'] = 'otherorg';
121124
await auth.configAuthentication(
122-
'https://nuget.pkg.github.com/otherorg/index.json'
125+
'https://nuget.pkg.github.com/otherorg/index.json',
126+
'',
127+
fakeSourcesDirForTesting
123128
);
124129
expect(fs.existsSync(nugetConfigFile)).toBe(true);
125130
expect(
@@ -137,7 +142,9 @@ describe('authutil tests', () => {
137142
let thrown = false;
138143
try {
139144
await auth.configAuthentication(
140-
'https://nuget.pkg.github.com/OwnerName/index.json'
145+
'https://nuget.pkg.github.com/OwnerName/index.json',
146+
'',
147+
fakeSourcesDirForTesting
141148
);
142149
} catch {
143150
thrown = true;
@@ -153,7 +160,9 @@ describe('authutil tests', () => {
153160
);
154161
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
155162
await auth.configAuthentication(
156-
'https://nuget.pkg.github.com/OwnerName/index.json'
163+
'https://nuget.pkg.github.com/OwnerName/index.json',
164+
'',
165+
fakeSourcesDirForTesting
157166
);
158167
expect(fs.existsSync(nugetConfigFile)).toBe(true);
159168
expect(
@@ -169,7 +178,9 @@ describe('authutil tests', () => {
169178
);
170179
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
171180
await auth.configAuthentication(
172-
'https://nuget.pkg.github.com/OwnerName/index.json'
181+
'https://nuget.pkg.github.com/OwnerName/index.json',
182+
'',
183+
fakeSourcesDirForTesting
173184
);
174185
expect(fs.existsSync(nugetConfigFile)).toBe(true);
175186
expect(
@@ -185,7 +196,9 @@ describe('authutil tests', () => {
185196
);
186197
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
187198
await auth.configAuthentication(
188-
'https://nuget.pkg.github.com/OwnerName/index.json'
199+
'https://nuget.pkg.github.com/OwnerName/index.json',
200+
'',
201+
fakeSourcesDirForTesting
189202
);
190203
expect(fs.existsSync(nugetConfigFile)).toBe(true);
191204
expect(
@@ -201,7 +214,9 @@ describe('authutil tests', () => {
201214
);
202215
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
203216
await auth.configAuthentication(
204-
'https://nuget.pkg.github.com/OwnerName/index.json'
217+
'https://nuget.pkg.github.com/OwnerName/index.json',
218+
'',
219+
fakeSourcesDirForTesting
205220
);
206221
expect(fs.existsSync(nugetConfigFile)).toBe(true);
207222
expect(
@@ -216,7 +231,11 @@ describe('authutil tests', () => {
216231
'nuget.config'
217232
);
218233
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
219-
await auth.configAuthentication('https://nuget.pkg.github.com');
234+
await auth.configAuthentication(
235+
'https://nuget.pkg.github.com',
236+
'',
237+
fakeSourcesDirForTesting
238+
);
220239
expect(fs.existsSync(nugetConfigFile)).toBe(true);
221240
expect(
222241
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
@@ -233,7 +252,9 @@ describe('authutil tests', () => {
233252
let thrown = false;
234253
try {
235254
await auth.configAuthentication(
236-
'https://nuget.pkg.github.com/OwnerName/index.json'
255+
'https://nuget.pkg.github.com/OwnerName/index.json',
256+
'',
257+
fakeSourcesDirForTesting
237258
);
238259
} catch {
239260
thrown = true;
@@ -255,7 +276,8 @@ describe('authutil tests', () => {
255276
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
256277
await auth.configAuthentication(
257278
'https://nuget.pkg.github.com/OwnerName/index.json',
258-
'subfolder/nuget.config'
279+
'subfolder/nuget.config',
280+
fakeSourcesDirForTesting
259281
);
260282
expect(fs.existsSync(nugetConfigFile)).toBe(true);
261283
expect(
@@ -271,7 +293,9 @@ describe('authutil tests', () => {
271293
);
272294
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
273295
await auth.configAuthentication(
274-
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
296+
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
297+
'',
298+
fakeSourcesDirForTesting
275299
);
276300
expect(fs.existsSync(nugetConfigFile)).toBe(true);
277301
expect(
@@ -287,7 +311,9 @@ describe('authutil tests', () => {
287311
);
288312
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
289313
await auth.configAuthentication(
290-
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
314+
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
315+
'',
316+
fakeSourcesDirForTesting
291317
);
292318
expect(fs.existsSync(nugetConfigFile)).toBe(true);
293319
expect(
@@ -298,7 +324,9 @@ describe('authutil tests', () => {
298324
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
299325
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
300326
await auth.configAuthentication(
301-
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
327+
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
328+
'',
329+
fakeSourcesDirForTesting
302330
);
303331
expect(fs.existsSync(nugetConfigFile)).toBe(true);
304332
expect(

__tests__/verify-dotnet.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ if (!$args[0])
33
throw "Must supply dotnet version argument"
44
}
55

6+
if (-Not (Test-Path "../nuget.config"))
7+
{
8+
throw "nuget file not generated correctly"
9+
}
10+
611
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
712
Write-Host "Found '$dotnet'"
813

__tests__/verify-dotnet.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ if [ -z "$1" ]; then
33
exit 1
44
fi
55

6+
if [ ! -f "../nuget.config" ]; then
7+
echo "nuget file not generated correctly"
8+
exit 1
9+
fi
10+
611
dotnet_version="$(dotnet --version)"
712
echo "Found dotnet version '$dotnet_version'"
813
if [ -z "$(echo $dotnet_version | grep $1)" ]; then

dist/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,9 +4964,9 @@ const core = __importStar(__webpack_require__(470));
49644964
const github = __importStar(__webpack_require__(469));
49654965
const xmlbuilder = __importStar(__webpack_require__(312));
49664966
const xmlParser = __importStar(__webpack_require__(989));
4967-
function configAuthentication(feedUrl, existingFileLocation = '') {
4968-
const existingNuGetConfig = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
4969-
const tempNuGetConfig = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '../', 'nuget.config');
4967+
function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) {
4968+
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
4969+
const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config');
49704970
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
49714971
}
49724972
exports.configAuthentication = configAuthentication;

src/authutil.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import * as core from '@actions/core';
44
import * as github from '@actions/github';
55
import * as xmlbuilder from 'xmlbuilder';
66
import * as xmlParser from 'fast-xml-parser';
7+
import {ProcessEnvOptions} from 'child_process';
78

89
export function configAuthentication(
910
feedUrl: string,
10-
existingFileLocation: string = ''
11+
existingFileLocation: string = '',
12+
processRoot: string = process.cwd()
1113
) {
1214
const existingNuGetConfig: string = path.resolve(
13-
process.env['RUNNER_TEMP'] || process.cwd(),
15+
processRoot,
1416
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
1517
);
1618

1719
const tempNuGetConfig: string = path.resolve(
18-
process.env['RUNNER_TEMP'] || process.cwd(),
20+
processRoot,
1921
'../',
2022
'nuget.config'
2123
);

0 commit comments

Comments
 (0)