Skip to content

Commit 1bf2680

Browse files
committed
ci: github actions test workflow
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 9bc104e commit 1bf2680

File tree

14 files changed

+163
-330
lines changed

14 files changed

+163
-330
lines changed

.circleci/config.yml

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,6 @@ version: 2
22

33
jobs:
44

5-
test:
6-
working_directory: /work
7-
docker: [{image: 'docker:20.10-git'}]
8-
environment:
9-
DOCKER_BUILDKIT: 1
10-
steps:
11-
- checkout
12-
- setup_remote_docker:
13-
version: 20.10.6
14-
reusable: true
15-
exclusive: false
16-
- run:
17-
name: "Docker version"
18-
command: docker version
19-
- run:
20-
name: "Docker info"
21-
command: docker info
22-
- run:
23-
name: "Unit Test with Coverage - build image"
24-
command: |
25-
mkdir -p test-results/unit-tests
26-
docker build --progress=plain -f dockerfiles/Dockerfile.dev --tag cli-builder:$CIRCLE_BUILD_NUM .
27-
- run:
28-
name: "Unit Test with Coverage"
29-
command: |
30-
docker run \
31-
-e GOTESTSUM_JUNITFILE=/tmp/junit.xml \
32-
--name \
33-
test-$CIRCLE_BUILD_NUM cli-builder:$CIRCLE_BUILD_NUM \
34-
make test-coverage
35-
docker cp \
36-
test-$CIRCLE_BUILD_NUM:/tmp/junit.xml \
37-
./test-results/unit-tests/junit.xml
38-
- run:
39-
name: "Upload to Codecov"
40-
command: |
41-
docker cp \
42-
test-$CIRCLE_BUILD_NUM:/go/src/github.com/docker/cli/coverage.txt \
43-
coverage.txt
44-
apk add -U bash curl
45-
curl -s https://codecov.io/bash | bash || \
46-
echo 'Codecov failed to upload'
47-
- store_test_results:
48-
path: test-results
49-
- store_artifacts:
50-
path: test-results
51-
525
validate:
536
working_directory: /work
547
docker: [{image: 'docker:20.10-git'}]
@@ -82,5 +35,4 @@ workflows:
8235
version: 2
8336
ci:
8437
jobs:
85-
- test
8638
- validate

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/cli/winresources/*.syso
44
/man/man*/
55
/docs/yaml/gen/
6-
coverage.txt
6+
/coverage
77
profile.out
88
/vndr.log

.github/workflows/e2e.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ jobs:
5252
env:
5353
BASE_VARIANT: ${{ matrix.base }}
5454
E2E_ENGINE_VERSION: ${{ matrix.engine-version }}
55+
TESTFLAGS: -coverprofile=/tmp/coverage/coverage.txt
56+
-
57+
name: Send to Codecov
58+
uses: codecov/codecov-action@v2
59+
with:
60+
file: ./coverage/coverage.txt

