Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling correctly both tag release and first release #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,27 @@ install_chart_releaser() {
lookup_latest_tag() {
git fetch --tags >/dev/null 2>&1

if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
if git symbolic-ref --short -q HEAD; then
if ! git describe --tags --abbrev=0 HEAD~ 2>/dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
fi
else
# In a detached HEAD state, such as when the pipeline
# is triggered by a push on a tag commit, we need to look back
# by date
current_commit=$(git rev-parse HEAD)
for tag in $(git tag --sort=-creatordate); do
if [ $(git rev-parse "$tag") = "$current_commit" ]; then
continue
else
echo "$tag"
break
fi
done
fi
}


filter_charts() {
while read -r chart; do
[[ ! -d "$chart" ]] && continue
Expand All @@ -269,15 +285,21 @@ filter_charts() {
lookup_changed_charts() {
local commit="$1"

local changed_files
changed_files=$(git diff --find-renames --name-only "$commit" -- "$charts_dir")
if [ -z "$commit" ]; then
# If no commit is given (i.e., no previous tag), consider all charts.
find "$charts_dir" -maxdepth 1 -type d | filter_charts
else
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 fields="1-${depth}"
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
fi
}


package_chart() {
local chart="$1"

Expand Down