diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d06d94..f994cff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/action.yml b/action.yml index 7a7430e..6c6d7bf 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/main.js b/main.js index 86c5554..51643c1 100644 --- a/main.js +++ b/main.js @@ -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}`) diff --git a/package-lock.json b/package-lock.json index 41ec504..bb4bdc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,4 +9,4 @@ "integrity": "sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig==" } } -} +} \ No newline at end of file