Skip to content

Commit 3995547

Browse files
authored
Support package.json (martinbeentjes#6)
* Update action.yml * Update action.yml * Update entrypoint.sh * Update README.md * Update entrypoint.sh
1 parent d081d46 commit 3995547

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ To use this action in your project, use the following:
1313
```
1414
1515
The Action sets an output variable called `current-version` which can be used in a following step by using `${{ steps.package-version.outputs.current-version}}`.
16+
17+
If you are using a monorepo or otherwise have some packages in a subdirectory of your repo, add the path to the `package.json` as a parameter:
18+
19+
```yaml
20+
- name: get-npm-version
21+
id: package-version
22+
uses: martinbeentjes/npm-get-version-action@master
23+
with:
24+
path: packages/<yourpackage>
25+
```

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ description: 'Get the current version of the npm package'
33
branding:
44
color: 'gray-dark'
55
icon: 'align-center'
6+
inputs:
7+
path:
8+
required: false
9+
default: ''
10+
description: 'Path to package.json file (directories only), e.g. packages/mypackage/'
611
outputs:
712
current-version:
813
description: 'Current version defined in the package.json file'
914
runs:
1015
using: 'docker'
1116
image: 'Dockerfile'
12-
17+
args:
18+
- ${{ inputs.path }}

entrypoint.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh -l
2-
3-
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
2+
PACKAGE_JSON_PATH="${1-.}"
3+
echo "Reading package.json from ${PACKAGE_JSON_PATH}/package.json"
4+
PACKAGE_VERSION=$(cat ${PACKAGE_JSON_PATH}/package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
45

56
echo ::set-output name=current-version::$PACKAGE_VERSION

0 commit comments

Comments
 (0)