Add changed_charts and chart_version outputs (#130)

* Add `changed_charts` and `chart_version` outputs

This should let downstream steps make conditional decisions
based on what we found.

Also: fix a confusing double-negative test in main().

Signed-off-by: Nathan J. Mehl <n@oden.io>

---------

Signed-off-by: Nathan J. Mehl <n@oden.io>
This commit is contained in:
Nathan J Mehl
2023-07-11 14:12:27 +02:00
committed by GitHub
parent 4b85f2c82c
commit 2504907988
3 changed files with 244 additions and 216 deletions
+5
View File
@@ -21,6 +21,11 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi
- `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'.
### Outputs
- `changed_charts`: A comma-separated list of charts that were released on this run. Will be an empty string if no updates were detected, will be unset if `--skip_packaging` is used: in the latter case your custom packaging step is responsible for setting its own outputs if you need them.
- `chart_version`: The version of the most recently generated charts; will be set even if no charts have been updated since the last run.
### Environment variables
- `CR_TOKEN` (required): The GitHub token of this repository (`${{ secrets.GITHUB_TOKEN }}`)
+17 -1
View File
@@ -32,11 +32,19 @@ inputs:
description: Mark the created GitHub release as 'latest'
required: false
default: true
outputs:
changed_charts:
description: "A comma-separated list of charts that were released on this run. Will be an empty string if no updates were detected, will be unset if `--skip_packaging` is used: in the latter case your custom packaging step is responsible for setting its own outputs if you need them."
value: ${{ steps.release.outputs.changed_charts }}
chart_version:
description: "The version of the most recently generated charts; will be set even if no charts have been updated since the last run."
value: ${{ steps.release.outputs.chart_version }}
runs:
using: composite
steps:
- run: |
- id: release
run: |
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
@@ -77,4 +85,12 @@ runs:
fi
"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
if [[ -f changed_charts.txt ]]; then
cat changed_charts.txt >> "$GITHUB_OUTPUT"
fi
if [[ -f chart_version.txt ]]; then
cat chart_version.txt >> "$GITHUB_OUTPUT"
fi
rm -f changed_charts.txt chart_version.txt
shell: bash
+26 -19
View File
@@ -21,7 +21,7 @@ set -o pipefail
DEFAULT_CHART_RELEASER_VERSION=v1.6.0
show_help() {
cat << EOF
cat <<EOF
Usage: $(basename "$0") <options>
-h, --help Display help
@@ -56,16 +56,16 @@ main() {
local repo_root
repo_root=$(git rev-parse --show-toplevel)
pushd "$repo_root" > /dev/null
pushd "$repo_root" >/dev/null
if ! [[ -n "$skip_packaging" ]]; then
if [[ -z "$skip_packaging" ]]; then
echo 'Looking up latest tag...'
local latest_tag
latest_tag=$(lookup_latest_tag)
echo "Discovering changed charts since '$latest_tag'..."
local changed_charts=()
readarray -t changed_charts <<< "$(lookup_changed_charts "$latest_tag")"
readarray -t changed_charts <<<"$(lookup_changed_charts "$latest_tag")"
if [[ -n "${changed_charts[*]}" ]]; then
install_chart_releaser
@@ -80,14 +80,19 @@ main() {
if [[ -d "$chart" ]]; then
package_chart "$chart"
else
echo "Chart '$chart' no longer exists in repo. Skipping it..."
echo "Nothing to do. No chart changes detected."
fi
done
release_charts
update_index
echo "changed_charts=$(
IFS=,
echo "${changed_charts[*]}"
)" >changed_charts.txt
else
echo "Nothing to do. No chart changes detected."
echo "changed_charts=" >changed_charts.txt
fi
else
install_chart_releaser
@@ -97,13 +102,15 @@ main() {
update_index
fi
popd > /dev/null
echo "chart_version=${latest_tag}" >chart_version.txt
popd >/dev/null
}
parse_command_line() {
while :; do
case "${1:-}" in
-h|--help)
-h | --help)
show_help
exit
;;
@@ -117,7 +124,7 @@ parse_command_line() {
exit 1
fi
;;
-v|--version)
-v | --version)
if [[ -n "${2:-}" ]]; then
version="$2"
shift
@@ -127,7 +134,7 @@ parse_command_line() {
exit 1
fi
;;
-d|--charts-dir)
-d | --charts-dir)
if [[ -n "${2:-}" ]]; then
charts_dir="$2"
shift
@@ -137,7 +144,7 @@ parse_command_line() {
exit 1
fi
;;
-o|--owner)
-o | --owner)
if [[ -n "${2:-}" ]]; then
owner="$2"
shift
@@ -147,7 +154,7 @@ parse_command_line() {
exit 1
fi
;;
-r|--repo)
-r | --repo)
if [[ -n "${2:-}" ]]; then
repo="$2"
shift
@@ -157,19 +164,19 @@ parse_command_line() {
exit 1
fi
;;
-n|--install-dir)
-n | --install-dir)
if [[ -n "${2:-}" ]]; then
install_dir="$2"
shift
fi
;;
-i|--install-only)
-i | --install-only)
if [[ -n "${2:-}" ]]; then
install_only="$2"
shift
fi
;;
-s|--skip-packaging)
-s | --skip-packaging)
if [[ -n "${2:-}" ]]; then
skip_packaging="$2"
shift
@@ -181,7 +188,7 @@ parse_command_line() {
shift
fi
;;
-l|--mark-as-latest)
-l | --mark-as-latest)
if [[ -n "${2:-}" ]]; then
mark_as_latest="$2"
shift
@@ -240,9 +247,9 @@ install_chart_releaser() {
}
lookup_latest_tag() {
git fetch --tags > /dev/null 2>&1
git fetch --tags >/dev/null 2>&1
if ! git describe --tags --abbrev=0 HEAD~ 2> /dev/null; then
if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
fi
}
@@ -265,10 +272,10 @@ lookup_changed_charts() {
local changed_files
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
local depth=$(( $(tr "/" "\n" <<< "$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1 ))
local depth=$(($(tr "/" "\n" <<<"$charts_dir" | sed '/^\(\.\)*$/d' | wc -l) + 1))
local fields="1-${depth}"
cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts
cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts
}
package_chart() {