Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Add feature for stripping v prefix (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhd999 authored Oct 20, 2021
1 parent 1ae757c commit 9674bdc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
- name: Test dev
run: |
test "v1.0.0" = "${{steps.tag_dev.outputs.tag}}"
- name: Run dev with strip v
id: tag_dev_strip_v
run: GITHUB_REF=refs/tags/v1.0.0 INPUT_STRIP_V=true node main.js
- name: Test dev with strip v
run: |
test "1.0.0" = "${{steps.tag_dev_strip_v.outputs.tag}}"
- name: Run prod
id: tag_prod
if: startsWith(github.ref, 'refs/tags') == true
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ description: Get tag name from GITHUB_REF environment variable
branding:
icon: tag
color: gray-dark
inputs:
strip_v:
required: false
default: false
description: Whether to strip "v" from the tag or not
outputs:
tag:
description: Git tag name
Expand Down
7 changes: 6 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ const core = require("@actions/core")
async function main() {
try {
const ref = process.env.GITHUB_REF
const strip_v = process.env.INPUT_STRIP_V
if(!ref)
throw "GITHUB_REF is not defined"
if(!ref.startsWith("refs/tags/"))
throw `Not a tag ref (${ref})`
const tag = ref.replace(/^refs\/tags\//, "")
let tag = ref.replace(/^refs\/tags\//, "")

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


core.info(`ref=${ref}`)
core.info(`tag=${tag}`)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9674bdc

Please sign in to comment.