diff --git a/.github/workflows/csi_operator_ci.yaml b/.github/workflows/csi_operator_ci.yaml new file mode 100644 index 000000000..475adc34b --- /dev/null +++ b/.github/workflows/csi_operator_ci.yaml @@ -0,0 +1,91 @@ +name: Community Operators test +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master +jobs: + operator_image_build: + name: "set env" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + outputs: + operator_image_for_test: "ibmcom/ibm-block-csi-operator:latest" + + prepare_env: + name: "prepare env" + needs: operator_image_build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup dependencies + id: setup_dependencies + run: | + build/ci/community/setup_ci_dependencies.sh + - name: Save dependencies files + uses: actions/upload-artifact@v2 + with: + name: gitconfig-file + path: | + /home/runner/.gitconfig + /home/runner/.bash_profile + retention-days: 1 + - uses: FranzDiebold/github-env-vars-action@v2 + - name: Prepare env + id: environment_setup + run: | + build/ci/community/prepare_env.sh + outputs: + image_branch_tag: "${{ steps.setup_dependencies.outputs.image_branch_tag }}" + community_operators_path: "${{ steps.environment_setup.outputs.community_operators_path }}" + upstream_community_operators_path: "${{ steps.environment_setup.outputs.upstream_community_operators_path }}" + repository_path: "${{ steps.environment_setup.outputs.repository_path }}" + operator_image_for_test: ${{ needs.operator_image_build.outputs.operator_image_for_test }} + csv_file: ${{ steps.environment_setup.outputs.csv_file }} + + CI-csi-demo-pr: + name: "community-operators fork checks" + needs: prepare_env + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + original_community_operators_repository: "k8s-operatorhub/community-operators" + original_community_operators_repository_prod: "redhat-openshift-ecosystem/community-operators-prod" + forked_community_operators_repository: "csiblock/community-operators" + forked_community_operators_repository_prod: "csiblock/community-operators-prod" + community_operators_kubernetes_branch: "ibm-block-csi-update-kubernetes-${{ github.run_number }}" + community_operators_openshift_branch: "ibm-block-csi-update-openshift-${{ github.run_number }}" + github_token: ${{ secrets.CSIBLOCK_GITHUB_TOKEN }} + repository_path: ${{ needs.prepare_env.outputs.repository_path }} + operator_image_for_test: ${{ needs.prepare_env.outputs.operator_image_for_test }} + csv_file: ${{ needs.prepare_env.outputs.csv_file }} + github_build_number: ${{ github.run_number }} + latest_operator_version: ${{ needs.prepare_env.outputs.image_branch_tag }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Retrieve gitconfig file + uses: actions/download-artifact@v2 + with: + name: gitconfig-file + path: /home/runner + - name: Create demo PR + run: | + build/ci/community/create_demo_pr.sh + - name: Wait for all demo PR checks to finish + run: | + build/ci/community/wait_demo_pr_checks.sh + - name: Assert all demo PR checks passed + run: | + build/ci/community/check_all_checks.sh + - name: Clean demo PR + if: always() + run: | + build/ci/community/clean_demo_pr.sh diff --git a/build/ci/community/check_all_checks.sh b/build/ci/community/check_all_checks.sh new file mode 100755 index 000000000..e011005d4 --- /dev/null +++ b/build/ci/community/check_all_checks.sh @@ -0,0 +1,24 @@ +#!/bin/bash -xe +set +o pipefail + +# CSI-3172 - run Red Hat bot checks + +did_all_checks_pass(){ + community_operators_branch=$1 + forked_repository=$2 + all_checks_passed=false + if [ "$(gh pr checks $community_operators_branch --repo $forked_repository | grep -iv pass | wc -l)" -eq 0 ] + then + all_checks_passed=true + fi + echo "$all_checks_passed" +} + +passed_k8s_checks=$(did_all_checks_pass $community_operators_kubernetes_branch $forked_community_operators_repository) +passed_openshift_checks=$(did_all_checks_pass $community_operators_openshift_branch $forked_community_operators_repository_prod) + +if [ $passed_k8s_checks == "false" ] || [ $passed_openshift_checks == "false" ] +then + echo "some test failed :(" + exit 1 +fi diff --git a/build/ci/community/clean_demo_pr.sh b/build/ci/community/clean_demo_pr.sh new file mode 100755 index 000000000..fae8e36f3 --- /dev/null +++ b/build/ci/community/clean_demo_pr.sh @@ -0,0 +1,17 @@ +#!/bin/bash -xe +set +o pipefail + +print_checks_and_delete_pr(){ + community_operators_branch=$1 + cluster_kind=$2 + forked_repository=$3 + repo_pr="gh pr list --repo $forked_repository | grep $community_operators_branch" + if [[ "`eval $repo_pr`" == *"$community_operators_branch"* ]]; then + echo "The $cluster_kind checks:" + gh pr checks $community_operators_branch --repo $forked_repository || true + gh pr close $community_operators_branch --delete-branch --repo $forked_repository + fi +} + +print_checks_and_delete_pr $community_operators_kubernetes_branch 'kubernetes' $forked_community_operators_repository +print_checks_and_delete_pr $community_operators_openshift_branch 'openshift' $forked_community_operators_repository_prod diff --git a/build/ci/community/create_demo_pr.sh b/build/ci/community/create_demo_pr.sh new file mode 100755 index 000000000..fafaced9d --- /dev/null +++ b/build/ci/community/create_demo_pr.sh @@ -0,0 +1,57 @@ +#!/bin/bash -xel +set +o pipefail + +edit_operator_image_in_csv_yaml (){ + cd $(dirname $csv_file) + chmod 547 $(basename $csv_file) + declare -a operator_image_fields=( + ".spec.install.spec.deployments[0].spec.template.spec.containers[0].image" + ".metadata.annotations.containerImage" + ".spec.relatedImages[0].image" + ) + for image_field in "${operator_image_fields[@]}" + do + yq eval "$image_field |= env(operator_image_for_test)" $(basename $csv_file) -i + done +cd - +} + +create_demo_pr(){ + community_operators_branch=$1 + dest_path=$2 + cluster_kind=$3 + forked_repository=$4 + cd $forked_repository-fork + repo_pr="gh pr list --repo $forked_repository | grep $community_operators_branch" + if [[ "`eval $repo_pr`" == *"$community_operators_branch"* ]]; then + gh pr close $community_operators_branch --delete-branch --repo $forked_repository + fi + git checkout main + git checkout -b $community_operators_branch + yes | cp -r $repository_path/deploy/olm-catalog/ibm-block-csi-operator-community/$latest_operator_version/ $dest_path/ibm-block-csi-operator-community + git add . + git commit --signoff -m "build number $github_build_number $cluster_kind" + git push origin $community_operators_branch + gh pr create --title "IBM Block CSI update $cluster_kind" --repo $forked_repository --base main --head $community_operators_branch --body "pr check" + cd - +} + +update_community_operators_fork (){ + forked_repository=$1 + original_repository=$2 + echo $github_token > github_token.txt + gh auth login --with-token < github_token.txt + gh repo fork $original_repository --clone $forked_repository-fork + cd $forked_repository-fork + git remote set-url origin https://csiblock:$github_token@github.com/$forked_repository.git + git fetch upstream + git rebase upstream/main + git push origin main --force + cd - +} + +edit_operator_image_in_csv_yaml +update_community_operators_fork $forked_community_operators_repository $original_community_operators_repository +update_community_operators_fork $forked_community_operators_repository_prod $original_community_operators_repository_prod +create_demo_pr $community_operators_kubernetes_branch "operators/" "kubernetes" $forked_community_operators_repository +create_demo_pr $community_operators_openshift_branch "operators/" "openshift" $forked_community_operators_repository_prod diff --git a/build/ci/community/prepare_env.sh b/build/ci/community/prepare_env.sh new file mode 100755 index 000000000..82f739cf6 --- /dev/null +++ b/build/ci/community/prepare_env.sh @@ -0,0 +1,15 @@ +#!/bin/bash -xel +set +o pipefail +operator_package_file_path=deploy/olm-catalog/ibm-block-csi-operator/ibm-block-csi-operator.package.yaml +csv_version=`yq eval .channels[0].currentCSV $operator_package_file_path` +# CSI-3171 - handle non GA versions +csv_version=`echo ${csv_version//ibm-block-csi-operator.v}` +repository_path=~/work/$CI_REPOSITORY_NAME/$CI_REPOSITORY_NAME +csv_file=$repository_path/deploy/olm-catalog/ibm-block-csi-operator-community/$csv_version/manifests/ibm-block-csi-operator.v$csv_version.clusterserviceversion.yaml +upstream_community_operators_path=upstream-community-operators/ibm-block-csi-operator-community/$csv_version +community_operators_path=community-operators/ibm-block-csi-operator-community/$csv_version + +echo "::set-output name=upstream_community_operators_path::${upstream_community_operators_path}" +echo "::set-output name=community_operators_path::${community_operators_path}" +echo "::set-output name=repository_path::${repository_path}" +echo "::set-output name=csv_file::${csv_file}" diff --git a/build/ci/community/setup_ci_dependencies.sh b/build/ci/community/setup_ci_dependencies.sh new file mode 100755 index 000000000..1359a1404 --- /dev/null +++ b/build/ci/community/setup_ci_dependencies.sh @@ -0,0 +1,17 @@ +#!/bin/bash -xe +set +o pipefail + +echo $'yq() {\n docker run --rm -e operator_image_for_test=$operator_image_for_test -i -v "${PWD}":/workdir mikefarah/yq:4 "$@"\n}' >> /home/runner/.bash_profile + +curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null +sudo apt-get update +sudo apt-get install gh + +git config --global user.email csi.block1@il.ibm.com +git config --global user.name csiblock + +image_version=`cat version/version.go | grep -i driverversion | awk -F = '{print $2}'` +image_version=`echo ${image_version//\"}` + +echo "::set-output name=image_branch_tag::${image_version}" \ No newline at end of file diff --git a/build/ci/community/wait_demo_pr_checks.sh b/build/ci/community/wait_demo_pr_checks.sh new file mode 100755 index 000000000..8c246eb01 --- /dev/null +++ b/build/ci/community/wait_demo_pr_checks.sh @@ -0,0 +1,32 @@ +#!/bin/bash -xe +set +o pipefail + +gh_pr_checks_command (){ + community_operators_branch=$1 + forked_repository=$2 + gh pr checks $community_operators_branch --repo $forked_repository +} + +wait_for_checks_to_start(){ + community_operators_branch=$1 + forked_repository=$2 + while [ `gh_pr_checks_command $community_operators_branch $forked_repository | wc -l` -eq 0 ]; do + sleep 1 + done +} +wait_for_checks_to_complete(){ + community_operators_branch=$1 + forked_repository=$2 + all_tests_passed=false + repo_pr=`gh pr list --repo $forked_repository | grep $community_operators_branch` + if [[ "$repo_pr" == *"$community_operators_branch"* ]]; then + wait_for_checks_to_start $community_operators_branch $forked_repository + test_summary="gh_pr_checks_command $community_operators_branch $forked_repository | grep -i summary" + while [[ ! "`eval $test_summary`" =~ "pass" ]] && [[ ! "`eval $test_summary`" =~ "fail" ]]; do + sleep 1 + done + fi +} + +wait_for_checks_to_complete $community_operators_kubernetes_branch $forked_community_operators_repository +wait_for_checks_to_complete $community_operators_openshift_branch $forked_community_operators_repository_prod