mirror of
https://github.com/NuGet/setup-nuget.git
synced 2025-12-06 07:48:23 +08:00
feat(secrets): add support for configuring API keys
This commit is contained in:
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
@@ -18,4 +18,5 @@ jobs:
|
||||
- uses: ./
|
||||
with:
|
||||
nuget-version: ${{ matrix.nuget-version }}
|
||||
nuget-api-key: 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a
|
||||
- run: nuget
|
||||
|
||||
@@ -20,6 +20,12 @@ Supported values for `nuget-version`:
|
||||
* `X.Y.Z` -- concrete semver version for a release (e.g. `5.3.1`).
|
||||
* semver range -- any [valid semver range specifier](https://github.com/npm/node-semver#ranges) (e.g. `5`, `>=5`, `5.3.x`, etc)
|
||||
|
||||
This action also supports configuring your NuGet API key using
|
||||
[GitHub secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets).
|
||||
The API key should be passed in as an `nuget-api-key` input. See
|
||||
[the GitHub documentation on secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets)
|
||||
for how to configure secrets on your repository.
|
||||
|
||||
### Basic:
|
||||
|
||||
```yaml
|
||||
@@ -27,6 +33,7 @@ steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: nuget/setup-nuget-exe@v1
|
||||
with:
|
||||
nuget-api-key: ${{ secrets.NuGetAPIKey }}
|
||||
nuget-version: '5.x' # SDK Version to use.
|
||||
- run: nuget restore MyProject.sln
|
||||
```
|
||||
|
||||
@@ -5,6 +5,10 @@ inputs:
|
||||
nuget-version:
|
||||
description: 'NuGet version to install. Can be `latest`, `preview`, a concrete version like `5.3.1`, or a semver range specifier like `5.x`.'
|
||||
default: 'latest'
|
||||
nuget-api-key:
|
||||
description: 'NuGet API Key to configure.'
|
||||
nuget-api-key-source:
|
||||
description: 'Source to scope the NuGet API Key to.'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
||||
|
||||
@@ -14,8 +14,9 @@ const core = __importStar(require("@actions/core"));
|
||||
const tc = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const exec_1 = require("@actions/exec");
|
||||
const pick_version_1 = __importDefault(require("./pick-version"));
|
||||
async function install(spec = 'latest') {
|
||||
async function install(spec = 'latest', apiKey, apiKeySource) {
|
||||
const tool = await pick_version_1.default(spec);
|
||||
core.debug(`Found NuGet version: ${tool.version}`);
|
||||
let cachePath = await tc.find('nuget.exe', tool.version);
|
||||
@@ -34,5 +35,13 @@ async function install(spec = 'latest') {
|
||||
core.addPath(cachePath);
|
||||
core.setOutput('nuget-version', tool.version);
|
||||
console.log(`Installed nuget.exe version ${tool.version}`);
|
||||
if (apiKey) {
|
||||
const args = ['SetApiKey', apiKey];
|
||||
if (apiKeySource) {
|
||||
args.push('-source', apiKeySource);
|
||||
}
|
||||
await exec_1.exec(path.join(cachePath, process.platform === 'win32' ? 'nuget.exe' : 'nuget'), args, { silent: true });
|
||||
console.log('Set up configured NuGet API key.');
|
||||
}
|
||||
}
|
||||
exports.default = install;
|
||||
|
||||
@@ -14,7 +14,7 @@ const core = __importStar(require("@actions/core"));
|
||||
const installer_1 = __importDefault(require("./installer"));
|
||||
async function run() {
|
||||
try {
|
||||
await installer_1.default(core.getInput('nuget-version'));
|
||||
await installer_1.default(core.getInput('nuget-version'), core.getInput('nuget-api-key'), core.getInput('nuget-api-key-source'));
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
||||
@@ -1,34 +1,54 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import pickVersion from './pick-version';
|
||||
|
||||
export default async function install(spec = 'latest') {
|
||||
const tool = await pickVersion(spec);
|
||||
core.debug(`Found NuGet version: ${tool.version}`);
|
||||
let cachePath = await tc.find('nuget.exe', tool.version);
|
||||
if (!cachePath) {
|
||||
const nugetExePath = await tc.downloadTool(tool.url);
|
||||
cachePath = await tc.cacheFile(
|
||||
nugetExePath,
|
||||
'nuget.exe',
|
||||
'nuget.exe',
|
||||
tool.version
|
||||
);
|
||||
}
|
||||
core.debug(`nuget.exe cache path: ${cachePath}.`);
|
||||
core.exportVariable('NUGET', `${cachePath}/nuget.exe`);
|
||||
if (process.platform !== 'win32') {
|
||||
core.debug(`Creating dummy 'nuget' script.`);
|
||||
const scriptPath = path.join(cachePath, 'nuget');
|
||||
fs.writeFileSync(
|
||||
scriptPath,
|
||||
`#!/bin/sh\nmono $MONO_OPTIONS ${path.join(cachePath, 'nuget.exe')} "$@"`
|
||||
);
|
||||
fs.chmodSync(scriptPath, '755');
|
||||
}
|
||||
core.addPath(cachePath);
|
||||
core.setOutput('nuget-version', tool.version);
|
||||
console.log(`Installed nuget.exe version ${tool.version}`);
|
||||
}
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {exec} from '@actions/exec';
|
||||
import pickVersion from './pick-version';
|
||||
|
||||
export default async function install(
|
||||
spec = 'latest',
|
||||
apiKey?: string,
|
||||
apiKeySource?: string
|
||||
) {
|
||||
const tool = await pickVersion(spec);
|
||||
core.debug(`Found NuGet version: ${tool.version}`);
|
||||
let cachePath = await tc.find('nuget.exe', tool.version);
|
||||
if (!cachePath) {
|
||||
const nugetExePath = await tc.downloadTool(tool.url);
|
||||
cachePath = await tc.cacheFile(
|
||||
nugetExePath,
|
||||
'nuget.exe',
|
||||
'nuget.exe',
|
||||
tool.version
|
||||
);
|
||||
}
|
||||
core.debug(`nuget.exe cache path: ${cachePath}.`);
|
||||
core.exportVariable('NUGET', `${cachePath}/nuget.exe`);
|
||||
if (process.platform !== 'win32') {
|
||||
core.debug(`Creating dummy 'nuget' script.`);
|
||||
const scriptPath = path.join(cachePath, 'nuget');
|
||||
fs.writeFileSync(
|
||||
scriptPath,
|
||||
`#!/bin/sh\nmono $MONO_OPTIONS ${path.join(cachePath, 'nuget.exe')} "$@"`
|
||||
);
|
||||
fs.chmodSync(scriptPath, '755');
|
||||
}
|
||||
core.addPath(cachePath);
|
||||
core.setOutput('nuget-version', tool.version);
|
||||
console.log(`Installed nuget.exe version ${tool.version}`);
|
||||
if (apiKey) {
|
||||
const args = ['SetApiKey', apiKey];
|
||||
if (apiKeySource) {
|
||||
args.push('-source', apiKeySource);
|
||||
}
|
||||
await exec(
|
||||
path.join(
|
||||
cachePath,
|
||||
process.platform === 'win32' ? 'nuget.exe' : 'nuget'
|
||||
),
|
||||
args,
|
||||
{silent: true}
|
||||
);
|
||||
console.log('Set up configured NuGet API key.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ import installer from './installer';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
await installer(core.getInput('nuget-version'));
|
||||
await installer(
|
||||
core.getInput('nuget-version'),
|
||||
core.getInput('nuget-api-key'),
|
||||
core.getInput('nuget-api-key-source')
|
||||
);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user