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

Honor specified nuget file location #109

Merged
merged 8 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
uses: ./
with:
dotnet-version: 3.0.100
# We are including this veriable to force the generation of the nuget config file to verify that it is created in the correct place
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
if: runner.os != 'windows'
run: __tests__/verify-dotnet.sh 3.0.100
Expand Down Expand Up @@ -70,6 +74,9 @@ jobs:
uses: ./
with:
dotnet-version: 3.0.100
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
run: __tests__/verify-dotnet.sh 3.0.100

Expand All @@ -87,5 +94,8 @@ jobs:
uses: ./
with:
dotnet-version: 3.0.100
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
run: __tests__/verify-dotnet.sh 3.0.100
58 changes: 43 additions & 15 deletions __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding=
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');

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

describe('authutil tests', () => {
Expand All @@ -95,7 +94,9 @@ describe('authutil tests', () => {
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -107,7 +108,9 @@ describe('authutil tests', () => {
let thrown = false;
try {
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
} catch {
thrown = true;
Expand All @@ -119,7 +122,9 @@ describe('authutil tests', () => {
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
process.env['INPUT_OWNER'] = 'otherorg';
await auth.configAuthentication(
'https://nuget.pkg.github.com/otherorg/index.json'
'https://nuget.pkg.github.com/otherorg/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -137,7 +142,9 @@ describe('authutil tests', () => {
let thrown = false;
try {
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
} catch {
thrown = true;
Expand All @@ -153,7 +160,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -169,7 +178,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -185,7 +196,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -201,7 +214,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -216,7 +231,11 @@ describe('authutil tests', () => {
'nuget.config'
);
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
await auth.configAuthentication('https://nuget.pkg.github.com');
await auth.configAuthentication(
'https://nuget.pkg.github.com',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
Expand All @@ -233,7 +252,9 @@ describe('authutil tests', () => {
let thrown = false;
try {
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json'
'https://nuget.pkg.github.com/OwnerName/index.json',
'',
fakeSourcesDirForTesting
);
} catch {
thrown = true;
Expand All @@ -255,7 +276,8 @@ describe('authutil tests', () => {
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json',
'subfolder/nuget.config'
'subfolder/nuget.config',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -271,7 +293,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
await auth.configAuthentication(
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -287,7 +311,9 @@ describe('authutil tests', () => {
);
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
await auth.configAuthentication(
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand All @@ -298,7 +324,9 @@ describe('authutil tests', () => {
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
await auth.configAuthentication(
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
'',
fakeSourcesDirForTesting
);
expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
Expand Down
5 changes: 5 additions & 0 deletions __tests__/verify-dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ if (!$args[0])
throw "Must supply dotnet version argument"
}

if (-Not (Test-Path "../nuget.config"))
{
throw "nuget file not generated correctly"
}

$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
Write-Host "Found '$dotnet'"

Expand Down
5 changes: 5 additions & 0 deletions __tests__/verify-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ if [ -z "$1" ]; then
exit 1
fi

if [ ! -f "../nuget.config" ]; then
echo "nuget file not generated correctly"
exit 1
fi

dotnet_version="$(dotnet --version)"
echo "Found dotnet version '$dotnet_version'"
if [ -z "$(echo $dotnet_version | grep $1)" ]; then
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4964,9 +4964,9 @@ const core = __importStar(__webpack_require__(470));
const github = __importStar(__webpack_require__(469));
const xmlbuilder = __importStar(__webpack_require__(312));
const xmlParser = __importStar(__webpack_require__(989));
function configAuthentication(feedUrl, existingFileLocation = '') {
const existingNuGetConfig = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
const tempNuGetConfig = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '../', 'nuget.config');
function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) {
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config');
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
}
exports.configAuthentication = configAuthentication;
Expand Down
8 changes: 5 additions & 3 deletions src/authutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import * as xmlbuilder from 'xmlbuilder';
import * as xmlParser from 'fast-xml-parser';
import {ProcessEnvOptions} from 'child_process';

export function configAuthentication(
feedUrl: string,
existingFileLocation: string = ''
existingFileLocation: string = '',
processRoot: string = process.cwd()
) {
const existingNuGetConfig: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
processRoot,
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
);

const tempNuGetConfig: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
processRoot,
'../',
'nuget.config'
);
Expand Down