Skip to content

Commit 3b4323c

Browse files
authored
Merge pull request #77 from WyriHaximus/absolve-prefix-into-pattern
Absolve `prefix` into `pattern`
2 parents 03e9ecf + f9b50b5 commit 3b4323c

4 files changed

Lines changed: 18 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
id: previoustagwithprefix
7777
uses: ./
7878
with:
79-
prefix: tag-with-prefix-v
79+
pattern: tag-with-prefix-v*
8080
- run: |
8181
echo "Tag: ${{ steps.previoustagwithprefix.outputs.tag }}"
8282
echo "Timestamp: ${{ steps.previoustagwithprefix.outputs.timestamp }}"
@@ -113,7 +113,7 @@ jobs:
113113
fail-fast: false
114114
matrix:
115115
include:
116-
- pattern: "v*[0-9].*[0-9].*[0-9]"
116+
- pattern: v*[0-9].*[0-9].*[0-9]
117117
expectedTag: v1.0.1
118118
os: ubuntu-latest
119119
- pattern: "v*[0-9].*[0-9].*[0-9]"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ GitHub Action that gets the latest tag from Git
1313

1414
By default, this action will fail if no tag can be found, however, it accepts a `fallback` tag that will be used when no
1515
tag can be found. Keep in mind that when this action is used in a workflow that has no `.git` directory, it will still
16-
fail, and the fallback tag isn't used. It is also accepts a `prefix` string to query the tags based on it. And finally
17-
it takes a `workingDirectory` if you need to look for a tag in an alternative path.
16+
fail, and the fallback tag isn't used. It is also accepts a `pattern` string to query the tags based on it. Pattern to
17+
query the tag by this can be semver (`v*[0-9].*[0-9].*[0-9]`) or a simple monotonically increasing integer (`r*`) and
18+
defaults to * And finally it takes a `workingDirectory` if you need to look for a tag in an alternative path.
1819

1920
* `fallback`: `1.0.0`
20-
* `prefix`: `tag-prefix`
2121
* `pattern`: `v*[0-9].*[0-9].*[0-9]`
2222
* `workingDirectory`: `another/path/where/a/git/repo/is/checked/out`
2323

action.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
name: 'Get Latest Tag'
2-
description: 'Get the latest tag from git and outputs that for use in other actions'
1+
name: Get Latest Tag
2+
description: Get the latest tag from git and outputs that for use in other actions
33
branding:
4-
icon: 'tag'
5-
color: 'gray-dark'
4+
icon: tag
5+
color: gray-dark
66
inputs:
77
fallback:
8-
description: 'Fallback tag to use when no previous tag can be found'
9-
required: false
10-
prefix:
11-
description: 'Prefix to query the tag by'
8+
description: Fallback tag to use when no previous tag can be found
129
required: false
1310
pattern:
14-
description: 'Pattern to query the tag by'
11+
description: "Pattern to query the tag by this can be semver (v*[0-9].*[0-9].*[0-9]) or a simple monotonically increasing integer (r*) and defaults to *"
12+
default: "*"
1513
required: false
1614
workingDirectory:
1715
description: The directory to run this workflow in
1816
default: ""
1917
required: false
2018
outputs:
2119
tag:
22-
description: 'Latest tag'
20+
description: Latest tag
2321
timestamp:
24-
description: 'Latest tag timestamp'
22+
description: Latest tag timestamp
2523
runs:
26-
using: 'node20'
27-
main: 'main.js'
24+
using: node20
25+
main: main.js

main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const { exec } = require('child_process');
22
const fs = require('fs');
3-
const tagPrefix = `${process.env.INPUT_PREFIX || ''}*`;
4-
const tagPattern = `${process.env.INPUT_PATTERN || ''}`;
3+
const tagPattern = `${process.env.INPUT_PATTERN || '*'}`;
54
const workingDirectory = process.env.INPUT_WORKINGDIRECTORY || null;
65

76
console.log('\x1b[33m%s\x1b[0m', 'Working directory: ', workingDirectory || '');
87

9-
exec(`git for-each-ref --sort=-refname --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPrefix}${tagPattern}"`, {cwd: workingDirectory}, (err, tag, stderr) => {
8+
exec(`git for-each-ref --sort=-refname --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPattern}"`, {cwd: workingDirectory}, (err, tag, stderr) => {
109
tag = tag.trim();
1110

1211
if (err) {

0 commit comments

Comments
 (0)