Skip to content

Commit

Permalink
feat: add a "match_tags" option
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dunglas committed Apr 25, 2023
1 parent db5211e commit bdec858
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://<owner>.github.io/<project>`)
- `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

Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
Expand Down Expand Up @@ -69,5 +72,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
18 changes: 17 additions & 1 deletion cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Usage: $(basename "$0") <options>
-i, --install-only Just install the cr tool
-s, --skip-packaging Skip the packaging step (run your own packaging before using the releaser)
-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
}

Expand All @@ -47,6 +48,7 @@ main() {
local install_only=
local skip_packaging=
local mark_as_latest=true
local match_tags=

parse_command_line "$@"

Expand Down Expand Up @@ -177,6 +179,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
;;
*)
Expand Down Expand Up @@ -234,7 +244,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
}
Expand Down

0 comments on commit bdec858

Please sign in to comment.