From 3b9681427c0bae1eebe6ee86c700f37608c477e5 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 29 Feb 2024 16:16:48 +0100 Subject: [PATCH] Add script and GH action to verify taps (#183) * Add script and GH action to verify taps * Add checkout action * Setup Homebrew from action * Fix older taps * Refactor gh action namning * Fix checksums in func@1.7.rb --- .github/workflows/knative-homebrew-test.yaml | 32 +++++++++ func@0.25.rb | 2 +- func@0.26.rb | 2 +- func@1.7.rb | 10 +-- func@1.8.rb | 2 +- hack/verify-taps.sh | 68 ++++++++++++++++++++ quickstart@1.7.rb | 2 +- source-kafka@1.7.rb | 2 +- 8 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/knative-homebrew-test.yaml create mode 100755 hack/verify-taps.sh diff --git a/.github/workflows/knative-homebrew-test.yaml b/.github/workflows/knative-homebrew-test.yaml new file mode 100644 index 0000000..9a23cfe --- /dev/null +++ b/.github/workflows/knative-homebrew-test.yaml @@ -0,0 +1,32 @@ +name: Homebrew Tests + +on: + push: + branches: [ 'main' ] + + pull_request: + branches: [ 'main' ] + +jobs: + test: + name: Verify Install + strategy: + matrix: + os: [ "ubuntu-latest", "macos-latest" ] + runs-on: ${{ matrix.os }} + steps: + - name: Git checkout + uses: actions/checkout@v4 + - name: Set up Homebrew + id: set-up-homebrew + uses: Homebrew/actions/setup-homebrew@master + - name: Install Bash 4 on MacOS + if: matrix.os == 'macos-latest' + run: | + brew install bash + + echo "/usr/local/bin" >> $GITHUB_PATH + echo "$(brew --prefix)/opt/gnu-sed/libexec/gnubin" >> $GITHUB_PATH + - name: Execute tests + run: | + ./hack/verify-taps.sh diff --git a/func@0.25.rb b/func@0.25.rb index b4751dd..8ad2932 100644 --- a/func@0.25.rb +++ b/func@0.25.rb @@ -1,6 +1,6 @@ require 'fileutils' -class Func < Formula +class FuncAT025 < Formula v = "v0.25.1" plugin_name = "func" path_name = "kn-plugin-#{plugin_name}" diff --git a/func@0.26.rb b/func@0.26.rb index b4751dd..c3f1053 100644 --- a/func@0.26.rb +++ b/func@0.26.rb @@ -1,6 +1,6 @@ require 'fileutils' -class Func < Formula +class FuncAT026 < Formula v = "v0.25.1" plugin_name = "func" path_name = "kn-plugin-#{plugin_name}" diff --git a/func@1.7.rb b/func@1.7.rb index fee9733..f83058f 100644 --- a/func@1.7.rb +++ b/func@1.7.rb @@ -1,6 +1,6 @@ require 'fileutils' -class Func < Formula +class FuncAT17 < Formula v = "v1.7.1" plugin_name = "func" path_name = "#{plugin_name}" @@ -14,20 +14,20 @@ class Func < Formula if OS.mac? if `uname -m`.chomp == "arm64" url "#{base_url}/#{file_name}_darwin_arm64" - sha256 "d2ab0de9c3b058e1a27b0cb2cb8a2a630b6526d2e8de9571c9894813faabf69d" + sha256 "cffe2b6ed5845651ac62dc8fc72c435e3042bb9b1cd2a94e1d4ef65c59841d8e" else url "#{base_url}/#{file_name}_darwin_amd64" - sha256 "80d0f6350c5d222259c22531fadddcca86339581efe455149b970648f5a2dd40" + sha256 "542b134cba4835fb452546829a84a1c8a3b44ee778c57585bf6d3c19c8ff00d0" end end if OS.linux? if `uname -m`.chomp == "arm64" url "#{base_url}/#{file_name}_linux_arm64" - sha256 "de357c92d62c4640da1c7750bbc70338c699a89f3ff4eab48c20a8e62aca1413" + sha256 "a49048728473f5399b9fbd4ff9de33c7ba92427da6037363c4d6fb393e539d91" else url "#{base_url}/#{file_name}_linux_amd64" - sha256 "1b0f2f9a357cb930a4c256620018b25adb634547a8fb315ddc303f150d4cf7f3" + sha256 "c6981cba72ad9265e1290fcdd819ff4017595925554a881bcb53fb8a5ef55eb9" end end diff --git a/func@1.8.rb b/func@1.8.rb index 9397182..f829dff 100644 --- a/func@1.8.rb +++ b/func@1.8.rb @@ -1,6 +1,6 @@ require 'fileutils' -class Func < Formula +class FuncAT18 < Formula v = "v1.8.2" plugin_name = "func" path_name = "#{plugin_name}" diff --git a/hack/verify-taps.sh b/hack/verify-taps.sh new file mode 100755 index 0000000..c646710 --- /dev/null +++ b/hack/verify-taps.sh @@ -0,0 +1,68 @@ +#! /usr/bin/env bash + +# Copyright 2024 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +set -o errexit +set -o nounset +set -o pipefail + +[[ ! -v REPO_ROOT_DIR ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" +readonly REPO_ROOT_DIR + +# List all *.rb files and try to install them as local Homebrew Tap formula +function verify_install() { + + pushd "${REPO_ROOT_DIR}" + local failed=() + + for filename in *.rb; do + local name + name=$(echo "${filename}" | cut -d '.' -f1 | cut -d '@' -f1) + + echo "Installing from: ${filename}" + echo "Plugin name: ${name}" + + brew install -v --formula ./"${filename}" --force || echo "Failed: ${filename}" + + if ! command -v kn-${name} >/dev/null; then + echo "Plugin $name not found. Installation probably failed." + failed+=("${filename}") + else + echo "Successfully verified: ${name}" + fi + + # Remove to not clash with other version, continue + brew remove -v --formula "${filename}" --force || echo "Failed uninstall: ${filename}" + done + + if (( ${#failed[@]} > 0 )); then + echo "#####" + echo "Test failed!" + echo "Files: ${failed[*]}" + echo "#####" + exit 1 + fi + + popd + echo "Test success!" +} + +# Adding main for convenience. It might be useful if we have more tests. +function main() { + verify_install +} + +main "$@" diff --git a/quickstart@1.7.rb b/quickstart@1.7.rb index ac58d9c..e7b5d37 100644 --- a/quickstart@1.7.rb +++ b/quickstart@1.7.rb @@ -1,6 +1,6 @@ require 'fileutils' -class QuickstartAT < Formula +class QuickstartAT17 < Formula v = "v1.7.0" plugin_name = "quickstart" path_name = "kn-plugin-#{plugin_name}" diff --git a/source-kafka@1.7.rb b/source-kafka@1.7.rb index f80ae01..0cdde2d 100644 --- a/source-kafka@1.7.rb +++ b/source-kafka@1.7.rb @@ -1,6 +1,6 @@ require 'fileutils' -class SourceKafkaAT < Formula +class SourceKafkaAT17 < Formula v = "v1.7.0" plugin_name = "source-kafka" path_name = "kn-plugin-#{plugin_name}"