This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
4 changed files
with
106 additions
and
19 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
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,29 @@ | ||
#!/bin/bash | ||
|
||
# Repository name (required) | ||
REPO=$1 | ||
|
||
# Version prefix from repo A (optional) | ||
VERSION_PREFIX=${2:-} # Defaults to an empty string if not provided | ||
|
||
# GitHub Token provided by GitHub Actions | ||
TOKEN=${GITHUB_TOKEN} | ||
|
||
# Fetch all tags from the repository. If VERSION_PREFIX is empty, all tags are fetched. | ||
# Fetch all tags from the GitHub API and filter for the latest tag containing the prefix | ||
if [[ -z "$VERSION_PREFIX" ]]; then | ||
# If no prefix is provided, fetch the latest release | ||
TAG=$(curl -sH "Authorization: token $TOKEN" "https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name') | ||
else | ||
# Fetch all tags, filter by prefix, and get the most recent one | ||
TAG=$(curl -sH "Authorization: token $TOKEN" "https://api.github.com/repos/$REPO/tags" \ | ||
| jq -r --arg PREFIX "$VERSION_PREFIX" '[.[0] | select(.name | startswith($PREFIX))] | sort_by(.name) | .[-1].name') | ||
fi | ||
echo "$TAG" | ||
|
||
# Sanitize repository name to create a valid environment variable name | ||
# Replace '/' with '_' and convert to lower case | ||
ENV_REPO_NAME=$(echo "$REPO" | tr '/' '_' | tr '[:upper:]' '[:lower:]') | ||
|
||
# Output the tag for subsequent steps | ||
echo "latest_tag_${ENV_REPO_NAME}=$TAG" >> $GITHUB_ENV |