From 2566ed438c1f94eef8f76f6e63dec005cc31d9d3 Mon Sep 17 00:00:00 2001 From: James Hewitt Date: Thu, 31 Aug 2023 10:54:13 +0100 Subject: [PATCH] Add coverage and have one workflow for standard CI Signed-off-by: James Hewitt --- .gitattributes | 1 + .github/workflows/test.yml | 44 +++++++++++++++++++++++++++------- .github/workflows/validate.yml | 24 ------------------- .gitignore | 2 ++ Makefile | 25 +++++++++++++++++++ README.md | 1 + 6 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 .gitattributes delete mode 100644 .github/workflows/validate.yml create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d207b18 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.go text eol=lf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd31f25..1382d34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,20 @@ name: test -on: [push, pull_request] + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] permissions: contents: read +env: + TESTFLAGS: -v + BUILDFLAGS: -v + jobs: - test: + build: strategy: matrix: go-version: [1.20.x, 1.21.x] @@ -13,9 +22,28 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 10 steps: - - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 - - name: Test - run: go test -v ./... + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Build + run: | + make build + + - name: lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.53 + args: --print-resources-usage --timeout=10m --verbose + + - name: Test + run: | + make coverage + + - name: Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./ diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index eac9b42..0000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: validate -on: [push, pull_request] - -permissions: - contents: read - -jobs: - linters: - strategy: - matrix: - go-version: [1.20.x] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - timeout-minutes: 10 - steps: - - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 - - name: lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.53 - args: --print-resources-usage --timeout=10m --verbose diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc07e6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Cover profiles +*.out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c78576b --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +# Project packages. +PACKAGES=$(shell go list ./...) + +# Flags passed to `go test` +BUILDFLAGS ?= +TESTFLAGS ?= + +.PHONY: all build test coverage +.DEFAULT: all + +all: build + +build: ## no binaries to build, so just check compilation suceeds + go build ${BUILDFLAGS} ./... + +test: ## run tests + go test ${TESTFLAGS} ./... + +coverage: ## generate coverprofiles from the unit tests + rm -f coverage.txt + go test ${TESTFLAGS} -cover -coverprofile=cover.out ./... + +.PHONY: help +help: + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_\/%-]+:.*?##/ { printf " \033[36m%-27s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) diff --git a/README.md b/README.md index 1bfe34f..e2531e4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Go library to handle references to container images. [![Build Status](https://github.com/distribution/reference/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/distribution/reference/actions?query=workflow%3ACI) [![GoDoc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/distribution/reference) [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE) +[![codecov](https://codecov.io/gh/distribution/reference/branch/main/graph/badge.svg)](https://codecov.io/gh/distribution/reference) [![FOSSA Status](https://app.fossa.com/api/projects/custom%2B162%2Fgithub.com%2Fdistribution%2Freference.svg?type=shield)](https://app.fossa.com/projects/custom%2B162%2Fgithub.com%2Fdistribution%2Freference?ref=badge_shield) This repository contains a library for handling refrences to container images held in container registries. Please see [godoc](https://pkg.go.dev/github.com/distribution/reference) for details.