diff --git a/README.md b/README.md index e689410..2d2cb0e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi - `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://.github.io/`) - `skip_packaging`: This option, when populated, will skip the packaging step. This allows you to do more advanced packaging of your charts (for example, with the `helm package` command) before this action runs. This action will only handle the indexing and publishing steps. - `mark_as_latest`: When you set this to `false`, it will mark the created GitHub release not as 'latest'. +- `match_tags`: The glob to use to filter Git tags, usually used with the `CR_RELEASE_NAME_TEMPLATE` environment variable (default: all tags) ### Environment variables diff --git a/action.yml b/action.yml index 4b8b4dc..a1e8436 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,9 @@ inputs: description: Mark the created GitHub release as 'latest' required: false default: true + match_tags: + description: "The glob to use to filter Git tags (default: all tags)" + required: false runs: using: composite @@ -76,5 +79,9 @@ runs: args+=(--mark-as-latest "${{ inputs.mark_as_latest }}") fi + if [[ -n "${{ inputs.match_tags }}" ]]; then + args+=(--match-tags "${{ inputs.match_tags }}") + fi + "$GITHUB_ACTION_PATH/cr.sh" "${args[@]}" shell: bash diff --git a/cr.sh b/cr.sh index 14ef919..2f0f91c 100755 --- a/cr.sh +++ b/cr.sh @@ -35,6 +35,7 @@ Usage: $(basename "$0") -s, --skip-packaging Skip the packaging step (run your own packaging before using the releaser) --skip-existing Skip package upload if release exists -l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true) + -m, --match-tags The glob to use to filter Git tags (default: all tags) EOF } @@ -49,6 +50,7 @@ main() { local skip_packaging= local skip_existing= local mark_as_latest=true + local match_tags= parse_command_line "$@" @@ -185,6 +187,14 @@ parse_command_line() { if [[ -n "${2:-}" ]]; then mark_as_latest="$2" shift + -m|--match-tags) + if [[ -n "${2:-}" ]]; then + match_tags="$2" + shift + else + echo "ERROR: '--match-tags' cannot be empty." >&2 + show_help + exit 1 fi ;; *) @@ -242,7 +252,13 @@ install_chart_releaser() { lookup_latest_tag() { git fetch --tags > /dev/null 2>&1 - if ! git describe --tags --abbrev=0 HEAD~ 2> /dev/null; then + args=("describe" "--tags" "--abbrev=0") + if [ -n "$match_tags" ]; then + args+=(--match="$match_tags") + fi + args+=(HEAD~) + + if ! git "${args[@]}" 2> /dev/null; then git rev-list --max-parents=0 --first-parent HEAD fi }