Skip to content

Commit

Permalink
Merge pull request #1 from camilamacedo86/init
Browse files Browse the repository at this point in the history
init version
  • Loading branch information
camilamacedo86 authored Dec 6, 2021
2 parents c15cb5b + 60479a9 commit 9811958
Show file tree
Hide file tree
Showing 20 changed files with 2,949 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: build

on:
push:
branches:
- '**'
pull_request:
paths:
- '**'
- '!doc/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '~1.16'
- run: make build
28 changes: 28 additions & 0 deletions .github/workflows/license-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: License Test

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
branches:
- '**'
pull_request:
paths:
- '**'
- '!doc/**'

jobs:

test:
name: License Test
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
- name: Perform the test
run: make test-license
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
branches:
- '**'
pull_request:
paths:
- '**'
- '!doc/**'

jobs:

lint:
name: golangci-lint
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.37 # Always uses the latest patch version.
only-new-issues: true # Show only new issues if it's a pull request
49 changes: 49 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
defaults:
run:
shell: bash
jobs:
create:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- uses: actions/create-release@v1
id: release
env:
GITHUB_TOKEN: ${{ github.token }}
with:
draft: true
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
assets:
needs: create
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '~1.16'
- run: |
make build
chmod +x bin/k8s-community-bundle-validator
echo "asset_path=bin/k8s-community-bundle-validator" >> $GITHUB_ENV
echo "asset_name=$(go env GOOS)-$(go env GOARCH)-k8s-community-bundle-validator$(go env GOEXE)" >> $GITHUB_ENV
- run: make ${{ env.asset_path }}
- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create.outputs.upload_url }}
asset_path: ${{ env.asset_path }}
asset_name: ${{ env.asset_name }}
asset_content_type: application/octet-stream
48 changes: 48 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Unit tests

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
branches:
- '**'
pull_request:
paths:
- '**'
- '!doc/**'

jobs:

test:
name: Unit tests
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: Perform the test
run: make test
coverage:
name: Code coverage
needs:
- test
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: Generate the coverage output
run: make test-coverage
- name: Send the coverage output
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage-all.out
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.idea/
.vscode/
.DS_Store

# Editor temp files
*~
\#*#

# skip dirs
**/output
**/bin
**/tmp


# skip .out files (coverage tests)
*.out

vendor/*
79 changes: 79 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash

# Copyright 2021 The K8s Community Validator 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.

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

##@ General

.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build
GO_ASMFLAGS = -asmflags "all=-trimpath=$(shell dirname $(PWD))"
GO_GCFLAGS = -gcflags "all=-trimpath=$(shell dirname $(PWD))"
LD_FLAGS=-ldflags " \
-X main.goos=$(shell go env GOOS) \
-X main.goarch=$(shell go env GOARCH) \
-X main.gitCommit=$(shell git rev-parse HEAD) \
-X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
"
.PHONY: build
build: ## Build the project locally
go build $(GO_GCFLAGS) $(GO_ASMFLAGS) $(LD_FLAGS) -o bin/k8s-community-bundle-validator ./cmd
cp ./bin/k8s-community-bundle-validator $(GOBIN)/k8s-community-bundle-validator

.PHONY: install
install: ## Build the project locally
make build
cp ./bin/k8s-community-bundle-validator $(GOBIN)/k8s-community-bundle-validator

##@ Development

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.37.1 ;\
}

##@ Tests

.PHONY: test
test: ## Run the unit tests
go test -race -v ./pkg/...

.PHONY: test-coverage
test-coverage: ## Run unit tests creating the output to report coverage
- rm -rf *.out # Remove all coverage files if exists
go test -race -failfast -tags=integration -coverprofile=coverage-all.out -coverpkg="./pkg/..." ./pkg/...

.PHONY: test-license
test-license: ## Check if all files has the license
./hack/check-license.sh
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
# bundle-validator
k8S Community Bundle Validator
==

## Overview

It is an external validator which can be used to ensure that an OLM bundle is respecting
the specific criteria to publish in the [Kubernetes Community Operator](https://github.com/k8s-operatorhub/community-operators).

Note that a distribution must attend the common requirements defied to integrate the Operator project
with OLM and then, this validator will check the bundle which is intended to be published on [OperatorHub.io](https://operatorhub.io/)
catalogs.

The common criteria to publish are defined and implemented in the [https://github.com/operator-framework/api](https://github.com/operator-framework/api)
which is also used by this project in order to try to ensure and respect the defined standards. Users are able to test their
bundles with the common and criteria to distributed in OLM by running `operator-sdk bundle validate ./bundle --select-optional suite=operatorframework`
and using [Operator-SDK][operator-sdk].

> **The purpose of this validator is to ensure
and centralize any rule and criteria which is specific to publish in
K8s Community Operator Catalog ([OperatorHub.io](https://operatorhub.io/)).**

**NOTE** We have an [EP in WIP](https://github.com/operator-framework/enhancements/pull/98). The idea is in the future
[Operator-SDK][operator-sdk] also be able to run this validator.

## Install

Download the binary from the release page.
Following the steps to allow you do that via command line:

1. Set platform information:

```sh
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
```

2. Download the binary:

```sh
export VALIDADOR_URL=https://github.com/k8s-operatorhub/bundle-validator/releases/download/{tagVersion}
curl -LO ${VALIDADOR_URL}/${OS}-${ARCH}-amd64-k8s-community-bundle-validator
chmod +x amd64-k8s-community-bundle-validator
```

### From source-code

Run `make install` to be able to build and install the binary locally.

## Usage

You can test this validator by running:

```sh
$ k8s-community-bundle-validator <bundle-path>
```

**NOTE** You can use the option `--output=json-alpha1` to output the format in `JSON` format.

## How to check what is validated with this project?

The documentation ought to get done in this project source code in order to generate the Golang docs.

## Release

Create a new tag and publish in the repository. It will call the GitHub action release and the
artifacts will be built and publish in the release page automatically after few minutes.

[operator-sdk]: https://github.com/operator-framework/operator-sdk
Loading

0 comments on commit 9811958

Please sign in to comment.