Add GitHub action to validate source code (#762)

* Add GitHub action to validate source code

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
pull/767/head
Anatolii Bazko 2021-04-09 09:55:33 +03:00 committed by GitHub
parent 31accc125a
commit 236f7ab5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 130 additions and 69 deletions

View File

@ -1,37 +0,0 @@
#
# 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
#
name: Eclipse Che operator image
on: [pull_request, push]
jobs:
build:
name: Build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Build the Docker image
run: docker build .
buildx:
name: Multi-platform build
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build images
uses: docker/build-push-action@v2
with:
file: Dockerfile
platforms: linux/amd64,linux/ppc64le
tags: quay.io/eclipse/che-operator:nightly

View File

@ -19,8 +19,9 @@ jobs:
- uses: actions/checkout@v2
- name: Install yq
run: sudo pip install yq
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Check nightly OLM bundle version
run: |
go version
export GOROOT=/opt/hostedtoolcache/go/1.15.10/x64/
${GITHUB_WORKSPACE}/.github/bin/check-nightly-olm-bundle-version.sh
run: ${GITHUB_WORKSPACE}/.github/bin/check-nightly-olm-bundle-version.sh

View File

@ -20,13 +20,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install yq
run: sudo pip install yq
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Che operator code check.
run: >-
env &&
go version &&
export GOROOT=/opt/hostedtoolcache/go/1.15.10/x64/ &&
${GITHUB_WORKSPACE}/.github/bin/check-nightly-olm-bundle.sh
run: ${GITHUB_WORKSPACE}/.github/bin/check-nightly-olm-bundle.sh

87
.github/workflows/pr-check.yml vendored Normal file
View File

@ -0,0 +1,87 @@
#
# 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
#
name: PR validation
on: pull_request
jobs:
build:
name: Image build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Build the Docker image
run: docker build .
multiplatform-build:
name: Multi-platform image build
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build images
uses: docker/build-push-action@v2
with:
file: Dockerfile
platforms: linux/amd64,linux/ppc64le
tags: quay.io/eclipse/che-operator:nightly
sources:
name: Source code validation
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Checkout source code
uses: actions/checkout@v1
- name: Cache go modules
id: cache-mod
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
if: steps.cache-mod.outputs.cache-hit != 'true'
- name: Check go mod status
run: |
go mod tidy
if [[ ! -z $(git status -s) ]]
then
echo "Go mod state is not clean:"
git --no-pager diff
exit 1
fi
- name: Check format
run: |
git reset HEAD --hard
go fmt -x ./...
if [[ ! -z $(git status -s) ]]
then
echo "not well formatted sources are found:"
git --no-pager diff
exit 1
fi
- name: Check imports
run: |
go get -u golang.org/x/tools/cmd/goimports
git reset HEAD --hard
if [[ $(find . -not -path "./vendor/*" -name '*.go' -exec goimports -l {} \;) != "" ]]
then
echo "not well formatted sources are found:"
find . -not -path "./vendor/*" -name '*.go' -exec goimports -l {} \;
exit 1
fi

View File

@ -5,9 +5,10 @@
package mock_che
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
v1 "k8s.io/api/rbac/v1"
reflect "reflect"
)
// MockPermissionChecker is a mock of PermissionChecker interface

View File

@ -5,10 +5,11 @@
package mock_che
import (
reflect "reflect"
deploy "github.com/eclipse-che/che-operator/pkg/deploy"
gomock "github.com/golang/mock/gomock"
v1 "github.com/openshift/api/config/v1"
reflect "reflect"
)
// MockOpenShiftOAuthUserHandler is a mock of OpenShiftOAuthUserHandler interface

View File

@ -5,8 +5,9 @@
package mock_util
import (
gomock "github.com/golang/mock/gomock"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
)
// MockRunnable is a mock of Runnable interface

View File

@ -1,13 +1,13 @@
//
// Copyright (c) 2012-2019 Red Hat, Inc.
// Copyright (c) 2019-2021 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: // Contributors:
// Red Hat, Inc. - initial API and implementation // Red Hat, Inc. - initial API and implementation
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package controller

View File

@ -426,13 +426,13 @@ func TestCaseAutoDetectOAuth(t *testing.T) {
func TestEnsureServerExposureStrategy(t *testing.T) {
type testCase struct {
name string
expectedCr *orgv1.CheCluster
name string
expectedCr *orgv1.CheCluster
devWorkspaceEnabled bool
initObjects []runtime.Object
initObjects []runtime.Object
}
testCases:= []testCase{
testCases := []testCase{
{
name: "Single Host should be enabled if devWorkspace is enabled",
expectedCr: &orgv1.CheCluster{

View File

@ -1,15 +1,14 @@
//
// Copyright (c) 2012-2019 Red Hat, Inc.
// Copyright (c) 2019-2021 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: // Contributors:
// Red Hat, Inc. - initial API and implementation // Red Hat, Inc. - initial API and implementation
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package controller
import (

View File

@ -9,11 +9,13 @@
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package devworkspace
import (
"context"
"errors"
"github.com/eclipse-che/che-operator/pkg/deploy"
"github.com/eclipse-che/che-operator/pkg/util"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"

View File

@ -1,3 +1,14 @@
//
// Copyright (c) 2021 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
//
package deploy
import (

View File

@ -59,4 +59,3 @@ func TestGetDeploymentPod(t *testing.T) {
}
logrus.Infof("Test passed. Pod %s found", pod)
}

View File

@ -204,13 +204,13 @@ func GetServerExposureStrategy(c *orgv1.CheCluster) string {
strategy := c.Spec.Server.ServerExposureStrategy
if strategy != "" {
return strategy
} else if c.Spec.DevWorkspace.Enable {
} else if c.Spec.DevWorkspace.Enable {
return "single-host"
} else if IsOpenShift {
} else if IsOpenShift {
return "multi-host"
} else {
} else {
return GetValue(c.Spec.K8s.IngressStrategy, "multi-host")
}
}
}
func IsTestMode() (isTesting bool) {

View File

@ -1,4 +1,3 @@
//
// Copyright (c) 2012-2019 Red Hat, Inc.
// This program and the accompanying materials are made
@ -38,7 +37,6 @@ func TestGeneratePasswd(t *testing.T) {
}
}
func TestGetValue(t *testing.T) {
key := "myvalue"
defaultValue := "myDefaultValue"