Skip to content

Commit

Permalink
Merge pull request #42 from AmitBenAmi/adding-tag-prefix
Browse files Browse the repository at this point in the history
Adding `prefix` input to the tag query
  • Loading branch information
WyriHaximus authored Dec 31, 2022
2 parents dc52ee2 + b8a4283 commit 385a2a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ jobs:
echo "Timestamp: ${{ steps.previoustag.outputs.timestamp }}"
test -n "${{ steps.previoustag.outputs.tag }}"
test -n "${{ steps.previoustag.outputs.timestamp }}"
- name: Add tag with prefix
run: |
git tag tag-with-prefix-v1.0.0
- name: 'Get Previous tag with prefix'
id: previoustagwithprefix
uses: ./
with:
prefix: tag-with-prefix-v
- run: |
echo "Tag: ${{ steps.previoustagwithprefix.outputs.tag }}"
echo "Timestamp: ${{ steps.previoustagwithprefix.outputs.timestamp }}"
test -n "${{ steps.previoustagwithprefix.outputs.tag }}"
test -n "${{ steps.previoustagwithprefix.outputs.timestamp }}"
- name: Remove tags
uses: JesseTG/[email protected]
with:
Expand Down
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 385a2a0

Please sign in to comment.