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:
@@ -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.
|
- `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'.
|
- `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
|
### Environment variables
|
||||||
|
|
||||||
- `CR_TOKEN` (required): The GitHub token of this repository (`${{ secrets.GITHUB_TOKEN }}`)
|
- `CR_TOKEN` (required): The GitHub token of this repository (`${{ secrets.GITHUB_TOKEN }}`)
|
||||||
|
|||||||
+17
-1
@@ -32,11 +32,19 @@ inputs:
|
|||||||
description: Mark the created GitHub release as 'latest'
|
description: Mark the created GitHub release as 'latest'
|
||||||
required: false
|
required: false
|
||||||
default: true
|
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:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- run: |
|
- id: release
|
||||||
|
run: |
|
||||||
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
|
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
|
||||||
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
|
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
|
||||||
|
|
||||||
@@ -77,4 +85,12 @@ runs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
|
"$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
|
shell: bash
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ set -o pipefail
|
|||||||
DEFAULT_CHART_RELEASER_VERSION=v1.6.0
|
DEFAULT_CHART_RELEASER_VERSION=v1.6.0
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat << EOF
|
cat <<EOF
|
||||||
Usage: $(basename "$0") <options>
|
Usage: $(basename "$0") <options>
|
||||||
|
|
||||||
-h, --help Display help
|
-h, --help Display help
|
||||||
@@ -56,16 +56,16 @@ main() {
|
|||||||
|
|
||||||
local repo_root
|
local repo_root
|
||||||
repo_root=$(git rev-parse --show-toplevel)
|
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...'
|
echo 'Looking up latest tag...'
|
||||||
local latest_tag
|
local latest_tag
|
||||||
latest_tag=$(lookup_latest_tag)
|
latest_tag=$(lookup_latest_tag)
|
||||||
|
|
||||||
echo "Discovering changed charts since '$latest_tag'..."
|
echo "Discovering changed charts since '$latest_tag'..."
|
||||||
local changed_charts=()
|
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
|
if [[ -n "${changed_charts[*]}" ]]; then
|
||||||
install_chart_releaser
|
install_chart_releaser
|
||||||
@@ -80,14 +80,19 @@ main() {
|
|||||||
if [[ -d "$chart" ]]; then
|
if [[ -d "$chart" ]]; then
|
||||||
package_chart "$chart"
|
package_chart "$chart"
|
||||||
else
|
else
|
||||||
echo "Chart '$chart' no longer exists in repo. Skipping it..."
|
echo "Nothing to do. No chart changes detected."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
release_charts
|
release_charts
|
||||||
update_index
|
update_index
|
||||||
|
echo "changed_charts=$(
|
||||||
|
IFS=,
|
||||||
|
echo "${changed_charts[*]}"
|
||||||
|
)" >changed_charts.txt
|
||||||
else
|
else
|
||||||
echo "Nothing to do. No chart changes detected."
|
echo "Nothing to do. No chart changes detected."
|
||||||
|
echo "changed_charts=" >changed_charts.txt
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
install_chart_releaser
|
install_chart_releaser
|
||||||
@@ -97,13 +102,15 @@ main() {
|
|||||||
update_index
|
update_index
|
||||||
fi
|
fi
|
||||||
|
|
||||||
popd > /dev/null
|
echo "chart_version=${latest_tag}" >chart_version.txt
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_command_line() {
|
parse_command_line() {
|
||||||
while :; do
|
while :; do
|
||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
-h|--help)
|
-h | --help)
|
||||||
show_help
|
show_help
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
@@ -117,7 +124,7 @@ parse_command_line() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-v|--version)
|
-v | --version)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
version="$2"
|
version="$2"
|
||||||
shift
|
shift
|
||||||
@@ -127,7 +134,7 @@ parse_command_line() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-d|--charts-dir)
|
-d | --charts-dir)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
charts_dir="$2"
|
charts_dir="$2"
|
||||||
shift
|
shift
|
||||||
@@ -137,7 +144,7 @@ parse_command_line() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-o|--owner)
|
-o | --owner)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
owner="$2"
|
owner="$2"
|
||||||
shift
|
shift
|
||||||
@@ -147,7 +154,7 @@ parse_command_line() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-r|--repo)
|
-r | --repo)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
repo="$2"
|
repo="$2"
|
||||||
shift
|
shift
|
||||||
@@ -157,19 +164,19 @@ parse_command_line() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-n|--install-dir)
|
-n | --install-dir)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
install_dir="$2"
|
install_dir="$2"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-i|--install-only)
|
-i | --install-only)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
install_only="$2"
|
install_only="$2"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-s|--skip-packaging)
|
-s | --skip-packaging)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
skip_packaging="$2"
|
skip_packaging="$2"
|
||||||
shift
|
shift
|
||||||
@@ -181,7 +188,7 @@ parse_command_line() {
|
|||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-l|--mark-as-latest)
|
-l | --mark-as-latest)
|
||||||
if [[ -n "${2:-}" ]]; then
|
if [[ -n "${2:-}" ]]; then
|
||||||
mark_as_latest="$2"
|
mark_as_latest="$2"
|
||||||
shift
|
shift
|
||||||
@@ -240,9 +247,9 @@ install_chart_releaser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lookup_latest_tag() {
|
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
|
git rev-list --max-parents=0 --first-parent HEAD
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -265,10 +272,10 @@ lookup_changed_charts() {
|
|||||||
local changed_files
|
local changed_files
|
||||||
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
|
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}"
|
local fields="1-${depth}"
|
||||||
|
|
||||||
cut -d '/' -f "$fields" <<< "$changed_files" | uniq | filter_charts
|
cut -d '/' -f "$fields" <<<"$changed_files" | uniq | filter_charts
|
||||||
}
|
}
|
||||||
|
|
||||||
package_chart() {
|
package_chart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user