From 3ba627bb41ccde4c6a3f31e7dc0c4e868b11257f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 12 Jul 2021 16:24:19 +0200 Subject: [PATCH] feat: add a "match_tags" option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I use this action to release the chart of [Mercure](https://mercure.rocks). We use a monolithic Git repository containing several projects, including the Helm chart. Currently, this action isn't compatible with our setup because it computes the changes made to the chart since the previous tag. In our case we also use tags for other projects in the same repository, so this actions is never triggered because there are no changes with the "previous" tag (which usually is for another project in the same repository). This PR introduces a `match_tags` option allowing to filter the tags to match using a glob. Signed-off-by: Kévin Dunglas --- README.md | 1 + action.yml | 11 +++++++++++ cr.sh | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 316890f..38aa5d6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `config`: Optional config file for chart-releaser - `charts_dir`: The charts directory - `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://.github.io/`) +- `match_tags`: The glob to use to filter Git tags, usually used with the `CR_RELEASE_NAME_TEMPLATE` environment variable (default: all tags) ### Example Workflow diff --git a/action.yml b/action.yml index 5f74729..8ef9f09 100644 --- a/action.yml +++ b/action.yml @@ -7,13 +7,20 @@ branding: inputs: version: description: "The chart-releaser version to use (default: v1.2.1)" + required: false config: description: "The relative path to the chart-releaser config file" + required: false charts_dir: description: The charts directory default: charts + required: false charts_repo_url: description: "The GitHub Pages URL to the charts repo (default: https://.github.io/)" + required: false + match_tags: + description: "The glob to use to filter Git tags (default: all tags)" + required: false runs: using: composite steps: @@ -36,5 +43,9 @@ runs: args+=(--charts-repo-url "${{ inputs.charts_repo_url }}") 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 2ad0d75..7b9a816 100755 --- a/cr.sh +++ b/cr.sh @@ -31,6 +31,7 @@ Usage: $(basename "$0") -u, --charts-repo-url The GitHub Pages URL to the charts repo (default: https://.github.io/) -o, --owner The repo owner -r, --repo The repo name + -m, --match-tags The glob to use to filter Git tags (default: all tags) EOF } @@ -41,6 +42,7 @@ main() { local owner= local repo= local charts_repo_url= + local match_tags= parse_command_line "$@" @@ -151,6 +153,16 @@ parse_command_line() { exit 1 fi ;; + -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 + ;; *) break ;; @@ -202,7 +214,12 @@ install_chart_releaser() { lookup_latest_tag() { git fetch --tags > /dev/null 2>&1 - if ! git describe --tags --abbrev=0 2> /dev/null; then + args=("describe" "--tags" "--abbrev=0") + if [ -n "$match_tags" ]; then + args+=(--match="$match_tags") + fi + + if ! git "${args[@]}" 2> /dev/null; then git rev-list --max-parents=0 --first-parent HEAD fi }