Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.
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
5 changes: 5 additions & 0 deletions .ci/setup_env_opensuse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ chronic sudo -E zypper -n install libudev-devel
echo "Install Build Tools"
chronic sudo -E zypper -n install patterns-devel-base-devel_basis python pkg-config zlib-devel

echo "Install YAML validator"
chronic sudo -E zypper -n install python-setuptools
chronic sudo -E easy_install pip
chronic sudo -E pip install yamllint

echo "Install tools for metrics tests"
chronic sudo -E zypper -n install smemstat jq

Expand Down
5 changes: 5 additions & 0 deletions .ci/setup_env_sles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ chronic sudo -E zypper -n install libudev-devel
echo "Install Build Tools"
chronic sudo -E zypper -n install -t pattern "Basis-Devel" && sudo -E zypper -n install python zlib-devel

echo "Install YAML validator"
chronic sudo -E zypper -n install python-setuptools
chronic sudo -E easy_install pip
chronic sudo -E pip install yamllint

echo "Install tools for metrics tests"
chronic sudo -E zypper -n install jq

Expand Down
48 changes: 39 additions & 9 deletions .ci/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ set -e
cidir=$(dirname "$0")
source "${cidir}/lib.sh"

export tests_repo="${tests_repo:-github.com/kata-containers/tests}"
export tests_repo_dir="${GOPATH}/src/${tests_repo}"

script_name=${0##*/}

repo=""
Expand All @@ -31,6 +34,7 @@ long_options=(
[force]="Force a skipped test to run"
[golang]="Check '.go' files"
[help]="Display usage statement"
[labels]="Check labels databases"
[licenses]="Check licenses"
[branch]="Specify upstream branch to compare against (default '$branch')"
[all]="Force checking of all changes, including files in the base branch"
Expand All @@ -39,6 +43,9 @@ long_options=(
[versions]="Check versions files"
)

yamllint_cmd="yamllint"
have_yamllint_cmd=$(command -v "$yamllint_cmd" || true)

usage()
{
cat <<EOT
Expand Down Expand Up @@ -153,8 +160,7 @@ check_commits()
{
# Since this script is called from another repositories directory,
# ensure the utility is built before running it.
local self="$GOPATH/src/github.com/kata-containers/tests"
(cd "$self" && make checkcommits)
(cd "${tests_repo_dir}" && make checkcommits)

# Check the commits in the branch
{
Expand Down Expand Up @@ -216,14 +222,14 @@ check_go()
then
info "Installing ${linter}"

local linter_url=$(get_test_version "externals.golangci-lint.url")
local linter_version=$(get_test_version "externals.golangci-lint.version")
local linter_url=$(get_test_version "externals.golangci-lint.url")
local linter_version=$(get_test_version "externals.golangci-lint.version")

info "Forcing ${linter} version ${linter_version}"
build_version ${linter_url} "" ${linter_version}
build_version ${linter_url} "" ${linter_version}
fi

local linter_args="run -c ${cidir}/.golangci.yml"
local linter_args="run -c ${cidir}/.golangci.yml"

# Non-option arguments other than "./..." are
# considered to be directories by $linter, not package names.
Expand Down Expand Up @@ -264,12 +270,34 @@ check_versions()

[ ! -e "$db" ] && return

cmd="yamllint"
if [ -n "$(command -v $cmd)" ]; then
eval "$cmd" "$db"
if [ -n "$have_yamllint_cmd" ]; then
eval "$yamllint_cmd" "$db"
else
info "Cannot check versions as $yamllint_cmd not available"
fi
}

check_labels()
{
[ $(uname -s) != Linux ] && info "Can only check labels under Linux" && return

# Handle SLES which doesn't provide the required command.
[ -z "$have_yamllint_cmd" ] && info "Cannot check labels as $yamllint_cmd not available" && return

# Since this script is called from another repositories directory,
# ensure the utility is built before the script below (which uses it) is run.
(cd "${tests_repo_dir}" && make github-labels)

tmp=$(mktemp)

info "Checking labels for repo ${repo} using temporary combined database ${tmp}"

bash -f "${tests_repo_dir}/cmd/github-labels/github-labels.sh" "generate" "${repo}" "${tmp}"

# All tests passed so remove combined labels database
rm -f "${tmp}"
}

# Ensure all files (where possible) contain an SPDX license header
check_license_headers()
{
Expand Down Expand Up @@ -612,6 +640,7 @@ main()
--force) force="true" ;;
--golang) func=check_go ;;
-h|--help) usage; exit 0 ;;
--labels) func=check_labels;;
--licenses) func=check_license_headers ;;
--repo) repo="$2"; shift ;;
--vendor) func=check_vendor;;
Expand Down Expand Up @@ -665,6 +694,7 @@ main()
check_docs
check_files
check_vendor
check_labels
}

