Skip to content

Commit

Permalink
🔨 (update-changelog): Add param to append or replace changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Apr 13, 2023
1 parent 2f004fd commit b3a638b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/renovate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
set -eux
export DESCRIPTION="$(sed 's/^:.*: //' <<<"$TITLE")"
CHANGELOG="$(yq -o json '[{"kind": "changed", "description": strenv(DESCRIPTION)}]')"
./hack/update-changelog.sh "$CHANGELOG" ${{ steps.changes.outputs.charts_files }}
./hack/update-changelog.sh replace "$CHANGELOG" ${{ steps.changes.outputs.charts_files }}
- name: Set type to patch
if: contains(steps.pr.outputs.labels, 'patch') || contains(steps.pr.outputs.labels, 'digest')
Expand Down
22 changes: 19 additions & 3 deletions hack/update-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ command -v yq >/dev/null 2>&1 || {
exit 1
}

if [ "$#" -eq 0 ]; then
echo 'Usage: changelog [chart...]'
if [ "$#" -lt 2 ]; then
echo 'Usage: {append | replace} changelog [chart...]'
exit
fi

update_type="$1"
shift

changelog="$(yq -P <<<"$1")"
export changelog
shift
Expand All @@ -31,10 +34,23 @@ else
fi
CHARTS=( $(sort -u <<<"${CHARTS[*]}") )

case "$update_type" in
append)
expression='.annotations."artifacthub.io/changes" |= (@yamld + (strenv(changelog) | @yamld) | @yaml | trim)'
;;
replace)
expression='.annotations."artifacthub.io/changes" = (env(changelog) | @yaml | trim)'
;;
*)
echo "Invalid update type: $update_type" >&2
exit 1
;;
esac

for chart in "${CHARTS[@]}"; do (
meta_file="$chart/Chart.yaml"
if [ ! -f "$meta_file" ]; then echo >&2 "Invalid file: $meta_file"; exit; fi

yq -i '.annotations."artifacthub.io/changes" = (strenv(changelog) | @yamld style="literal" | @yaml)' "$meta_file"
yq --inplace "$expression" "$meta_file"
echo "Updated $(basename "$chart") changelog"
) done

0 comments on commit b3a638b

Please sign in to comment.