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

fix(scripts): address shellcheck errs #39

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
48 changes: 26 additions & 22 deletions scripts/bump-spin-formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ SED_INPLACE='sed -i.bak'
trap 'rm checksums.txt **/*.bak &>/dev/null' EXIT

usage() {
echo "Usage: $0 <VERSION> [<FORMULA_PATH>]"
echo "Updates the Spin Formula for the specified release version"
echo "Example: $0 v3.0.0"
echo "Usage: $0 <VERSION> [<FORMULA_PATH>]"
echo "Updates the Spin Formula for the specified release version"
echo "Example: $0 v3.0.0"
}

if [ $# -ne 1 ]; then
usage
exit 1
if [[ $# -ne 1 ]]
then
usage
exit 1
fi

# Ensure version is prefixed with 'v' and an 'official' release
if [[ ! "${VERSION}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "VERSION doesn't match v[0-9]+.[0-9]+.[0-9]+ and may be a prerelease; skipping."
exit 1
if [[ ! "${VERSION}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]
then
echo "VERSION doesn't match v[0-9]+.[0-9]+.[0-9]+ and may be a prerelease; skipping."
exit 1
fi

# Get the checksum file for the release
wget -qO checksums.txt "https://github.com/fermyon/spin/releases/download/$VERSION/checksums-$VERSION.txt" || \
(echo "Checksum file not found for version $VERSION" && exit 1)
wget -qO checksums.txt "https://github.com/fermyon/spin/releases/download/${VERSION}/checksums-${VERSION}.txt" ||
(echo "Checksum file not found for version ${VERSION}" && exit 1)

# Remove the 'v' prefix from the version
ERSION="${VERSION:1}"
$SED_INPLACE -e "s/version \"[^\"]*\"/version \"$ERSION\"/" $FORMULA
${SED_INPLACE} -e "s/version \"[^\"]*\"/version \"${ERSION}\"/" "${FORMULA}"
# Update the sha256 checksums for each OS/Arch
while read -r line; do
filename=$(echo "$line" | awk '{print $2}')
sha256=$(echo "$line" | awk '{print $1}')
os_arch=$(echo ${filename} | sed "s/spin-v${ERSION}-//g")
if grep -q "$os_arch" $FORMULA; then
$SED_INPLACE -E "/url \".*$os_arch\"/ { n; s/sha256 \"[^\"]*\"/sha256 \"$sha256\"/; }" $FORMULA
fi
done < checksums.txt

echo "Formula updated to version $VERSION with new checksums."
while read -r line
do
filename=$(echo "${line}" | awk '{print $2}')
sha256=$(echo "${line}" | awk '{print $1}')
os_arch="${filename//spin-v${ERSION}-/}"
if grep -q "${os_arch}" "${FORMULA}"
then
${SED_INPLACE} -E "/url \".*${os_arch}\"/ { n; s/sha256 \"[^\"]*\"/sha256 \"${sha256}\"/; }" "${FORMULA}"
fi
done <checksums.txt

echo "Formula updated to version ${VERSION} with new checksums."
Loading