diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8aa4a9..5c4e354 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,3 +22,14 @@ jobs: uses: ./ - run: | echo "${{ steps.previoustag.outputs.tag }}" + - name: Remove tags + uses: JesseTG/rm@v1.0.2 + with: + path: .git/refs/tags + - name: 'Get Previous tag with fallback' + id: previoustagwithfallback + uses: ./ + with: + fallback: v1.0.0 + - run: | + echo "${{ steps.previoustagwithfallback.outputs.tag }}" diff --git a/README.md b/README.md index c03be2c..839b453 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/action.yml b/action.yml index 98960bd..592205a 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/main.js b/main.js index 2dc252d..f487233 100644 --- a/main.js +++ b/main.js @@ -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); }