Skip to content

Commit

Permalink
Merge pull request #28 from Erriez/staging/erriez/add-default-value
Browse files Browse the repository at this point in the history
Add default value
  • Loading branch information
rajbos authored Apr 10, 2023
2 parents 30d2219 + 8c9c4fb commit 3f6118e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ on:
id: tag
uses: devops-actions/[email protected]
with:
# Optionally strip `v` prefix
strip_v: true
strip_v: true # Optional: Remove 'v' character from version
default: v0.0.0 # Optional: Default version when tag not found

- name: Use tag
run: echo ${{steps.tag.outputs.tag}}
```
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ inputs:
strip_v:
required: false
default: false
description: Whether to strip "v" from the tag or not
description: Whether to strip "v" from the tag or not (optional)
default:
required: false
description: Set default version (optional)
outputs:
tag:
description: Git tag name
Expand Down
19 changes: 14 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ async function main() {
try {
const ref = process.env.GITHUB_REF
const strip_v = process.env.INPUT_STRIP_V
const default_version = process.env.INPUT_DEFAULT
let tag

if(!ref)
throw "GITHUB_REF is not defined"
if(!ref.startsWith("refs/tags/"))
throw `Not a tag ref (${ref})`
let tag = ref.replace(/^refs\/tags\//, "")


if(ref.startsWith("refs/tags/"))
tag = ref.replace(/^refs\/tags\//, "")
else if(default_version)
tag = default_version
else
throw `Not a tag ref (${ref}) or default version not set`

if(!tag)
throw `Not tag version found`

if(strip_v === "true" && tag.startsWith("v"))
tag = tag.replace(/^v/, "")


core.info(`ref=${ref}`)
core.info(`tag=${tag}`)

Expand Down

0 comments on commit 3f6118e

Please sign in to comment.