-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(action-git): add extract-version-from-tag action
- Loading branch information
1 parent
3f7fe35
commit 8a78dad
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Git: extract-version-from-tag | ||
|
||
## Behavior | ||
|
||
Extract version number from semver tag. | ||
WARNING: Must be run on tag reference. | ||
|
||
## Usage | ||
|
||
```yaml | ||
jobs: | ||
extract-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout Code" | ||
uses: "actions/checkout@v3" | ||
|
||
- name: "extract version" | ||
uses: "meero-com/github-actions-shared-workflows/actions/git/extract-version-from-tag@main" | ||
with: | ||
PREFIX: "DEV-v" | ||
``` | ||
Will outputs | ||
```yaml | ||
version_number: 1.2.3 # if ran on tag DEV-v1.2.3 | ||
``` | ||
Beware of using a `@ref` (`@main` in the example above) which suits your stability requirements in your workflow: | ||
|
||
* Use `@main` if you always want to use the latest version of the workflow. | ||
* Use `@<tag>` if you wan to use a specific frozen version of the workflow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: "Extract version from tag" | ||
description: "Extract version number from semver tag. Must be run on tag reference." | ||
|
||
inputs: | ||
PREFIX: | ||
description: "Prefix of the tag (example 'prefix-v': 'prefix-v1.0.0' -> '1.0.0')" | ||
required: false | ||
default: 'v' | ||
|
||
outputs: | ||
version_number: | ||
description: "version number (ex: 1.0.0)" | ||
value: ${{ steps.extract-version.outputs.version }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "extract version from refname" | ||
id: extract-version | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const getVersion = function (ref_name) { | ||
var rx = /${{ inputs.PREFIX }}([0-9]+\.[0-9]+\.[0-9]+)/g; | ||
var arr = rx.exec(ref_name); | ||
return arr[1]; | ||
} | ||
core.setOutput('version', getVersion('${{ github.ref_name }}')) |