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

ci(*): add workflow to create Spin bump PR on release event; a few script updates #34

Merged
merged 1 commit into from
Apr 4, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/bump-spin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Bump Spin

on:
repository_dispatch:
types:
- spin-release

jobs:
create-pr:
name: Create PR with Spin Formula bumped
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Bump Spin Formula
shell: bash
run: ./scripts/bump-spin-formula.sh ${{ github.event.client_payload.version }}

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: "chore(spin.rb): bump Spin to ${{ github.event.client_payload.version }}"
title: "chore(spin.rb): bump Spin to ${{ github.event.client_payload.version }}"
body: Update the Spin formula with ${{ github.event.client_payload.version }}
branch: bump-spin-${{ github.event.client_payload.version }}
base: main
delete-branch: true
committer: fermybot <[email protected]>
author: fermybot <[email protected]>
signoff: true
33 changes: 17 additions & 16 deletions scripts/bump-spin-formula.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash
set -euo pipefail

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

# -i syntax differs between GNU and Mac sed; this usage is supported by both
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this universal option. Thank you!

SED_INPLACE='sed -i.bak'

# cleanup
trap 'rm checksums.txt **/*.bak &>/dev/null' EXIT

usage() {
echo "Usage: $0 <VERSION> [<FORMULA_PATH>]"
Expand All @@ -14,33 +21,27 @@ if [ $# -ne 1 ]; then
exit 1
fi

# Ensure the version is prefixed with 'v'
if [[ $VERSION != v* ]]; then
VERSION="v$VERSION"
# 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
fi

# Get the checksum file for the release
wget -qO checksums.txt "https://github.com/fermyon/spin/releases/download/$VERSION/checksums-$VERSION.txt"

# Check if failed to download the checksum file
if [ $? -ne 0 ]; then
echo "Checksum file not found for version $VERSION"
exit 1
fi
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 -i '' -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="${filename:12}"
os_arch=$(echo ${filename} | sed "s/spin-v${ERSION}-//g")
if grep -q "$os_arch" $FORMULA; then
sed -i '' -E "/url \".*$os_arch\"/ { n; s/sha256 \"[^\"]*\"/sha256 \"$sha256\"/; }" $FORMULA
$SED_INPLACE -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