.github/workflows/test.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
- '[0-9]+.[0-9]{2}'
9+
tags:
10+
- 'v*'
11+
pull_request:
12+
13+
jobs:
14+
ctn:
15+
runs-on: ubuntu-latest
16+
steps:
17+
-
18+
name: Checkout
19+
uses: actions/checkout@v2
20+
-
21+
name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
-
24+
name: Test
25+
uses: docker/bake-action@v1
26+
with:
27+
targets: test-coverage
28+
-
29+
name: Send to Codecov
30+
uses: codecov/codecov-action@v2
31+
with:
32+
file: ./coverage/coverage.txt
33+
34+
host:
35+
runs-on: ${{ matrix.os }}
36+
env:
37+
GOPATH: ${{ github.workspace }}
38+
GOBIN: ${{ github.workspace }}/bin
39+
GO111MODULE: auto
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
os:
44+
- macos-latest
45+
# - windows-latest # FIXME: some tests are failing on the Windows runner, as well as on Appveyor since June 24, 2018: https://ci.appveyor.com/project/docker/cli/history
46+
steps:
47+
-
48+
name: Prepare git
49+
if: matrix.os == 'windows-latest'
50+
run: |
51+
git config --system core.autocrlf false
52+
git config --system core.eol lf
53+
-
54+
name: Checkout
55+
uses: actions/checkout@v2
56+
with:
57+
path: ${{ env.GOPATH }}/src/github.com/docker/cli
58+
-
59+
name: Set up Go
60+
uses: actions/setup-go@v2
61+
with:
62+
go-version: 1.16.10
63+
-
64+
name: Test
65+
run: |
66+
go test -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '/vendor/|/e2e/')
67+
go tool cover -func=/tmp/coverage.txt
68+
working-directory: ${{ env.GOPATH }}/src/github.com/docker/cli
69+
shell: bash
70+
-
71+
name: Send to Codecov
72+
uses: codecov/codecov-action@v2
73+
with:
74+
file: /tmp/coverage.txt
75+
working-directory: ${{ env.GOPATH }}/src/github.com/docker/cli

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ Thumbs.db
1414
/man/man5/
1515
/man/man8/
1616
/docs/yaml/gen/
17-
coverage.txt
17+
/coverage
1818
profile.out
1919
/vndr.log

Dockerfile

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ARG BASE_VARIANT=alpine
44
ARG GO_VERSION=1.16.10
55
ARG XX_VERSION=1.0.0-rc.2
66
ARG GOVERSIONINFO_VERSION=v1.3.0
7+
ARG GOTESTSUM_VERSION=v1.7.0
78

89
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS gostable
910
FROM --platform=$BUILDPLATFORM golang:1.17rc1-${BASE_VARIANT} AS golatest
@@ -37,6 +38,19 @@ FROM build-base-buster AS build-buster
3738
ARG TARGETPLATFORM
3839
RUN xx-apt install --no-install-recommends -y libc6-dev libgcc-8-dev
3940

41+
FROM build-base-${BASE_VARIANT} AS goversioninfo
42+
ARG GOVERSIONINFO_VERSION
43+
RUN --mount=type=cache,target=/root/.cache/go-build \
44+
--mount=type=cache,target=/go/pkg/mod \
45+
GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
46+
47+
FROM build-base-${BASE_VARIANT} AS gotestsum
48+
ARG GOTESTSUM_VERSION
49+
RUN --mount=type=cache,target=/root/.cache/go-build \
50+
--mount=type=cache,target=/go/pkg/mod \
51+
GOBIN=/out GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
52+
&& /out/gotestsum --version
53+
4054
FROM build-${BASE_VARIANT} AS build
4155
# GO_LINKMODE defines if static or dynamic binary should be produced
4256
ARG GO_LINKMODE=static
@@ -50,11 +64,7 @@ ARG CGO_ENABLED
5064
ARG VERSION
5165
# COMPANY_NAME sets the company that produced the windows binary
5266
ARG COMPANY_NAME
53-
# GOVERSIONINFO_VERSION defines goversioninfo tool version
54-
ARG GOVERSIONINFO_VERSION
55-
RUN --mount=type=cache,target=/root/.cache \
56-
# install goversioninfo tool
57-
GO111MODULE=auto go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}
67+
COPY --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
5868
RUN --mount=type=bind,target=.,ro \
5969
--mount=type=cache,target=/root/.cache \
6070
--mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
@@ -65,6 +75,17 @@ RUN --mount=type=bind,target=.,ro \
6575
TARGET=/out ./scripts/build/binary && \
6676
xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
6777

