Skip to content

Commit

Permalink
Add script and GH action to verify taps (#183)
Browse files Browse the repository at this point in the history
* 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 [email protected]
  • Loading branch information
dsimansk authored Feb 29, 2024
1 parent ee53467 commit 3b96814
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 10 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/knative-homebrew-test.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
10 changes: 5 additions & 5 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'fileutils'

class Func < Formula
class FuncAT17 < Formula
v = "v1.7.1"
plugin_name = "func"
path_name = "#{plugin_name}"
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'fileutils'

class Func < Formula
class FuncAT18 < Formula
v = "v1.8.2"
plugin_name = "func"
path_name = "#{plugin_name}"
Expand Down
68 changes: 68 additions & 0 deletions hack/verify-taps.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down

0 comments on commit 3b96814

Please sign in to comment.