├── Dockerfile ├── entrypoint.sh ├── action.yml ├── README.md └── LICENSE /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | 3 | RUN apk add --no-cache ca-certificates bash jq 4 | 5 | COPY entrypoint.sh /entrypoint.sh 6 | ENTRYPOINT ["/entrypoint.sh"] 7 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 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 | jq '.version' | tr -d '"') 5 | 6 | echo "current-version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT 7 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Get current package version' 2 | description: 'Get the current version of the npm package' 3 | branding: 4 | color: 'gray-dark' 5 | 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/' 11 | outputs: 12 | current-version: 13 | description: 'Current version defined in the package.json file' 14 | runs: 15 | using: 'docker' 16 | image: 'Dockerfile' 17 | args: 18 | - ${{ inputs.path }} 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm-get-version-action 2 | 3 | This GitHub Action retrieves the package version from the package.json file and sets the version in the `current-version` output value usable in your workflow file. 4 | 5 | ## Example 6 | 7 | To use this action in your project, use the following: 8 | 9 | ```yaml 10 | - name: get-npm-version 11 | id: package-version 12 | uses: martinbeentjes/npm-get-version-action@v1.3.1 13 | ``` 14 | 15 | 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@v1.3.1 23 | with: 24 | path: packages/ 25 | ``` 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Martin Beentjes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------