forked from reloc8/action-latest-release-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
50 lines (44 loc) · 1.43 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: latest-release-action
description: Fetch the latest release version for the current repository, optionally filtering by tag prefix.
author: alessiovierti
branding:
icon: tag
color: purple
inputs:
tag-prefix:
description: 'Prefix to filter tags by. If not specified, all tags will be considered.'
required: false
default: ''
outputs:
latest-release:
description: Latest release version
value: ${{ steps.fetch-latest-release-version.outputs.latest-release }}
commit-sha:
description: Latest release tag's commit sha
value: ${{ steps.fetch-latest-release-version.outputs.commit-sha }}
runs:
using: composite
steps:
- id: fetch-latest-release-version
shell: bash
run: |
set -o xtrace
set -o pipefail
if [[ "$(git rev-parse --is-shallow-repository)" == true ]]
then
git fetch --tags --prune --unshallow
else
git fetch --tags --prune
fi
git branch
PREFIX=${{ inputs.tag-prefix }}
if LAST_TAG=$(git tag -l "${PREFIX}*" | sort -V | tail -1)
then
echo "latest-release=${LAST_TAG}" | tee -a ${GITHUB_OUTPUT}
else
echo "ERROR: No matching tags found." >&2
exit 1
fi
COMMIT_SHA=$(git rev-list -n 1 ${LAST_TAG})
echo "commit-sha=${COMMIT_SHA}" | tee -a ${GITHUB_OUTPUT}
echo The latest release version is "${LAST_TAG} (${COMMIT_SHA})".