From 26750cc1b2f8620e7a56e4b1259715e936cd38d9 Mon Sep 17 00:00:00 2001 From: Sergio Arroutbi Date: Wed, 4 Oct 2023 15:47:19 +0200 Subject: [PATCH] Include test suite execution on top of minikube (#6) Resolves: #5 Signed-off-by: Sergio Arroutbi --- .github/workflows/run_test.yaml | 44 +++++++++++ .../workflows/scripts/install_dependencies.sh | 49 ++++++++++++ .../retrieve_and_install_operator_sdk.sh | 78 +++++++++++++++++++ .gitignore | 1 + 4 files changed, 172 insertions(+) create mode 100644 .github/workflows/run_test.yaml create mode 100644 .github/workflows/scripts/install_dependencies.sh create mode 100755 .github/workflows/scripts/retrieve_and_install_operator_sdk.sh create mode 100644 .gitignore diff --git a/.github/workflows/run_test.yaml b/.github/workflows/run_test.yaml new file mode 100644 index 0000000..8b0d63a --- /dev/null +++ b/.github/workflows/run_test.yaml @@ -0,0 +1,44 @@ +--- +name: "Test Execution" + +on: + push: + branches: [main] + paths-ignore: + - '**.md' + - '.wordlist.txt' + pull_request: + paths-ignore: + - '**.md' + - '.wordlist.txt' + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@vmaster + + - name: Minikube Installation + id: minikube + uses: medyagh/setup-minikube@latest + + - name: Status + run: minikube status + + - name: Install operator-sdk + run: | + sh .github/workflows/scripts/retrieve_and_install_operator_sdk.sh \ + "v1.31.0" "5m" "${GITHUB_HEAD_REF}" + + - name: Install dependencies (kubectl, helm, clamscan, make) + run: | + sh .github/workflows/scripts/install_dependencies.sh + + - name: Run test + run: | + tree; make + + + diff --git a/.github/workflows/scripts/install_dependencies.sh b/.github/workflows/scripts/install_dependencies.sh new file mode 100644 index 0000000..18ad3b3 --- /dev/null +++ b/.github/workflows/scripts/install_dependencies.sh @@ -0,0 +1,49 @@ +#!/bin/sh -ex +# +# MIT License +# +# Copyright (c) 2023 Sergio Arroutbi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +COMMON="git file tree make" + +case "${DISTRO}" in +debian:*|ubuntu:*) + export DEBIAN_FRONTEND=noninteractive + apt clean + apt update + # We get some errors once in a while, so let's try a few times. + for i in 1 2 3; do + apt -y install ${COMMON} ${DEBIAN_UBUNTU} && break + sleep 1 + done + ;; +fedora:*|*centos:*) + echo 'max_parallel_downloads=10' >> /etc/dnf/dnf.conf + dnf -y clean all + dnf -y --setopt=deltarpm=0 update + dnf -y install ${COMMON} ${FEDORA_CENTOS} + ;; +esac + +echo "================= SYSTEM =================" +cat /etc/os-release +uname -a +echo "==========================================" diff --git a/.github/workflows/scripts/retrieve_and_install_operator_sdk.sh b/.github/workflows/scripts/retrieve_and_install_operator_sdk.sh new file mode 100755 index 0000000..3bb627f --- /dev/null +++ b/.github/workflows/scripts/retrieve_and_install_operator_sdk.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Copyright 2021. +# +# 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 -x -e + +OPERATOR_SDK_DEFAULT_RELEASE_VERSION="v1.31.0" +DEFAULT_TIMEOUT="5m" +DEFAULT_GITHUB_BRANCH="main" + +OPERATOR_SDK_RELEASE_VERSION="${1}" +TIMEOUT="${2}" +GITHUB_REF="${3}" +GITHUB_BRANCH="${3##*/}" + +test -z "${GITHUB_BRANCH}" && GITHUB_BRANCH="main" +ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n "$(uname -m)" ;; esac) +OS=$(uname | awk '{print tolower($0)}') + +dump_info() { + cat << EOF +==================$0 INFO =================== +OPERATOR_SDK_RELEASE_VERSION="${OPERATOR_SDK_RELEASE_VERSION}" +TIMEOUT="${TIMEOUT}" +GITHUB_SHA="${GITHUB_SHA}" +GITHUB_REF="${GITHUB_REF}" +GITHUB_BRANCH="${GITHUB_BRANCH}" +ARCH=${ARCH} +OS=${OS} +==================$0 INFO =================== +EOF +} + +if [ -z "${OPERATOR_SDK_RELEASE_VERSION}" ]; then + echo "INFO: operator-sdk release version is not set. Setting default version:${OPERATOR_SDK_DEFAULT_RELEASE_VERSION}" + OPERATOR_SDK_RELEASE_VERSION="${OPERATOR_SDK_DEFAULT_RELEASE_VERSION}" +fi + +OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_RELEASE_VERSION} + +if [ -z "${TIMEOUT}" ]; then + echo "INFO: using default timeout: ${DEFAULT_TIMEOUT}" + TIMEOUT="${DEFAULT_TIMEOUT}" +fi + +if [ -z "${BUNDLE_IMG}" ]; then + echo "INFO: using default bundle image: ${DEFAULT_BUNDLE_IMG}" + BUNDLE_IMG="${DEFAULT_BUNDLE_IMG}" +fi + +if [ -z "${GITHUB_BRANCH}" ]; then + echo "INFO: using default github branch: ${DEFAULT_GITHUB_BRANCH}" + GITHUB_BRANCH=${DEFAULT_GITHUB_BRANCH} +fi + +dump_info + +curl -L -o "operator-sdk_${OS}_${ARCH}" -L "${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}" +gpg --keyserver keyserver.ubuntu.com --recv-keys 052996E2A20B5C7E +curl -LO "${OPERATOR_SDK_DL_URL}"/checksums.txt +curl -LO "${OPERATOR_SDK_DL_URL}"/checksums.txt.asc +gpg -u "Operator SDK (release) " --verify checksums.txt.asc +grep "operator-sdk_${OS}_${ARCH}" checksums.txt | sha256sum -c - + +mv "operator-sdk_${OS}_${ARCH}" "$(pwd)/operator-sdk" +chmod +x "$(pwd)/operator-sdk" +"$(pwd)"/operator-sdk olm install --timeout "${TIMEOUT}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~