rancher-charts/scripts/release-asset

63 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
cd $(dirname $0)
cd ..
mkdir -p released
if ! [[ -d assets ]] || ! [[ -d charts ]]; then
echo "No assets to move to released/"
exit 0
fi
# Ensure that all provided assets exist
for asset in $@; do
# Find the resrouce even if it's not prefixed with assets/
asset=${asset#'assets/'}
if ! [ -f "assets/${asset}" ]; then
echo "Failed to find assets/${asset}"
exit 1
fi
done
# Create to-be-released directory with same structure as assets
find assets -type d | sed 's/assets\//to-be-released\//' | xargs mkdir -p
# Copy assets inside
for asset in $@; do
asset=${asset#'assets/'}
mv "assets/${asset}" "to-be-released/${asset}"
done
# Remove charts
for chart in $(find charts -type d -mindepth 3 -maxdepth 3); do
# Replace final / with -
asset=$(echo ${chart} | rev | sed 's/\//-/' | rev).tgz
# Remove charts/ prefix
asset=${asset#'charts/'}
for deleted_asset in $@; do
deleted_asset=${deleted_asset#'assets/'}
[ "${deleted_asset}" == "${asset}" ] && rm -rf ${chart}
done
done
# Update released/assets/index.yaml
helm repo index --merge ./released/assets/index.yaml --url released/assets to-be-released
cp to-be-released/index.yaml ./released/assets/index.yaml
# Update index.yaml
helm repo index --merge ./index.yaml --url released/assets to-be-released
cp to-be-released/index.yaml ./index.yaml
# Copy assets into released-assets
for asset in $@; do
asset=${asset#'assets/'}
mkdir -p $(dirname "released/assets/${asset}")
mv "to-be-released/${asset}" "released/assets/${asset}"
done
rm -rf to-be-released
find assets -type d -empty -delete
find charts -type d -empty -delete