From 8f858982b9971bab45dc2f4771dacaca8bb23f55 Mon Sep 17 00:00:00 2001 From: Zuhair AlSader Date: Thu, 17 Aug 2023 17:22:13 -0400 Subject: [PATCH] Add option to exclude tags Signed-off-by: Zuhair AlSader --- README.md | 1 + action.yml | 6 ++++++ cr.sh | 14 +++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba8d0ef..1df4e51 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi - `mark_as_latest`: When you set this to `false`, it will mark the created GitHub release not as 'latest'. - `packages_with_index`: When you set this to `true`, it will upload chart packages directly into publishing branch. - `pages_branch`: Name of the branch to be used to push the index and artifacts. (default to: gh-pages but it is not set in the action it is a default value for the chart-releaser binary) +- `exclude_tags`: Tags matching this glob are excluded when looking for the latest release ### Outputs diff --git a/action.yml b/action.yml index ade9f00..18adb53 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,8 @@ inputs: required: false pages_branch: description: "Name of the branch to be used to push the index and artifacts. (default to: gh-pages but it is not set in the action it is a default value for the chart-releaser binary)" + exclude_tags: + description: "Tags matching this glob are excluded when looking for the latest release" required: false outputs: changed_charts: @@ -97,6 +99,10 @@ runs: if [[ -n "${{ inputs.pages_branch }}" ]]; then args+=(--pages-branch "${{ inputs.pages_branch }}") fi + + if [[ -n "${{ inputs.exclude_tags }}" ]]; then + args+=(--exclude-tags "${{ inputs.exclude_tags }}") + fi "$GITHUB_ACTION_PATH/cr.sh" "${args[@]}" diff --git a/cr.sh b/cr.sh index 3a6f990..2128711 100755 --- a/cr.sh +++ b/cr.sh @@ -37,6 +37,7 @@ Usage: $(basename "$0") --skip-existing Skip package upload if release exists -l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true) --packages-with-index Upload chart packages directly into publishing branch + -e, --exclude-tags Tags matching this glob are excluded when looking for the latest release EOF } @@ -53,6 +54,7 @@ main() { local mark_as_latest=true local packages_with_index=false local pages_branch= + local exclude_tags= parse_command_line "$@" @@ -210,6 +212,12 @@ parse_command_line() { shift fi ;; + -e | --exclude-tags) + if [[ -n "${2:-}" ]]; then + exclude_tags="$2" + shift + fi + ;; *) break ;; @@ -264,8 +272,12 @@ install_chart_releaser() { lookup_latest_tag() { git fetch --tags >/dev/null 2>&1 + local describe_args=(--tags --abbrev=0) + if [[ -n "$exclude_tags" ]]; then + describe_args+=(--exclude="$exclude_tags") + fi - if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then + if ! git describe "${describe_args[@]}" HEAD~ 2>/dev/null; then git rev-list --max-parents=0 --first-parent HEAD fi }