main "$@"
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ env:
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y -qq automake ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then travis_retry brew install bash; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install --user yamllint ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then travis_retry brew install bash yamllint; fi

script:
- bash .ci/static-checks.sh github.com/kata-containers/tests
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ ifneq ($(wildcard $(ARCH_FILE)),)
include $(ARCH_FILE)
endif

default: checkcommits
default: checkcommits github-labels

checkcommits:
make -C cmd/checkcommits

github-labels:
make -C cmd/github-labels

ginkgo:
ln -sf . vendor/src
GOPATH=$(PWD)/vendor go build ./vendor/github.com/onsi/ginkgo/ginkgo
Expand Down
32 changes: 32 additions & 0 deletions cmd/github-labels/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2017-2019 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

TARGET = kata-github-labels
SOURCES = $(shell find . -type f 2>&1 | grep -E '.*\.go$$')

VERSION := ${shell cat ./VERSION}
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")

BINDIR := $(GOPATH)/bin
DESTTARGET := $(abspath $(BINDIR)/$(TARGET))

default: install

check: $(SOURCES)
go test -v ./...

$(TARGET): $(SOURCES)
go build -o "$(TARGET)" -ldflags "-X main.name=${TARGET} -X main.commit=${COMMIT} -X main.version=${VERSION}" .

install: $(TARGET)
install -d $(shell dirname $(DESTTARGET))
install $(TARGET) $(DESTTARGET)

clean:
rm -f $(TARGET)

.PHONY: install clean
75 changes: 75 additions & 0 deletions cmd/github-labels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
* [Overview](#overview)
* [Generating the combined labels database](#generating-the-combined-labels-database)
* [Checking and summarising the labels database](#checking-and-summarising-the-labels-database)
* [Show labels](#show-labels)
* [Show categories](#show-categories)
* [Check only](#check-only)
* [Full details](#full-details)

# Overview

The Kata Project uses a number of GitHub repositories. To allow issues and PRs
to be handled consistently between repositories a standard set of issue labels
are used. These labels are stored in YAML format in the master
[labels database template](labels.yaml.in). This file is human-readable,
machine-readable, and self-describing (see the file for the introductory
description).

Each repository can contain a set of additional (repository-specific) labels,
which are stored in a top-level YAML template file called `labels.yaml.in`.

Expanding the templates and merging the two databases describes the full set
of labels a repository uses.

# Generating the combined labels database

You can run the `github_labels.sh` script with the `generate` argument to
create the combined labels database. The additional arguments specify the
repository (in order to generate the combined labels database) and the name of
a file to write the combined database:

```sh
$ ./github-labels.sh generate github.com/kata-containers/runtime /tmp/combined.yaml
```

This script validates the combined labels database by performing a number of
checks, including running the `kata-github-labels` tool in checking mode. See
the
[Checking and summarising the labels database](#checking-and-summarising-the-labels-database)
section for more information.

# Checking and summarising the labels database

The `kata-github-labels` tool checks and summarizes the labels database for
each repository.

## Show labels

Displays a summary of the labels:

```sh
$ kata-github-labels show labels labels.yaml
```

## Show categories

Shows all information about categories:

```sh
$ kata-github-labels show categories --with-labels labels.yaml
```
## Check only

Performs checks on a specified labels database:

```sh
$ kata-github-labels check labels.yaml
```

## Full details

Lists all available options:

```sh
$ kata-github-labels -h
```
1 change: 1 addition & 0 deletions cmd/github-labels/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
Loading