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

Add script to easily update Spin formula for new releases #31

Merged
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ a pull request.
```sh
brew test-bot --only-tap-syntax
```

### Updating the Spin Formula for a New Release

Run the [`bump-spin-formula.sh`](scripts/bump-spin-formula.sh) to update the
formula to use the assets of a specific release (say `v2.4.0`):

```sh
./scripts/bump-spin-formula.sh v2.4.0
```

The script will update the version in the formula, get the checksums file from
the specified release, and update the checksum for each architecture and OS.
46 changes: 46 additions & 0 deletions scripts/bump-spin-formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

VERSION=$1
FORMULA=${2:-Formula/Spin.rb}

usage() {
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
fi

# Ensure the version is prefixed with 'v'
if [[ $VERSION != v* ]]; then
VERSION="v$VERSION"
fi

# Get the checksum file for the release
wget -qO checksums.txt "https://github.com/fermyon/spin/releases/download/$VERSION/checksums-$VERSION.txt"
kate-goldenring marked this conversation as resolved.
Show resolved Hide resolved

# Check if failed to download the checksum file
if [ $? -ne 0 ]; then
echo "Checksum file not found for version $VERSION"
exit 1
fi

# Remove the 'v' prefix from the version
ERSION="${VERSION:1}"
kate-goldenring marked this conversation as resolved.
Show resolved Hide resolved
sed -i '' -e "s/version \"[^\"]*\"/version \"$ERSION\"/" $FORMULA
kate-goldenring marked this conversation as resolved.
Show resolved Hide resolved
# 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="${filename:12}"
if grep -q "$os_arch" $FORMULA; then
sed -i '' -E "/url \".*$os_arch\"/ { n; s/sha256 \"[^\"]*\"/sha256 \"$sha256\"/; }" $FORMULA
fi
done < checksums.txt

rm checksums.txt

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