Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: github actions validate workflow #3381

Merged
merged 6 commits into from
Feb 25, 2022
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
38 changes: 0 additions & 38 deletions .circleci/config.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
/cli/winresources/versioninfo.json
/cli/winresources/*.syso
/man/man*/
/docs/yaml/gen/
/man/vendor/
/man/go.sum
/docs/yaml/
/docs/vendor/
/docs/go.sum
profile.out

# top-level go.mod is not meant to be checked in
/go.mod
/go.sum
21 changes: 21 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- lint
- shellcheck
- validate-vendor
- update-authors # ensure authors update target runs fine
steps:
-
name: Checkout
Expand All @@ -31,3 +32,23 @@ jobs:
uses: docker/bake-action@v1
with:
targets: ${{ matrix.target }}

validate-make:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- yamldocs # ensure yamldocs target runs fine
- manpages # ensure manpages target runs fine
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Run
shell: 'script --return --quiet --command "bash {0}"'
run: |
make -f docker.Makefile ${{ matrix.target }}
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ Thumbs.db
/build/
/cli/winresources/versioninfo.json
/cli/winresources/*.syso
/man/man1/
/man/man5/
/man/man8/
/docs/yaml/gen/
profile.out

# top-level go.mod is not meant to be checked in
/go.mod
/go.sum
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS))

.PHONY: clean
clean: ## remove build artifacts
rm -rf ./build/* cli/winresources/rsrc_* ./man/man[1-9] docs/yaml/gen
rm -rf ./build/* man/man[1-9] docs/yaml

.PHONY: test
test: test-unit ## run tests
Expand Down Expand Up @@ -77,8 +77,3 @@ yamldocs: ## generate documentation YAML files consumed by docs repo
.PHONY: help
help: ## print this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: ci-validate
ci-validate:
time make manpages
time make yamldocs
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Docker CLI

[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/cli)
[![Build Status](https://img.shields.io/github/workflow/status/docker/cli/build?logo=github)](https://github.com/docker/cli/actions?query=workflow%3Abuild)
[![Test Status](https://img.shields.io/github/workflow/status/docker/cli/test?logo=github)](https://github.com/docker/cli/actions?query=workflow%3Atest)
[![CircleCI Status](https://img.shields.io/circleci/build/github/docker/cli/master?logo=circleci)](https://circleci.com/gh/docker/cli/tree/master)
[![Build Status](https://img.shields.io/github/workflow/status/docker/cli/build?label=build&logo=github)](https://github.com/docker/cli/actions?query=workflow%3Abuild)
[![Test Status](https://img.shields.io/github/workflow/status/docker/cli/test?label=test&logo=github)](https://github.com/docker/cli/actions?query=workflow%3Atest)
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/cli)](https://goreportcard.com/report/github.com/docker/cli)
[![Codecov](https://codecov.io/gh/docker/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/docker/cli)

Expand Down
31 changes: 31 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
variable "GO_VERSION" {
default = "1.16.11"
}
variable "VERSION" {
default = ""
}
Expand All @@ -16,11 +19,19 @@ variable "COMPANY_NAME" {
default = ""
}

target "_common" {
args = {
GO_VERSION = GO_VERSION
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
}
}

group "default" {
targets = ["binary"]
}

target "binary" {
inherits = ["_common"]
target = "binary"
platforms = ["local"]
output = ["build"]
Expand All @@ -40,6 +51,7 @@ target "dynbinary" {
}

target "plugins" {
inherits = ["_common"]
target = "plugins"
platforms = ["local"]
output = ["build"]
Expand Down Expand Up @@ -67,30 +79,35 @@ target "plugins-cross" {
}

target "lint" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.lint"
target = "lint"
output = ["type=cacheonly"]
}

target "shellcheck" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.shellcheck"
target = "shellcheck"
output = ["type=cacheonly"]
}

target "validate-vendor" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "validate"
output = ["type=cacheonly"]
}

target "update-vendor" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "update"
output = ["."]
}

target "mod-outdated" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.vendor"
target = "outdated"
args = {
Expand All @@ -100,6 +117,20 @@ target "mod-outdated" {
output = ["type=cacheonly"]
}

target "validate-authors" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.authors"
target = "validate"
output = ["type=cacheonly"]
}

target "update-authors" {
inherits = ["_common"]
dockerfile = "./dockerfiles/Dockerfile.authors"
target = "update"
output = ["."]
}

target "test" {
target = "test"
output = ["type=cacheonly"]
Expand Down
2 changes: 1 addition & 1 deletion docker.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod-outdated: ## check outdated dependencies

.PHONY: authors
authors: ## generate AUTHORS file from git history
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make authors
docker buildx bake update-authors

.PHONY: manpages
manpages: build_docker_image ## generate man pages from go source and markdown
Expand Down
23 changes: 23 additions & 0 deletions dockerfiles/Dockerfile.authors
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1.3-labs

FROM alpine:3.14 AS gen
RUN apk add --no-cache bash git
WORKDIR /src
RUN --mount=type=bind,target=. \
mkdir /out && ./scripts/docs/generate-authors.sh /out

FROM scratch AS update
COPY --from=gen /out /

FROM gen AS validate
RUN --mount=type=bind,target=.,rw <<EOT
set -e
git add -A
cp -rf /out/* .
diff=$(git status --porcelain -- AUTHORS)
if [ -n "$diff" ]; then
echo >&2 'ERROR: Authors result differs. Please update with "make -f docker.Makefile authors"'
echo "$diff"
exit 1
fi
EOT
3 changes: 3 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/yaml
/go.sum
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ the place to edit them.

The docs in the general repo are open-source and we appreciate
your feedback and pull requests!

# Generate docs

```shell
$ make -f docker.Makefile yamldocs
```
67 changes: 67 additions & 0 deletions docs/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This file is intended for use with "go run"; it isn't really part of the package.

// +build docsgen

package main

import (
"log"
"os"

clidocstool "github.com/docker/cli-docs-tool"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/commands"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

const defaultSourcePath = "docs/reference/commandline/"

type options struct {
source string
target string
}

func gen(opts *options) error {
log.SetFlags(0)

dockerCLI, err := command.NewDockerCli()
if err != nil {
return err
}
cmd := &cobra.Command{
Use: "docker [OPTIONS] COMMAND [ARG...]",
Short: "The base command for the Docker CLI.",
}
commands.AddCommands(cmd, dockerCLI)

c, err := clidocstool.New(clidocstool.Options{
Root: cmd,
SourceDir: opts.source,
TargetDir: opts.target,
Plugin: false,
})
if err != nil {
return err
}

return c.GenYamlTree(cmd)
}

func run() error {
opts := &options{}
flags := pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
flags.StringVar(&opts.source, "source", defaultSourcePath, "Docs source folder")
flags.StringVar(&opts.target, "target", defaultSourcePath, "Docs target folder")
if err := flags.Parse(os.Args[1:]); err != nil {
return err
}
return gen(opts)
}

func main() {
if err := run(); err != nil {
log.Printf("ERROR: %+v", err)
os.Exit(1)
}
}
13 changes: 13 additions & 0 deletions docs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/docker/cli/docs

// dummy go.mod to avoid dealing with dependencies specific
// to docs generation and not really part of the project.

go 1.16

//require (
// github.com/docker/cli v0.0.0+incompatible
// github.com/docker/cli-docs-tool v0.3.0
//)
//
//replace github.com/docker/cli v0.0.0+incompatible => ../
7 changes: 7 additions & 0 deletions docs/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build tools

package main

import (
_ "github.com/docker/cli-docs-tool"
)
4 changes: 0 additions & 4 deletions docs/yaml/Dockerfile

This file was deleted.

Loading