File tree Expand file tree Collapse file tree 4 files changed +79
-0
lines changed
next-repository-tag-number Expand file tree Collapse file tree 4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file.
99The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.1.0/ ) ,
1010and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
1111
12+ ## [ Unreleased]
13+
14+ ### Added
15+
16+ - Initial release of the next-repository-tag-number action.
17+
1218## [ 1.0.1] - 2024-11-04
1319
1420### Fixed
Original file line number Diff line number Diff line change 1+ FROM alpine:latest
2+ RUN apk add --update --no-cache --no-progress curl jq
3+ COPY get-next-tag-number.sh /get-next-tag-number.sh
4+ ENTRYPOINT ["/get-next-tag-number.sh" ]
Original file line number Diff line number Diff line change 1+ name : Next Repository Tag Number
2+ description : Get the next tag number for a repository.
3+
4+ inputs :
5+ repository_url :
6+ description : The URL of the OCI-compatible repository.
7+ required : true
8+ bearer_token :
9+ description : Optional bearer token for repository authentication.
10+ required : false
11+ initial_number :
12+ description : Starting tag number if no tags exist.
13+ default : ' 1'
14+ required : false
15+ tag_prefix :
16+ description : Prefix for the tags.
17+ default : ' build-'
18+ required : false
19+
20+ outputs :
21+ tag :
22+ description : The next tag.
23+ value : ${{ steps.next-tag.outputs.tag }}
24+ number :
25+ description : The next tag number.
26+ value : ${{ steps.next-tag.outputs.number }}
27+
28+ runs :
29+ using : docker
30+ image : Dockerfile
31+ args :
32+ - ${{ inputs.repository_url }}
33+ - ${{ inputs.bearer_token }}
34+ - ${{ inputs.initial_number }}
35+ - ${{ inputs.tag_prefix }}
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env sh
2+
3+ REPOSITORY_URL=$1
4+ BEARER_TOKEN=$2
5+ INITIAL_NUMBER=${3:- 1}
6+ TAG_PREFIX=${4:- " build-" }
7+
8+ if [ -n " $BEARER_TOKEN " ]; then
9+ AUTH_HEADER=" -H \" Authorization: Bearer ${BEARER_TOKEN} \" "
10+ else
11+ AUTH_HEADER=" "
12+ fi
13+
14+ TAGS=$( curl -s $AUTH_HEADER " ${REPOSITORY_URL} /tags/list" | jq -r ' .tags[]' || echo " " )
15+
16+ if [ -z " $TAGS " ]; then
17+ echo " No existing tags were found. Using initial tag number ${INITIAL_NUMBER} ."
18+ NEXT_TAG_NUMBER=$INITIAL_NUMBER
19+ else
20+ HIGHEST_TAG=$( echo " $TAGS " | grep -Eo " ${TAG_PREFIX} [0-9]+" | sort -V | tail -n 1)
21+
22+ if [ -z " $HIGHEST_TAG " ]; then
23+ echo " No existing tags with the specified prefix were found. Using initial tag number ${INITIAL_NUMBER} ."
24+ NEXT_TAG_NUMBER=$INITIAL_NUMBER
25+ else
26+ HIGHEST_TAG_NUMBER=$( echo " $HIGHEST_TAG " | grep -Eo ' [0-9]+' )
27+ NEXT_TAG_NUMBER=$(( HIGHEST_TAG_NUMBER + 1 ))
28+ fi
29+ fi
30+
31+ NEXT_TAG=" ${TAG_PREFIX}${NEXT_TAG_NUMBER} "
32+ echo " Next tag: $NEXT_TAG "
33+ echo " tag=$NEXT_TAG " >> $GITHUB_OUTPUT
34+ echo " number=$NEXT_TAG_NUMBER " >> $GITHUB_OUTPUT
You can’t perform that action at this time.
0 commit comments