Skip to content

Commit

Permalink
Add fallback tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Apr 23, 2021
1 parent 2d4e466 commit b4810d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ jobs:
uses: ./
- run: |
echo "${{ steps.previoustag.outputs.tag }}"
- run: rm .git/refs/tags -Rfv
- name: 'Get Previous tag with fallback'
id: previoustagwithfallback
uses: ./
with:
fallback: v1.0.0
- run: |
echo "${{ steps.previoustagwithfallback.outputs.tag }}"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: 1.0.0 # Optional fallback tag to use when no tag can be found
- name: 'Get next minor version'
id: semvers
uses: "WyriHaximus/github-action-next-semvers@v1"
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ description: 'Get the latest tag from git and outputs that for use in other acti
branding:
icon: 'tag'
color: 'gray-dark'
inputs:
fallback:
description: 'Fallback tag to use when no previous tag can be found'
required: false
outputs:
tag:
description: 'Latest tag'
Expand Down
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ exec('git rev-list --tags --max-count=1', (err, rev, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any tags because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
if (process.env.INPUT_FALLBACK) {
let timestamp = Math.floor(new Date().getTime() / 1000);
console.log('\x1b[33m%s\x1b[0m', 'Falling back to default tag');
console.log('\x1b[32m%s\x1b[0m', `Found tag: ${process.env.INPUT_FALLBACK}`);
console.log('\x1b[32m%s\x1b[0m', `Found timestamp: ${timestamp}`);
console.log(`::set-output name=tag::${process.env.INPUT_FALLBACK}`);
console.log(`::set-output name=timestamp::${timestamp}`);
process.exit(0);
}
process.exit(1);
}

Expand Down

0 comments on commit b4810d7

Please sign in to comment.