Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding prefix input to the tag query #42

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/rm@v1.0.2
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