From e2f5a781105ed18e18f05538f77f130ae811d091 Mon Sep 17 00:00:00 2001 From: Amit Ben Ami Date: Wed, 21 Dec 2022 11:52:33 +0200 Subject: [PATCH] feat(prefix): adding prefix to the tag query --- README.md | 3 +++ action.yml | 3 +++ main.js | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3121f30..fad4d90 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,10 @@ By default, this action will fail if no tag can be found, however, it accepts a tag can be found. Keep in mind that when this action is used in a workflow that has no `.git` directory, it will still fail, and the fallback tag isn't used. +It is also accepts a `prefix` string to query the tags based on it. + * `fallback`: `1.0.0` +* `prefix`: `tag-prefix` ## Output diff --git a/action.yml b/action.yml index 38db9b8..afd33da 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ inputs: fallback: description: 'Fallback tag to use when no previous tag can be found' required: false + prefix: + description: 'Prefix to query the tag by' + required: false outputs: tag: description: 'Latest tag' diff --git a/main.js b/main.js index f347af1..f06f28e 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,8 @@ const { exec } = require('child_process'); const fs = require('fs'); +const tagPrefix = `${process.env.INPUT_PREFIX || ''}*`; -exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/*"`, (err, tag, stderr) => { +exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPrefix}"`, (err, tag, stderr) => { tag = tag.trim(); if (err) {