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

Add commit new nightly bundle github action. #498

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
2 changes: 1 addition & 1 deletion .github/action_scripts/build_olm_bundle_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ do
export incrementPart=$(getNightlyVersionIncrementPart "${nightlyVersion}")
echo "[INFO] Nightly increment version ${incrementPart}"

export CHECK_NIGHTLY_TAG=$(skopeo inspect docker://quay.io/eclipse/eclipse-che-kubernetes-opm-bundles:${nightlyVersion} 2>/dev/null | jq -r '.RepoTags[]|select(. == "${nightlyVersion}")')
export CHECK_NIGHTLY_TAG=$(skopeo inspect docker://${IMAGE_REGISTRY}/${IMAGE_REGISTRY_USERNAME}/eclipse-che-kubernetes-opm-bundles:${nightlyVersion} 2>/dev/null | jq -r ".RepoTags[]|select(. == \"${nightlyVersion}\")")
if [ -z "$CHECK_NIGHTLY_TAG" ]
then
buildBundleImage "${CATALOG_BUNDLE_IMAGE_NAME_LOCAL}"
Expand Down
66 changes: 0 additions & 66 deletions .github/action_scripts/operator_code_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,73 +49,7 @@ function check_che_types() {
fi
}

set -e
go version
ROOT_PROJECT_DIR="${GITHUB_WORKSPACE}"
if [ -z "${ROOT_PROJECT_DIR}" ]; then
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
ROOT_PROJECT_DIR=$(dirname "$(dirname "${BASE_DIR}")")
fi

# Unfortunately ${GOPATH} is required for an old operator-sdk
if [ -z "${GOPATH}" ]; then
export GOPATH="/home/runner/work/che-operator/go"
echo "[INFO] GOPATH: ${GOPATH}"
fi

installYq() {
YQ=$(command -v yq) || true
if [[ ! -x "${YQ}" ]]; then
pip3 install wheel
pip3 install yq
# Make python3 installed modules "visible"
export PATH=$HOME/.local/bin:$PATH
ls "${HOME}/.local/bin"
fi
echo "[INFO] $(yq --version)"
echo "[INFO] $(jq --version)"
}

installOperatorSDK() {
YQ=$(command -v operator-sdk) || true
if [[ ! -x "${YQ}" ]]; then
OPERATOR_SDK_TEMP_DIR="$(mktemp -q -d -t "OPERATOR_SDK_XXXXXX" 2>/dev/null || mktemp -q -d)"
pushd "${OPERATOR_SDK_TEMP_DIR}" || exit
echo "[INFO] Downloading 'operator-sdk' cli tool..."
curl -sLo operator-sdk "$(curl -sL https://api.github.com/repos/operator-framework/operator-sdk/releases/19175509 | jq -r '[.assets[] | select(.name == "operator-sdk-v0.10.0-x86_64-linux-gnu")] | first | .browser_download_url')"
export OPERATOR_SDK_BINARY="${OPERATOR_SDK_TEMP_DIR}/operator-sdk"
chmod +x "${OPERATOR_SDK_BINARY}"
echo "[INFO] Downloading completed!"
echo "[INFO] $(${OPERATOR_SDK_BINARY} version)"
popd || exit
fi
}

isActualNightlyOlmBundleCSVFiles() {
cd "${ROOT_PROJECT_DIR}"
export BASE_DIR="${ROOT_PROJECT_DIR}/olm"
export NO_DATE_UPDATE="true"
export NO_INCREMENT="true"
source "${ROOT_PROJECT_DIR}/olm/update-nightly-bundle.sh"

CSV_FILE_KUBERNETES="deploy/olm-catalog/eclipse-che-preview-kubernetes/manifests/che-operator.clusterserviceversion.yaml"
CSV_FILE_OPENSHIFT="deploy/olm-catalog/eclipse-che-preview-openshift/manifests/che-operator.clusterserviceversion.yaml"

IFS=$'\n' read -d '' -r -a changedFiles < <( git ls-files -m ) || true
for file in "${changedFiles[@]}"
do
if [ "${CSV_FILE_KUBERNETES}" == "${file}" ] || [ "${CSV_FILE_OPENSHIFT}" == "${file}" ]; then
echo "[ERROR] Nightly bundle file ${file} should be updated in your pr, please. Use script 'che-operator/olm/update-nightly-bundle.sh' for this purpose."
exit 1
fi
done
echo "[INFO] Nightly Olm bundle is in actual state."
}

transform_files
check_che_types
installYq
installOperatorSDK
isActualNightlyOlmBundleCSVFiles

echo "[INFO] Done."
86 changes: 86 additions & 0 deletions .github/action_scripts/provideNewNightlyBundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
#
# Copyright (c) 2012-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

set -ex

ROOT_PROJECT_DIR="${GITHUB_WORKSPACE}"
if [ -z "${ROOT_PROJECT_DIR}" ]; then
BASE_DIR=$(cd $(dirname "$0"); pwd)
ROOT_PROJECT_DIR=$(dirname "$(dirname "${BASE_DIR}")")
fi

installOperatorSDK() {
YQ=$(command -v operator-sdk) || true
if [[ ! -x "${YQ}" ]]; then
OPERATOR_SDK_TEMP_DIR="$(mktemp -q -d -t "OPERATOR_SDK_XXXXXX" 2>/dev/null || mktemp -q -d)"
pushd "${OPERATOR_SDK_TEMP_DIR}" || exit
echo "[INFO] Downloading 'operator-sdk' cli tool..."
curl -sLo operator-sdk "$(curl -sL https://api.github.com/repos/operator-framework/operator-sdk/releases/19175509 | jq -r '[.assets[] | select(.name == "operator-sdk-v0.10.0-x86_64-linux-gnu")] | first | .browser_download_url')"
export OPERATOR_SDK_BINARY="${OPERATOR_SDK_TEMP_DIR}/operator-sdk"
chmod +x "${OPERATOR_SDK_BINARY}"
echo "[INFO] Downloading completed!"
echo "[INFO] $(${OPERATOR_SDK_BINARY} version)"
popd || exit
fi
}

installYq() {
YQ=$(command -v yq) || true
if [[ ! -x "${YQ}" ]]; then
pip3 install wheel
pip3 install yq
# Make python3 installed modules "visible"
export PATH=$HOME/.local/bin:$PATH
ls "${HOME}/.local/bin"
fi
echo "[INFO] $(yq --version)"
echo "[INFO] $(jq --version)"
}

updateDate() {
NEW_CSV=${1}
createdAt=$(date -u +%FT%TZ)
echo "[INFO] - createdAt => ${createdAt}"
sed -e "s/createdAt:.*$/createdAt: \"${createdAt}\"/" "${NEW_CSV}" > "${NEW_CSV}.new"
mv "${NEW_CSV}.new" "${NEW_CSV}"
}

installYq
installOperatorSDK

# Update nightly bundles, but without time and increment to detect if we really have changes for new bundles.
export BASE_DIR="${ROOT_PROJECT_DIR}/olm"
export NO_DATE_UPDATE="true"
export NO_INCREMENT="true"
source "${ROOT_PROJECT_DIR}/olm/update-nightly-bundle.sh"

source "${ROOT_PROJECT_DIR}/olm/incrementNightlyBundles.sh"

CSV_FILE_KUBERNETES="deploy/olm-catalog/eclipse-che-preview-kubernetes/manifests/che-operator.clusterserviceversion.yaml"
CSV_FILE_OPENSHIFT="deploy/olm-catalog/eclipse-che-preview-openshift/manifests/che-operator.clusterserviceversion.yaml"

IFS=$'\n' read -d '' -r -a changedFiles < <( git ls-files -m ) || true
for file in "${changedFiles[@]}"
do
if [ "${CSV_FILE_KUBERNETES}" == "${file}" ]; then
incrementNightlyVersion 'kubernetes'
updateDate "${CSV_FILE_KUBERNETES}"
echo "[INFO] Prepared new bundle file ${CSV_FILE_KUBERNETES}"
fi

if [ "${CSV_FILE_OPENSHIFT}" == "${file}" ]; then
incrementNightlyVersion 'openshift'
updateDate "${CSV_FILE_OPENSHIFT}"
echo "[INFO] Prepared new bundle file ${CSV_FILE_OPENSHIFT}"
fi
done
echo "[INFO] Done."
9 changes: 1 addition & 8 deletions .github/workflows/checkNightlyOpmBundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
path: go/src/github.com/eclipse/${{ github.repository }}
fetch-depth: 0
- name: Che operator code check.
run: >-
export GOPATH="${GITHUB_WORKSPACE}/go" &&
echo "GOPATH: ${GOPATH}" &&
export GITHUB_WORKSPACE="${GITHUB_WORKSPACE}/go/src/github.com/eclipse/${{ github.repository }}" &&
cd ${GITHUB_WORKSPACE} &&
.github/action_scripts/operator_code_check.sh
${GITHUB_WORKSPACE}/.github/action_scripts/operator_code_check.sh
28 changes: 24 additions & 4 deletions .github/workflows/pushCatalogImages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,28 @@ jobs:

build:
name: Build
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
path: go/src/github.com/eclipse/${{ github.repository }}
fetch-depth: 0

- name: Prepare new nightly Olm bundle
run: >-
export GOPATH="${GITHUB_WORKSPACE}/go" &&
echo "GOPATH: ${GOPATH}" &&
export GITHUB_WORKSPACE="${GOPATH}/src/github.com/eclipse/${{ github.repository }}" &&
cd ${GITHUB_WORKSPACE} && "${GITHUB_WORKSPACE}/.github/action_scripts/provideNewNightlyBundle.sh"

- name: Commit new nightly Olm bundle
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about adding a custom message in the commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good idea, but I think, we can improve it in the next pr's.

uses: EndBug/add-and-commit@v5
with:
add: "*.yaml"
cwd: go/src/github.com/eclipse/${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker login
uses: azure/docker-login@v1
Expand All @@ -32,4 +50,6 @@ jobs:
password: ${{ secrets.QUAY_PASSWORD }}

- name: Build catalog source and opm bundle images
run: "${GITHUB_WORKSPACE}/.github/action_scripts/build_olm_bundle_images.sh"
run: >-
export GITHUB_WORKSPACE=${GITHUB_WORKSPACE}/go/src/github.com/eclipse/${{ github.repository }} &&
${GITHUB_WORKSPACE}/.github/action_scripts/build_olm_bundle_images.sh
48 changes: 23 additions & 25 deletions olm/incrementNightlyBundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,29 @@ ROOT_PROJECT_DIR=$(dirname "${BASE_DIR}")
source ${BASE_DIR}/check-yq.sh

incrementNightlyVersion() {
for platform in 'kubernetes' 'openshift'
do
OPM_BUNDLE_DIR="${ROOT_PROJECT_DIR}/deploy/olm-catalog/eclipse-che-preview-${platform}"
OPM_BUNDLE_MANIFESTS_DIR="${OPM_BUNDLE_DIR}/manifests"
CSV="${OPM_BUNDLE_MANIFESTS_DIR}/che-operator.clusterserviceversion.yaml"

currentNightlyVersion=$(yq -r ".spec.version" "${CSV}")
echo "[INFO] current nightly ${platform} version: ${currentNightlyVersion}"

getNightlyVersionIncrementPart "${currentNightlyVersion}"

PACKAGE_NAME="eclipse-che-preview-${platform}"
PACKAGE_FOLDER_PATH="${ROOT_PROJECT_DIR}/olm/eclipse-che-preview-${platform}/deploy/olm-catalog/${PACKAGE_NAME}"
PACKAGE_FILE_PATH="${PACKAGE_FOLDER_PATH}/${PACKAGE_NAME}.package.yaml"
CLUSTER_SERVICE_VERSION=$(yq -r ".channels[] | select(.name == \"stable\") | .currentCSV" "${PACKAGE_FILE_PATH}")
STABLE_PACKAGE_VERSION=$(echo "${CLUSTER_SERVICE_VERSION}" | sed -e "s/${PACKAGE_NAME}.v//")

parseStableVersion
STABLE_MINOR_VERSION=$((STABLE_MINOR_VERSION+1))
newVersion="${STABLE_MAJOR_VERSION}.${STABLE_MINOR_VERSION}.0-$((incrementPart+1)).nightly"

echo "[INFO] Set up nightly ${platform} version: ${newVersion}"
yq -rY "(.spec.version) = \"${newVersion}\" | (.metadata.name) = \"eclipse-che-preview-${platform}.v${newVersion}\"" "${CSV}" > "${CSV}.old"
mv "${CSV}.old" "${CSV}"
done
platform="${1}"
OPM_BUNDLE_DIR="${ROOT_PROJECT_DIR}/deploy/olm-catalog/eclipse-che-preview-${platform}"
OPM_BUNDLE_MANIFESTS_DIR="${OPM_BUNDLE_DIR}/manifests"
CSV="${OPM_BUNDLE_MANIFESTS_DIR}/che-operator.clusterserviceversion.yaml"

currentNightlyVersion=$(yq -r ".spec.version" "${CSV}")
echo "[INFO] current nightly ${platform} version: ${currentNightlyVersion}"

getNightlyVersionIncrementPart "${currentNightlyVersion}"

PACKAGE_NAME="eclipse-che-preview-${platform}"
PACKAGE_FOLDER_PATH="${ROOT_PROJECT_DIR}/olm/eclipse-che-preview-${platform}/deploy/olm-catalog/${PACKAGE_NAME}"
PACKAGE_FILE_PATH="${PACKAGE_FOLDER_PATH}/${PACKAGE_NAME}.package.yaml"
CLUSTER_SERVICE_VERSION=$(yq -r ".channels[] | select(.name == \"stable\") | .currentCSV" "${PACKAGE_FILE_PATH}")
STABLE_PACKAGE_VERSION=$(echo "${CLUSTER_SERVICE_VERSION}" | sed -e "s/${PACKAGE_NAME}.v//")

parseStableVersion
STABLE_MINOR_VERSION=$((STABLE_MINOR_VERSION+1))
newVersion="${STABLE_MAJOR_VERSION}.${STABLE_MINOR_VERSION}.0-$((incrementPart+1)).nightly"

echo "[INFO] Set up nightly ${platform} version: ${newVersion}"
yq -rY "(.spec.version) = \"${newVersion}\" | (.metadata.name) = \"eclipse-che-preview-${platform}.v${newVersion}\"" "${CSV}" > "${CSV}.old"
mv "${CSV}.old" "${CSV}"
}

getNightlyVersionIncrementPart() {
Expand Down
9 changes: 5 additions & 4 deletions olm/update-nightly-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ mv "${NEW_OPERATOR_LOCAL_YAML}" "${OPERATOR_LOCAL_YAML}"
DOCKERFILE=${BASE_DIR}/../Dockerfile
sed -i 's|registry.access.redhat.com/ubi8-minimal:.*|'${UBI8_MINIMAL_IMAGE}'|g' $DOCKERFILE

if [ -z "${NO_INCREMENT}" ]; then
source "${BASE_DIR}/incrementNightlyBundles.sh"
incrementNightlyVersion
fi
source "${BASE_DIR}/incrementNightlyBundles.sh"

for platform in 'kubernetes' 'openshift'
do
Expand Down Expand Up @@ -126,6 +123,10 @@ do
mv "${NEW_CSV}.new" "${NEW_CSV}"
fi

if [ -z "${NO_INCREMENT}" ]; then
incrementNightlyVersion "${platform}"
fi

cp -rf "${ROOT_PROJECT_DIR}/deploy/crds/org_v1_che_crd.yaml" "${bundleFolder}/manifests"
echo "Done for ${platform}"

Expand Down