DEV Community

Pon Cheol, Ku
Pon Cheol, Ku

Posted on

GitHub actions: Get version action

This is an action to get the version string from project file such as package.json, .csproj (c# sdk style project file)

Of course, you can do this with a script, but I hope this is a convenient solution for those who find scripts difficult.

Usages

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - uses: bbonkr/get-version-action@v1
    id: get_version
    with:
      project: './package.json'
  - name: logging
    run: |
      echo "version=${{ steps.get_version.outputs.version }}"
      echo "major=${{ steps.get_version.outputs.major }}"
      echo "minor=${{ steps.get_version.outputs.minor }}"
      echo "patch=${{ steps.get_version.outputs.patch }}"
      echo "pre-release=${{ steps.get_version.outputs.pre-release }}"
      echo "build=${{ steps.get_version.outputs.build }}"
Enter fullscreen mode Exit fullscreen mode

Inputs

Name Required Description
project Your project file path. Support package.json, .csproj (c# sdk style project file)

Support file

  • package.json
  • .csproj (c# sdk style project file)

Outputs

Name Description
version version string, If does not find version string, throws exception.
major major of version (SEMVER1)
minor minor of version (SEMVER1)
patch patch of version (SEMVER1)
pre-release pre-release of version (SEMVER1)
build build of version (SEMVER1)

e.g.)
input: v1.2.3-pre.4+5

outputs:
version: v1.2.3-pre.4+5
major: 1
minor: 2
patch: 3
pre-release: pre.4
build: 5

Closing

You can see code from GitHub: bbonkr/get-version-action

You can find GitHub Action from GitHub Marketplace: get-version-action

I hope this is a convenient solution for your version management.


  1. https://semver.org/ 

Top comments (0)