GitHub Action that reads a package.json file and exposes its version field as a workflow output.
This is useful when you want to reuse the package version for tagging, naming build artifacts, publishing, or release automation.
- Reads
package.jsonfrom the repository root by default - Supports packages inside subdirectories, which is useful for monorepos
- Exposes the detected version as
steps.<id>.outputs.version
Make sure your workflow checks out the repository before running the action.
on: push
name: Build
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Extract package version
id: package_version
uses: saionaro/extract-package-version@v1.4.0
- name: Print version
run: echo "${{ steps.package_version.outputs.version }}"| Name | Required | Default | Description |
|---|---|---|---|
path |
No | Repository root | Directory that contains package.json |
| Name | Description |
|---|---|
version |
The value of the version field from package.json |
If your package lives in a subdirectory, pass that directory through path.
on: push
name: Build
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract package version
id: package_version
uses: saionaro/extract-package-version@v1.4.0
with:
path: packages/my-package
- name: Use version
run: echo "Version: ${{ steps.package_version.outputs.version }}"pathshould point to the directory containingpackage.json, not to the file itself- The action fails if the file cannot be read or if
package.jsondoes not contain a validversion