78+
FROM build-${BASE_VARIANT} AS test
79+
COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
80+
ENV GO111MODULE=auto
81+
RUN --mount=type=bind,target=.,rw \
82+
--mount=type=cache,target=/root/.cache \
83+
--mount=type=cache,target=/go/pkg/mod \
84+
gotestsum -- -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '/vendor/|/e2e/')
85+
86+
FROM scratch AS test-coverage
87+
COPY --from=test /tmp/coverage.txt /coverage.txt
88+
6889
FROM build-${BASE_VARIANT} AS build-plugins
6990
ARG GO_LINKMODE=static
7091
ARG GO_BUILDTAGS
@@ -85,13 +106,6 @@ ARG COMPOSE_VERSION=1.29.2
85106
RUN curl -fsSL https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && \
86107
chmod +x /usr/local/bin/docker-compose
87108

88-
FROM build-${BASE_VARIANT} AS gotestsum
89-
ARG GOTESTSUM_VERSION=v1.7.0
90-
RUN --mount=type=cache,target=/root/.cache/go-build \
91-
--mount=type=cache,target=/go/pkg/mod \
92-
GOBIN=/out GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
93-
&& /out/gotestsum --version
94-
95109
FROM e2e-base-${BASE_VARIANT} AS e2e
96110
ARG NOTARY_VERSION=v0.6.1
97111
ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ _:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS))
1313
clean: ## remove build artifacts
1414
rm -rf ./build/* cli/winresources/rsrc_* ./man/man[1-9] docs/yaml/gen
1515

16-
.PHONY: test-unit
17-
test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit
18-
gotestsum $(TESTFLAGS) -- $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')}
19-
2016
.PHONY: test
2117
test: test-unit ## run tests
2218

19+
.PHONY: test-unit
20+
test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit
21+
gotestsum -- $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')} $(TESTFLAGS)
22+
2323
.PHONY: test-coverage
2424
test-coverage: ## run test coverage
25-
gotestsum -- -coverprofile=coverage.txt $(shell go list ./... | grep -vE '/vendor/|/e2e/')
25+
mkdir -p ./coverage
26+
gotestsum -- $(shell go list ./... | grep -vE '/vendor/|/e2e/') -coverprofile=coverage.txt
2627

2728
.PHONY: lint
2829
lint: ## run all the lint tools

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/cli)
44
[![Build Status](https://img.shields.io/github/workflow/status/docker/cli/build?logo=github)](https://github.com/docker/cli/actions?query=workflow%3Abuild)
5+
[![Test Status](https://img.shields.io/github/workflow/status/docker/cli/test?logo=github)](https://github.com/docker/cli/actions?query=workflow%3Atest)
56
[![CircleCI Status](https://img.shields.io/circleci/build/github/docker/cli/master?logo=circleci)](https://circleci.com/gh/docker/cli/tree/master)
67
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/cli)](https://goreportcard.com/report/github.com/docker/cli)
78
[![Codecov](https://codecov.io/gh/docker/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/docker/cli)
@@ -45,6 +46,12 @@ Run all linting:
4546
docker buildx bake lint shellcheck
4647
```
4748

49+
Run test:
50+
51+
```shell
52+
docker buildx bake test
53+
```
54+
4855
List all the available targets:
4956

5057
```shell

appveyor.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

cli/command/cli_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ func TestNewAPIClientFromFlags(t *testing.T) {
3939

4040
func TestNewAPIClientFromFlagsForDefaultSchema(t *testing.T) {
4141
host := ":2375"
42+
slug := "tcp://localhost"
43+
if runtime.GOOS == "windows" {
44+
slug = "tcp://127.0.0.1"
45+
}
4246
opts := &flags.CommonOptions{Hosts: []string{host}}
4347
apiClient, err := NewAPIClientFromFlags(opts, &configfile.ConfigFile{})
4448
assert.NilError(t, err)
45-
assert.Equal(t, apiClient.DaemonHost(), "tcp://localhost"+host)
49+
assert.Equal(t, apiClient.DaemonHost(), slug+host)
4650
assert.Equal(t, apiClient.ClientVersion(), api.DefaultVersion)
4751
}
4852

0 commit comments

Comments
 (0)