Skip to content

Commit

Permalink
refactor(.circleci/release.sh): skip charts with a matching tag
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Grasso <[email protected]>
  • Loading branch information
leogr authored and poiana committed Jul 9, 2020
1 parent 9327e13 commit 540aa18
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions .circleci/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,31 @@ main() {
echo "Fetching tags..."
git fetch --tags

local latest_tag
latest_tag=$(find_latest_tag)
echo "Fetching charts..."

local latest_tag_rev
latest_tag_rev=$(git rev-parse --verify "$latest_tag")
echo "$latest_tag_rev $latest_tag (latest tag)"

local head_rev
head_rev=$(git rev-parse --verify HEAD)
echo "$head_rev HEAD"

if [[ "$latest_tag_rev" == "$head_rev" ]]; then
echo "No code changes. Nothing to release."
exit
fi
local changed_charts=()

# iterate over all charts and skip those that already have a tag matching the current version
for chart_config in */Chart.yaml; do
local chart_name=$(cat $chart_config | awk '/^name: /{print $NF}')
local chart_ver=$(cat $chart_config | awk '/^version: /{print $NF}')
local tag="${chart_name}-${chart_ver}"
if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Chart '$chart_name': tag '$tag' already exists, skipping."
else
echo "Chart '$chart_name': new version '$chart_ver' detected."
local changed_charts+=($chart_name)
fi
done

# preparing dirs
rm -rf .cr-release-packages
mkdir -p .cr-release-packages

rm -rf .cr-index
mkdir -p .cr-index

echo "Identifying changed charts since tag '$latest_tag'..."

local changed_charts=()
local charts_path='*/Chart.yaml' # we consider only charts dirs at level one
readarray -t changed_charts <<< "$(git diff --find-renames --name-only "$latest_tag_rev" -- $charts_path | cut -d '/' -f 1 | uniq)"

# only release those charts for which a new version has been detected
if [[ -n "${changed_charts[*]}" ]]; then
for chart in "${changed_charts[@]}"; do
echo "Packaging chart '$chart'..."
Expand All @@ -61,12 +58,6 @@ main() {
popd > /dev/null
}

find_latest_tag() {
if ! git describe --tags --abbrev=0 2> /dev/null; then
git rev-list --max-parents=0 --first-parent HEAD
fi
}

package_chart() {
local chart="$1"
helm package "$chart" --destination .cr-release-packages --dependency-update
Expand Down

0 comments on commit 540aa18

Please sign in to comment.