From e2f5a781105ed18e18f05538f77f130ae811d091 Mon Sep 17 00:00:00 2001 From: Amit Ben Ami Date: Wed, 21 Dec 2022 11:52:33 +0200 Subject: [PATCH 1/2] 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) { From b8a42836611df047797093e44d1f1c9af72730c0 Mon Sep 17 00:00:00 2001 From: Amit Ben Ami Date: Wed, 21 Dec 2022 12:04:13 +0200 Subject: [PATCH 2/2] feat(prefix): adding prefix to the CI --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f67f16b..535a2eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: