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

Add stamp input to apply version stamp to package.json #24

Merged
merged 1 commit into from
May 10, 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
7 changes: 7 additions & 0 deletions .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ jobs:
gci env:NBGV_*,env:Git*
if (-not $env:NBGV_Version) { exit 1 }
shell: pwsh
- name: nbgv (stamp)
uses: ./
with:
stamp: package.json
- name: print package.json version
run: npm ls nbgv-action ; exit 0
shell: bash --noprofile --norc {0}
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All inputs are optional.
`path`|Repo root|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.
`setCommonVars`|false|Defines a few common version variables as environment variables, with a "Git" prefix (e.g. GitBuildVersion, GitBuildVersionSimple, GitAssemblyInformationalVersion). Adds the `--common-vars` switch to the `nbgv cloud` command.
`setAllVars`|false|Defines ALL version variables as environment variables, with a "NBGV_" prefix. Adds the `--all-vars` switch to the `nbgv cloud` command.
`stamp`||The path to a file whose version setting should be changed to match the computed version. Supported file types: `package.json`
`toolVersion`|latest stable|The version of the nbgv dotnet CLI tool to install and use. If not specified, the default is the latest stable version.

## Outputs
Expand Down Expand Up @@ -56,20 +57,28 @@ SemVer2|The SemVer 2.0 compliant version.
### Using step outputs

```yaml
- uses: aarnott/nbgv@v0.3
- uses: aarnott/nbgv@master
id: nbgv
- run: echo 'SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}'
```
### Using environment variables
```yaml
- uses: aarnott/nbgv@v0.3
- uses: aarnott/nbgv@master
with:
setAllVars: true
- run: echo "NBGV_SemVer2 $NBGV_SemVer2"
```
### Stamp the version on a package.json file
```yaml
- uses: aarnott/nbgv@master
with:
stamp: package.json
```
## Checkout requirements
Git history based versioning tools rely on history being included in the clone.
Expand Down
12 changes: 12 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ async function run() {
}
await exec_1.exec('nbgv', args);
}
if (settings_1.Inputs.stamp) {
if (path.basename(settings_1.Inputs.stamp) === 'package.json') {
await exec_1.exec('npm', ['version', versionProperties.NpmPackageVersion, '--git-tag-version=false', '--allow-same-version']);
}
else {
throw new Error(`Unable to stamp unsupported file format: ${path.basename(settings_1.Inputs.stamp)}`);
}
}
}
catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -1392,6 +1400,10 @@ class Inputs {
const result = core.getInput('path');
return result === '' || result === null ? undefined : result;
}
static get stamp() {
const result = core.getInput('stamp');
return result === '' || result === null ? undefined : result;
}
static get setAllVars() {
return core.getInput('setAllVars') === 'true';
}
Expand Down
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ async function run() {

await exec('nbgv', args);
}

// Stamp the version on an existing file, if desired.
if (Inputs.stamp) {
if (path.basename(Inputs.stamp) === 'package.json') {
await exec('npm', ['version', versionProperties.NpmPackageVersion, '--git-tag-version=false', '--allow-same-version']);
} else {
throw new Error(`Unable to stamp unsupported file format: ${path.basename(Inputs.stamp)}`);
}
}
} catch (error) {
core.setFailed(error.message);
}
Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export class Inputs {
return result === '' || result === null ? undefined : result;
}

static get stamp(): string | undefined {
const result = core.getInput('stamp');
return result === '' || result === null ? undefined : result;
}

static get setAllVars(): boolean {
return core.getInput('setAllVars') === 'true';
}
Expand Down