Skip to content

Commit

Permalink
Merge pull request #14 from AArnott/useCloud
Browse files Browse the repository at this point in the history
Use cloud command and offer switch options
  • Loading branch information
AArnott authored Jan 15, 2020
2 parents 279fa8e + 8a4f804 commit 1cb7bfa
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 39 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: nbgv
- name: nbgv -c -p src
uses: ./
with:
path: src
allVars: false
- name: Print env vars
run: gci env:NBGV_*
run: gci env:NBGV_*,env:Git*
shell: pwsh
- name: nbgv -a -p src
uses: ./
with:
path: src
commonVars: false
- name: Print env vars
run: gci env:NBGV_*,env:Git*
shell: pwsh
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,37 @@ It does the equivalent of:

```bash
dotnet tool install -g nbgv
nbgv get-version -f json > nbgv.json
nbgv cloud --all-vars
nbgv cloud --all-vars --common-vars
```

This sets many environment variables to the various forms of the version for your repo or project.

## Inputs

### Path
### path

**Optional** The path to the directory for which the version should be determined. This should be at or below the directory containing the version.json file. Default is repo root directory.

### commonVars

**Optional** Defines a few common version variables as cloud build variables, with a "Git" prefix (e.g. GitBuildVersion, GitBuildVersionSimple, GitAssemblyInformationalVersion).

Adds the `--common-vars` switch to the `nbgv cloud` command.

Default value is `true`.

### allVars

**Optional** Defines ALL version variables as cloud build variables, with a "NBGV_" prefix.

Adds the `--all-vars` switch to the `nbgv cloud` command.

Default value is `true`.

### toolVersion

**Optional** The version of the nbgv dotnet CLI tool to install and use. If not specified, the default is the latest stable version.

## Example usage

``` yaml
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ inputs:
description: The path to the directory for which the version should be determined. This should be at or below the directory containing the version.json file. Default is repo root directory.
required: false
default: '.'
allVars:
description: Defines ALL version variables as cloud build variables, with a "NBGV_" prefix.
required: false
default: 'true'
commonVars:
description: Defines a few common version variables as cloud build variables, with a "Git" prefix (e.g. GitBuildVersion, GitBuildVersionSimple, GitAssemblyInformationalVersion).
required: false
default: 'true'
toolVersion:
description: The version of the nbgv dotnet CLI tool to install and use. If not specified, the default is the latest stable version.
required: false
runs:
using: node12
main: lib/main.js
29 changes: 13 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,31 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
// install nbgv
let exitCode = yield exec.exec('dotnet', ['tool', 'install', '-g', 'nbgv'], { ignoreReturnCode: true });
let installArgs = ['tool', 'install', '-g', 'nbgv'];
const toolVersion = core.getInput('toolVersion');
if (toolVersion) {
installArgs.push('--version', toolVersion);
}
let exitCode = yield exec.exec('dotnet', installArgs, { ignoreReturnCode: true });
if (exitCode > 1) {
throw new Error("dotnet tool install failed.");
}
// add .dotnet/tools to the path
core.addPath(path.join(os.homedir(), '.dotnet', 'tools'));
// run nbgv
let jsonStr = '';
let args = ['get-version', '-f', 'json'];
let args = ['cloud'];
const dir_path = core.getInput('path');
if (dir_path) {
args.push('-p', dir_path);
}
yield exec.exec('nbgv', args, {
listeners: {
stdout: (data) => {
jsonStr += data.toString();
}
}
});
// parse json and export all cloud variables
const json = JSON.parse(jsonStr);
for (const key in json.CloudBuildAllVars) {
if (json.CloudBuildAllVars.hasOwnProperty(key)) {
const element = json.CloudBuildAllVars[key];
core.exportVariable(key, element);
}
if (core.getInput('commonVars') === 'true') {
args.push('-c');
}
if (core.getInput('allVars') === 'true') {
args.push('-a');
}
yield exec.exec('nbgv', args);
}
catch (error) {
core.setFailed(error.message);
Expand Down
33 changes: 15 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import * as path from 'path'
async function run() {
try {
// install nbgv
let exitCode = await exec.exec('dotnet', ['tool', 'install', '-g', 'nbgv'], { ignoreReturnCode: true });
let installArgs = ['tool', 'install', '-g', 'nbgv'];
const toolVersion = core.getInput('toolVersion');
if (toolVersion) {
installArgs.push('--version', toolVersion);
}

let exitCode = await exec.exec('dotnet', installArgs, { ignoreReturnCode: true });
if (exitCode > 1) {
throw new Error("dotnet tool install failed.");
}
Expand All @@ -16,28 +22,19 @@ async function run() {

// run nbgv
let jsonStr = '';
let args = ['get-version', '-f', 'json'];
let args = ['cloud'];
const dir_path = core.getInput('path');
if (dir_path) {
args.push('-p', dir_path);
}

await exec.exec('nbgv', args, {
listeners: {
stdout: (data) => {
jsonStr += data.toString();
}
}
});

// parse json and export all cloud variables
const json = JSON.parse(jsonStr);
for (const key in json.CloudBuildAllVars) {
if (json.CloudBuildAllVars.hasOwnProperty(key)) {
const element = json.CloudBuildAllVars[key];
core.exportVariable(key, element);
}
if (core.getInput('commonVars') === 'true') {
args.push('-c');
}
if (core.getInput('allVars') === 'true') {
args.push('-a');
}

await exec.exec('nbgv', args);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit 1cb7bfa

Please sign in to comment.