Skip to content

Commit

Permalink
feat(prefix): adding prefix to the tag query
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitBenAmi committed Dec 21, 2022
1 parent dc52ee2 commit e2f5a78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit e2f5a78

Please sign in to comment.