-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a next-repository-tag-number action
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM alpine:latest | ||
RUN apk add --update --no-cache --no-progress curl jq | ||
COPY get-next-tag-number.sh /get-next-tag-number.sh | ||
ENTRYPOINT ["/get-next-tag-number.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Next Repository Tag Number | ||
description: Get the next tag number for a repository. | ||
|
||
inputs: | ||
repository_url: | ||
description: The URL of the OCI-compatible repository. | ||
required: true | ||
bearer_token: | ||
description: Optional bearer token for repository authentication. | ||
required: false | ||
initial_number: | ||
description: Starting tag number if no tags exist. | ||
default: '1' | ||
required: false | ||
tag_prefix: | ||
description: Prefix for the tags. | ||
default: 'build-' | ||
required: false | ||
|
||
outputs: | ||
tag: | ||
description: The next tag. | ||
value: ${{ steps.next-tag.outputs.tag }} | ||
number: | ||
description: The next tag number. | ||
value: ${{ steps.next-tag.outputs.number }} | ||
|
||
runs: | ||
using: docker | ||
image: Dockerfile | ||
args: | ||
- ${{ inputs.repository_url }} | ||
- ${{ inputs.bearer_token }} | ||
- ${{ inputs.initial_number }} | ||
- ${{ inputs.tag_prefix }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env sh | ||
|
||
REPOSITORY_URL=$1 | ||
BEARER_TOKEN=$2 | ||
INITIAL_NUMBER=${3:-1} | ||
TAG_PREFIX=${4:-"build-"} | ||
|
||
if [ -n "$BEARER_TOKEN" ]; then | ||
AUTH_HEADER="-H \"Authorization: Bearer ${BEARER_TOKEN}\"" | ||
else | ||
AUTH_HEADER="" | ||
fi | ||
|
||
TAGS=$(curl -s $AUTH_HEADER "${REPOSITORY_URL}/tags/list" | jq -r '.tags[]' || echo "") | ||
|
||
if [ -z "$TAGS" ]; then | ||
echo "No existing tags were found. Using initial tag number ${INITIAL_NUMBER}." | ||
NEXT_TAG_NUMBER=$INITIAL_NUMBER | ||
else | ||
HIGHEST_TAG=$(echo "$TAGS" | grep -Eo "${TAG_PREFIX}[0-9]+" | sort -V | tail -n 1) | ||
|
||
if [ -z "$HIGHEST_TAG" ]; then | ||
echo "No existing tags with the specified prefix were found. Using initial tag number ${INITIAL_NUMBER}." | ||
NEXT_TAG_NUMBER=$INITIAL_NUMBER | ||
else | ||
HIGHEST_TAG_NUMBER=$(echo "$HIGHEST_TAG" | grep -Eo '[0-9]+') | ||
NEXT_TAG_NUMBER=$((HIGHEST_TAG_NUMBER + 1)) | ||
fi | ||
fi | ||
|
||
NEXT_TAG="${TAG_PREFIX}${NEXT_TAG_NUMBER}" | ||
echo "Next tag: $NEXT_TAG" | ||
echo "tag=$NEXT_TAG" >> $GITHUB_OUTPUT | ||
echo "number=$NEXT_TAG_NUMBER" >> $GITHUB_OUTPUT |