diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d18d21a..fc1b248 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,5 +9,14 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Print env + run: env + + - name: Read event json + run: cat $GITHUB_EVENT_PATH + - name: Build - run: make -f docker.Makefile + run: DOCKER_BUILDKIT=1 make -f docker.Makefile build + + - name: E2E + run: DOCKER_BUILDKIT=1 make -f docker.Makefile test-e2e diff --git a/Dockerfile b/Dockerfile index 6e7386c..6e972a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ ARG GO_VERSION=1.13.7 ARG GOLANGCI_LINT_VERSION=v1.23.6 -ARG ALPINE_VERSION=3.11.3 - +ARG DND_VERSION=19.03 +# Builds the github-actions binary, checks linting, and runs unit level tests FROM golang:${GO_VERSION} AS builder RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} -ARG MAKE_TARGET=all +ARG MAKE_TARGET=default ENV CGO_ENABLED=0 WORKDIR /src @@ -17,13 +17,31 @@ COPY . . RUN make ${MAKE_TARGET} +# Used to run e2e tests for github-actions +# This image must be run as a container to run the tests +FROM golang:${GO_VERSION} AS e2e +ARG CLI_CHANNEL=stable +ARG CLI_VERSION=19.03.5 + +RUN apt-get install -y -q --no-install-recommends coreutils util-linux + +ENV CGO_ENABLED=0 +ENV GITHUB_ACTIONS_BINARY=/github-actions +WORKDIR /tests + +RUN curl -fL https://download.docker.com/linux/static/${CLI_CHANNEL}/x86_64/docker-${CLI_VERSION}.tgz | tar xzO docker/docker > /usr/bin/docker && chmod +x /usr/bin/docker + +COPY . . +COPY --from=builder /src/bin/github-actions /github-actions + +# Used to extract the github-actions binary FROM scratch AS cli COPY --from=builder /src/bin/github-actions github-actions - -FROM alpine:${ALPINE_VERSION} +# The github-actions image that is used by published docker github actions +FROM docker:${DND_VERSION} COPY --from=builder /src/bin/github-actions /github-actions diff --git a/Makefile b/Makefile index 5fc9b09..fbf8798 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -all: build lint test +default: build lint test-unit + +all: default test-e2e build: @$(call mkdir,bin) @@ -7,5 +9,11 @@ build: lint: golangci-lint run --config golangci.yml ./... -test: - go test ./... +test: test-unit test-e2e + +test-unit: + go test ./cmd/... ./internal/... + +test-e2e: build + docker build --file ./e2e/Dockerfile.registry -t github-actions-registry ./e2e + go test ./e2e/... diff --git a/README.md b/README.md index bfcc33a..f71fd2b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,143 @@ # github-actions -The core code base for Docker's GitHub Actions (https://github.com/features/actions). This code is used to build the docker/github-actions image that provides the functionality used by the published Docker GitHub Actions +The core code base for Docker's GitHub Actions (https://github.com/features/actions). This code is used to build the docker/github-actions image that provides the functionality used by the published Docker GitHub Actions. +`github-actions` runs a command line tool that shells out to docker to perform the various functions. Parameters are supplied to `github-actions` using environment variables in the form described by the GitHub Actions documentation. `github-actions` uses some of the default GitHub Actions environment variables as described in the individual commands section. + +## Commands + +Commands can be called using `docker run docker/github-actions {command}` + +### login + +Does a `docker login` using the supplied username and password. Will default to Docker Hub but can be supplied a server address to login to a third-party registry as required. + +#### inputs + +|Environment Variable|Required|Description| +|---|---|---| +|INPUT_USERNAME|yes|Username to login with| +|INPUT_PASSWORD|yes|Password to login with| +|INPUT_REGISTRY|no|Registry server to login to. Defaults to Docker Hub| + +### build + +Builds and tags a docker image. + +#### inputs + +|Environment Variable|Required|Description| +|---|---|---| +|INPUT_PATH|yes|Path to build from| +|INPUT_DOCKERFILE|no|Path to Dockerfile| +|INPUT_ADD_GIT_LABELS|no|Adds git labels (see below)| +|INPUT_TARGET|no|Target build stage to build| +|INPUT_BUILD_ARGS|no|Comma-delimited list of build-args| +|INPUT_LABELS|no|Comma-delimited list of labels| + +See the tagging section for information on tag inputs + +##### Git labels + +When `INPUT_ADD_GIT_LABELS` is `true` labels are automatically added to the image that contain data about the current state of the git repo: + +|Label|Description| +|---|---| +|com.docker.github-actions-actor|The username of the user that kicked off this run of the actions (e.g. the user that did the git push)| +|com.docker.github-actions-sha|The full git sha of this commit| + +### push + +Pushes a docker image. + +#### inputs + +See the tagging section for information on tag inputs + + +### build-push + +Builds, logs in, and pushes a docker image. + +#### inputs + +Same as the login and build commands with the addition of + +|Environment Variable|Required|Description| +|---|---|---| +|INPUT_PUSH|no|Will push the image if true| + + +## Tagging + +Tagging of images can be set manually, left to `github-actions` to automate, or a combination of the both. + +There are 4 input variables used for tagging + +|Environment Variable|Required|Description| +|---|---|---| +|INPUT_REGISTRY|no|Registry server to tag with| +|INPUT_REPOSITORY|yes|Repository to tag with| +|INPUT_TAGS|no|Hard coded comma-delimited list of tags| +|INPUT_TAG_WITH_REF|no|If true then `github-actions` will add tags depending on the git ref automatically as described below| +|INPUT_TAG_WITH_SHA|no|If true then `github-actions` will add a tag in the form `sha-{git-short-sha}`| + +If `INPUT_REGISTRY` is set then all tags are prefixed with `{INPUT_REGISTRY}/{INPUT_REPOSITORY}:`. +If not then all tags are prefixed with `{INPUT_REPOSITORY}:` + +Auto tags depend on the git reference that the run is associated with. The reference is passed to `github-actions` using the GitHub actions `GITHUB_REF` enviroment variable. + +If the reference is `refs/heads/{branch-name}` then the tag `{branch-name}` is added. For the master branch the `{branch-name}` is replaced with `latest`. + +If the reference is `refs/pull-requests/{pr}` then the tag `pr-{pr}` is added. + +If the reference is `refs/tags/{tag-name}` then the tag `{tag-name}` is added. + +Any `/` in the auto tags are replaced with `-`. + +For example if the environment variables are as follows: + +|Variable|Value| +|---|---| +|INPUT_REGISTRY|| +|INPUT_REPOSITORY|myorg/myimage| +|INPUT_TAGS|foo,bar| +|INPUT_TAG_WITH_REF|true| +|GITHUB_REF|refs/tags/v0.1| + +Then the image will be tagged with: +``` +myorg/myimage:foo +myorg/myimage:bar +myorg/myimage:v0.1 +``` + +If the variables are as follows: + +|Variable|Value| +|---|---| +|INPUT_REGISTRY|myregistry| +|INPUT_REPOSITORY|myorg/myimage| +|INPUT_TAGS|foo,bar| +|INPUT_TAG_WITH_REF|true| +|INPUT_TAG_WITH_SHA|true| +|GITHUB_REF|refs/heads/master| +|GITHUB_SHA|c6df8c68eb71799f9c9ab4a4a4650d6aabd7e415| + +Then the image will be tagged with: +``` +myregistry/myorg/myimage:foo +myregistry/myorg/myimage:bar +myregistry/myorg/myimage:lastest +myregistry/myorg/myimage:c6df8c6 +``` ## Building github-actions The code is written in Go v1.13 with `go mod`. It can be built locally using the `Makefile` or in docker using the `docker.Makefile`. `make -f docker.Makefile` will build the code, check the linting using golangci-lint, run the go tests, and build the image with a tag of docker/github-actions:latest -`make -f docker.Makefile TAG=foo` will build the code, check the linting using golangci-lint, run the go tests, and build the image with a tag of docker/github-actions:foo - `make -f docker.Makefile image` will build the github-actions image without a tag and without running test or lint checking `make -f docker.Makefile cli` will build the cli and copy it to `./bin/github-actions` -`make -f docker.Makefile test` will run the go tests +`make -f docker.Makefile test` will run the unit and e2e tests diff --git a/cmd/build.go b/cmd/build.go new file mode 100644 index 0000000..085f6be --- /dev/null +++ b/cmd/build.go @@ -0,0 +1,25 @@ +package main + +import ( + "github.com/docker/github-actions/internal/command" + "github.com/docker/github-actions/internal/options" +) + +func build(cmd command.Runner) error { + o, err := options.GetBuildOptions() + if err != nil { + return err + } + + github, err := options.GetGitHubOptions() + if err != nil { + return err + } + + tags, err := options.GetTags(options.GetRegistry(), github) + if err != nil { + return err + } + + return command.RunBuild(cmd, o, github, tags) +} diff --git a/cmd/build_push.go b/cmd/build_push.go new file mode 100644 index 0000000..4e785b6 --- /dev/null +++ b/cmd/build_push.go @@ -0,0 +1,43 @@ +package main + +import ( + "github.com/docker/github-actions/internal/command" + "github.com/docker/github-actions/internal/options" +) + +func buildPush(cmd command.Runner) error { + github, err := options.GetGitHubOptions() + if err != nil { + return err + } + + registry := options.GetRegistry() + tags, err := options.GetTags(registry, github) + if err != nil { + return err + } + + build, err := options.GetBuildOptions() + if err != nil { + return err + } + if err = command.RunBuild(cmd, build, github, tags); err != nil { + return err + } + + if shouldPush, err := options.ShouldPush(); err != nil { + return err + } else if shouldPush { + login, err := options.GetLoginOptions() + if err != nil { + return err + } + if login.Username != "" && login.Password != "" { + if err := command.RunLogin(cmd, login, registry); err != nil { + return err + } + } + } + + return command.RunPush(cmd, tags) +} diff --git a/cmd/login.go b/cmd/login.go new file mode 100644 index 0000000..3f9d34c --- /dev/null +++ b/cmd/login.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/docker/github-actions/internal/command" + "github.com/docker/github-actions/internal/options" +) + +func login(cmd command.Runner) error { + o, err := options.GetLoginOptions() + if err != nil { + return err + } + + return command.RunLogin(cmd, o, options.GetRegistry()) +} diff --git a/cmd/main.go b/cmd/main.go index b325279..24c40b6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,17 +4,56 @@ import ( "fmt" "os" - commandLine "github.com/urfave/cli/v2" + "github.com/docker/github-actions/internal/command" + "github.com/docker/github-actions/internal/options" + "github.com/spf13/cobra" ) func main() { - app := &commandLine.App{ - Name: "docker github actions", - Usage: "Used in GitHub Actions to run Docker workflows", + _, err := options.GetGitHubOptions() + if err != nil { + fmt.Println(err) + os.Exit(1) } - err := app.Run(os.Args) - if err != nil { + runner := command.NewRunner() + + rootCmd := &cobra.Command{ + Use: "github-actions", + Short: "Used in GitHub Actions to run Docker workflows", + } + rootCmd.AddCommand( + &cobra.Command{ + Use: "login", + Short: "Logs into a docker registry", + RunE: func(cmd *cobra.Command, args []string) error { + return login(runner) + }, + }, + &cobra.Command{ + Use: "build", + Short: "Builds a docker image", + RunE: func(cmd *cobra.Command, args []string) error { + return build(runner) + }, + }, + &cobra.Command{ + Use: "push", + Short: "Pushes a docker image", + RunE: func(cmd *cobra.Command, args []string) error { + return push(runner) + }, + }, + &cobra.Command{ + Use: "build-push", + Short: "Builds and pushes a docker image to a registry, logging in if necessary", + RunE: func(cmd *cobra.Command, args []string) error { + return buildPush(runner) + }, + }, + ) + + if err = rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } diff --git a/cmd/push.go b/cmd/push.go new file mode 100644 index 0000000..1521ea6 --- /dev/null +++ b/cmd/push.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/docker/github-actions/internal/command" + "github.com/docker/github-actions/internal/options" +) + +func push(cmd command.Runner) error { + github, err := options.GetGitHubOptions() + if err != nil { + return err + } + tags, err := options.GetTags(options.GetRegistry(), github) + if err != nil { + return err + } + return command.RunPush(cmd, tags) +} diff --git a/docker.Makefile b/docker.Makefile index 7a67273..6410f0e 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -1,9 +1,13 @@ TAG ?= latest -STATIC_FLAGS = BUILDKIT_PROGRESS=plain -DOCKER_BUILD = $(STATIC_FLAGS) docker build +DOCKER_BUILD = docker build --progress=plain -all: - $(DOCKER_BUILD) -t docker/github-actions:$(TAG) . +ROOT_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +ROOT_DIR := $(subst .\,,$(ROOT_DIR)) + +all: build test-unit + +build: + $(DOCKER_BUILD) -t docker/github-actions-default --build-arg MAKE_TARGET=default . image: $(DOCKER_BUILD) -t docker/github-actions:$(TAG) --build-arg MAKE_TARGET=build . @@ -13,7 +17,13 @@ cli: $(DOCKER_BUILD) -t github-actions-cli --target=cli --output type=local,dest=./bin/ --build-arg MAKE_TARGET=build . lint: - $(DOCKER_BUILD) -t github-actions-lint --build-arg MAKE_TARGET=lint . + $(DOCKER_BUILD) -t github-actions-lint --target=builder --build-arg MAKE_TARGET=lint . + +test: test-unit test-e2e + +test-unit: + $(DOCKER_BUILD) -t github-actions-test-unit --target=builder --build-arg MAKE_TARGET=test-unit . -test: - $(DOCKER_BUILD) -t github-actions-test --build-arg MAKE_TARGET=test . +test-e2e: + $(DOCKER_BUILD) -t github-actions-test-e2e --target e2e --build-arg MAKE_TARGET=build . + docker run --rm --network="host" -v /var/run/docker.sock:/var/run/docker.sock github-actions-test-e2e make test-e2e diff --git a/e2e/Dockerfile.registry b/e2e/Dockerfile.registry new file mode 100644 index 0000000..1a2c62c --- /dev/null +++ b/e2e/Dockerfile.registry @@ -0,0 +1,7 @@ +FROM registry:2 + +ENV REGISTRY_AUTH=htpasswd +ENV REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" +ENV REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd + +COPY ./testdata/auth/htpasswd /auth/htpasswd diff --git a/e2e/build_push_test.go b/e2e/build_push_test.go new file mode 100644 index 0000000..546bf52 --- /dev/null +++ b/e2e/build_push_test.go @@ -0,0 +1,61 @@ +package e2e + +import ( + "os/exec" + "sort" + "testing" + + "gotest.tools/v3/assert" +) + +func TestBuildPush(t *testing.T) { + tags := []string{ + "localhost:5000/my-repository:build-push-tag1", + "localhost:5000/my-repository:build-push-test", + } + labels := map[string]string{ + "a": "a1", + "com.docker.github-actions-actor": "actor", + "com.docker.github-actions-sha": "sha", + } + err := removeImages(tags) + assert.NilError(t, err) + defer removeImages(tags) + + err = setupLocalRegistry() + assert.NilError(t, err) + defer removeLocalRegistry() + + err = loginLocalRegistry() + assert.NilError(t, err) + + err = runActionsCommand("build-push", "testdata/build_push_tests/build_push.env") + assert.NilError(t, err) + + for _, tag := range tags { + assertBuildPushImages(t, tag, tags, labels) + } + + err = removeImages(tags) + assert.NilError(t, err) + + for _, tag := range tags { + err = exec.Command("docker", "pull", tag).Run() + assert.NilError(t, err) + } + + for _, tag := range tags { + assertBuildPushImages(t, tag, tags, labels) + } +} + +func assertBuildPushImages(t *testing.T, image string, expectedTags []string, expectedLabels map[string]string) { + inspect, err := inspectImage(image) + assert.NilError(t, err) + + repoTags := inspect.RepoTags + sort.Strings(repoTags) + + assert.DeepEqual(t, expectedTags, repoTags) + assert.DeepEqual(t, expectedLabels, inspect.Config.Labels) +} diff --git a/e2e/build_test.go b/e2e/build_test.go new file mode 100644 index 0000000..a446399 --- /dev/null +++ b/e2e/build_test.go @@ -0,0 +1,106 @@ +package e2e + +import ( + "os/exec" + "testing" + + "github.com/hashicorp/go-multierror" + "gotest.tools/v3/assert" +) + +func TestBuild(t *testing.T) { + testCases := []struct { + name string + envFile string + expectedTags []string + expectedLabels map[string]string + }{ + { + name: "static-tags", + envFile: "testdata/build_tests/static_tags.env", + expectedTags: []string{ + "localhost:5000/my-repository:v1-static-tags", + "localhost:5000/my-repository:v1.1-static-tags", + }, + }, + { + name: "static-labels", + envFile: "testdata/build_tests/static_labels.env", + expectedTags: []string{ + "localhost:5000/my-repository:static-labels", + }, + expectedLabels: map[string]string{ + "a": "a1", + "b": "b1", + }, + }, + { + name: "auto-labels", + envFile: "testdata/build_tests/auto_labels.env", + expectedTags: []string{ + "localhost:5000/my-repository:auto-labels", + }, + expectedLabels: map[string]string{ + "a": "a1", + "com.docker.github-actions-actor": "actor", + "com.docker.github-actions-sha": "sha", + }, + }, + { + name: "auto-tags-master", + envFile: "testdata/build_tests/tag_master.env", + expectedTags: []string{ + "localhost:5000/my-repository:auto-tags-master", + "localhost:5000/my-repository:latest", + }, + }, + { + name: "auto-tags-branch", + envFile: "testdata/build_tests/tag_branch.env", + expectedTags: []string{ + "localhost:5000/my-repository:auto-tags-branch", + "localhost:5000/my-repository:branch", + }, + }, + { + name: "auto-tags-pr", + envFile: "testdata/build_tests/tag_pr.env", + expectedTags: []string{ + "localhost:5000/my-repository:pr-pr1", + }, + }, + { + name: "auto-tags-tag", + envFile: "testdata/build_tests/tag_tag.env", + expectedTags: []string{ + "localhost:5000/my-repository:tag1", + }, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := runActionsCommand("build", tc.envFile) + assert.NilError(t, err) + defer removeImages(tc.expectedTags) + + for _, tag := range tc.expectedTags { + inspect, err := inspectImage(tag) + assert.NilError(t, err) + assert.DeepEqual(t, tc.expectedTags, inspect.RepoTags) + assert.DeepEqual(t, tc.expectedLabels, inspect.Config.Labels) + } + }) + } +} + +func removeImages(tags []string) error { + var result error + for _, tag := range tags { + if err := exec.Command("docker", "rmi", "-f", tag).Run(); err != nil { + result = multierror.Append(result, err) + } + } + return result +} diff --git a/e2e/helper_test.go b/e2e/helper_test.go new file mode 100644 index 0000000..fe5fb8c --- /dev/null +++ b/e2e/helper_test.go @@ -0,0 +1,93 @@ +package e2e + +import ( + "bufio" + "encoding/json" + "fmt" + "os" + "os/exec" +) + +const ( + registryContainerName = "github-actions-registry" + githubActionsImage = "github-actions-e2e" +) + +func readEnvFile(envFile string) ([]string, error) { + var vars []string + + file, err := os.Open(envFile) + if err != nil { + return vars, err + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + vars = append(vars, scanner.Text()) + } + + path := os.Getenv("PATH") + vars = append(vars, fmt.Sprintf("PATH=%s", path)) + return vars, scanner.Err() +} + +func setupLocalRegistry() error { + _ = removeLocalRegistry() + + cmd := exec.Command("docker", "run", "-d", "-p", "5000:5000", "--name", registryContainerName, registryContainerName) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func removeLocalRegistry() error { + return exec.Command("docker", "rm", "-f", registryContainerName).Run() +} + +func runActionsCommand(command, envFile string) error { + vars, err := readEnvFile(envFile) + if err != nil { + return err + } + + bin, err := getActionsBinaryPath() + if err != nil { + return err + } + + cmd := exec.Command(bin, command) + cmd.Env = vars + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func getActionsBinaryPath() (string, error) { + if path := os.Getenv("GITHUB_ACTIONS_BINARY"); path != "" { + return path, nil + } + + return "../bin/github-actions", nil +} + +func inspectImage(image string) (inspectResult, error) { + out, err := exec.Command("docker", "inspect", image).Output() + if err != nil { + return inspectResult{}, err + } + var result []inspectResult + if err = json.Unmarshal(out, &result); err != nil { + return inspectResult{}, err + } + return result[0], nil +} + +type inspectResult struct { + RepoTags []string `json:"RepoTags"` + Config inspectResultConfig `json:"Config"` +} + +type inspectResultConfig struct { + Labels map[string]string `json:"Labels"` +} diff --git a/e2e/login_test.go b/e2e/login_test.go new file mode 100644 index 0000000..8cc7bf5 --- /dev/null +++ b/e2e/login_test.go @@ -0,0 +1,25 @@ +package e2e + +import ( + "testing" + "time" + + "gotest.tools/v3/assert" + "k8s.io/apimachinery/pkg/util/wait" +) + +func TestLogin(t *testing.T) { + err := setupLocalRegistry() + assert.NilError(t, err) + defer removeLocalRegistry() + + err = loginLocalRegistry() + assert.NilError(t, err) +} + +func loginLocalRegistry() error { + return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) { + err := runActionsCommand("login", "testdata/login_test.env") + return err == nil, err + }) +} diff --git a/e2e/push_test.go b/e2e/push_test.go new file mode 100644 index 0000000..00b9e09 --- /dev/null +++ b/e2e/push_test.go @@ -0,0 +1,48 @@ +package e2e + +import ( + "os/exec" + "testing" + + "gotest.tools/v3/assert" +) + +func TestPush(t *testing.T) { + err := setupLocalRegistry() + assert.NilError(t, err) + defer removeLocalRegistry() + + err = loginLocalRegistry() + assert.NilError(t, err) + + tags := []string{"localhost:5000/my-repository:push-test"} + + err = removeImages(tags) + assert.NilError(t, err) + + err = runActionsCommand("build", "testdata/push_tests/push.env") + assert.NilError(t, err) + + err = runActionsCommand("push", "testdata/push_tests/push.env") + assert.NilError(t, err) + + err = removeImages(tags) + assert.NilError(t, err) + + err = exec.Command("docker", "pull", tags[0]).Run() + defer removeImages(tags) + assert.NilError(t, err) + + result, err := inspectImage(tags[0]) + assert.NilError(t, err) + assert.DeepEqual(t, + inspectResult{ + RepoTags: tags, + Config: inspectResultConfig{ + Labels: map[string]string{ + "a": "a1", + "b": "b1", + }, + }, + }, result) +} diff --git a/e2e/testdata/auth/htpasswd b/e2e/testdata/auth/htpasswd new file mode 100644 index 0000000..30c69ff --- /dev/null +++ b/e2e/testdata/auth/htpasswd @@ -0,0 +1,2 @@ +my_user:$2y$05$aj/uKGxLnExU9dMOYtDrOOTp6UfLWIt1r9Y3vz9MnkhK/8z8mwUse + diff --git a/e2e/testdata/build_push_tests/Dockerfile b/e2e/testdata/build_push_tests/Dockerfile new file mode 100644 index 0000000..44f2edf --- /dev/null +++ b/e2e/testdata/build_push_tests/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine + +ENTRYPOINT ["echo", "hello-world build-push"] \ No newline at end of file diff --git a/e2e/testdata/build_push_tests/build_push.env b/e2e/testdata/build_push_tests/build_push.env new file mode 100644 index 0000000..fc78c6e --- /dev/null +++ b/e2e/testdata/build_push_tests/build_push.env @@ -0,0 +1,14 @@ +INPUT_PATH=./testdata/build_push_tests +INPUT_DOCKERFILE=./testdata/build_push_tests/Dockerfile +INPUT_TAG_WITH_REF=true +INPUT_ADD_GIT_LABELS=true +INPUT_TAGS=build-push-test +INPUT_LABELS=a=a1 +INPUT_REGISTRY=localhost:5000 +INPUT_USERNAME=my_user +INPUT_PASSWORD=my_password +INPUT_REPOSITORY=my-repository +INPUT_PUSH=true +GITHUB_ACTOR=actor +GITHUB_SHA=sha +GITHUB_REF=refs/tags/build-push-tag1 diff --git a/e2e/testdata/build_tests/Dockerfile b/e2e/testdata/build_tests/Dockerfile new file mode 100644 index 0000000..62ecf71 --- /dev/null +++ b/e2e/testdata/build_tests/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine + +ENTRYPOINT ["echo", "hello-world build"] \ No newline at end of file diff --git a/e2e/testdata/build_tests/auto_labels.env b/e2e/testdata/build_tests/auto_labels.env new file mode 100644 index 0000000..be5e42d --- /dev/null +++ b/e2e/testdata/build_tests/auto_labels.env @@ -0,0 +1,10 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=false +INPUT_ADD_GIT_LABELS=true +INPUT_TAGS=auto-labels +INPUT_LABELS=a=a1 +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository +GITHUB_ACTOR=actor +GITHUB_SHA=sha diff --git a/e2e/testdata/build_tests/static_labels.env b/e2e/testdata/build_tests/static_labels.env new file mode 100644 index 0000000..2be65ee --- /dev/null +++ b/e2e/testdata/build_tests/static_labels.env @@ -0,0 +1,8 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=false +INPUT_ADD_GIT_LABELS=false +INPUT_TAGS=static-labels +INPUT_LABELS=a=a1,b=b1 +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository diff --git a/e2e/testdata/build_tests/static_tags.env b/e2e/testdata/build_tests/static_tags.env new file mode 100644 index 0000000..6e8046d --- /dev/null +++ b/e2e/testdata/build_tests/static_tags.env @@ -0,0 +1,7 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=false +INPUT_ADD_GIT_LABELS=false +INPUT_TAGS=v1-static-tags,v1.1-static-tags +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository diff --git a/e2e/testdata/build_tests/tag_branch.env b/e2e/testdata/build_tests/tag_branch.env new file mode 100644 index 0000000..7459e9b --- /dev/null +++ b/e2e/testdata/build_tests/tag_branch.env @@ -0,0 +1,8 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=true +INPUT_ADD_GIT_LABELS=false +INPUT_TAGS=auto-tags-branch +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository +GITHUB_REF=refs/heads/branch diff --git a/e2e/testdata/build_tests/tag_master.env b/e2e/testdata/build_tests/tag_master.env new file mode 100644 index 0000000..6891aa7 --- /dev/null +++ b/e2e/testdata/build_tests/tag_master.env @@ -0,0 +1,8 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=true +INPUT_ADD_GIT_LABELS=false +INPUT_TAGS=auto-tags-master +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository +GITHUB_REF=refs/heads/master diff --git a/e2e/testdata/build_tests/tag_pr.env b/e2e/testdata/build_tests/tag_pr.env new file mode 100644 index 0000000..b90bd7a --- /dev/null +++ b/e2e/testdata/build_tests/tag_pr.env @@ -0,0 +1,7 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=true +INPUT_ADD_GIT_LABELS=false +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository +GITHUB_REF=refs/pulls/pr1 diff --git a/e2e/testdata/build_tests/tag_tag.env b/e2e/testdata/build_tests/tag_tag.env new file mode 100644 index 0000000..f13ed94 --- /dev/null +++ b/e2e/testdata/build_tests/tag_tag.env @@ -0,0 +1,7 @@ +INPUT_PATH=./testdata/build_tests +INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile +INPUT_TAG_WITH_REF=true +INPUT_ADD_GIT_LABELS=false +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository +GITHUB_REF=refs/tags/tag1 diff --git a/e2e/testdata/login_test.env b/e2e/testdata/login_test.env new file mode 100644 index 0000000..b58b3e4 --- /dev/null +++ b/e2e/testdata/login_test.env @@ -0,0 +1,3 @@ +INPUT_REGISTRY=localhost:5000 +INPUT_USERNAME=my_user +INPUT_PASSWORD=my_password diff --git a/e2e/testdata/push_tests/Dockerfile b/e2e/testdata/push_tests/Dockerfile new file mode 100644 index 0000000..dfbed4c --- /dev/null +++ b/e2e/testdata/push_tests/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine + +ENTRYPOINT ["echo", "hello-world push"] \ No newline at end of file diff --git a/e2e/testdata/push_tests/push.env b/e2e/testdata/push_tests/push.env new file mode 100644 index 0000000..1a2205d --- /dev/null +++ b/e2e/testdata/push_tests/push.env @@ -0,0 +1,8 @@ +INPUT_PATH=./testdata/push_tests +INPUT_DOCKERFILE=./testdata/push_tests/Dockerfile +INPUT_TAG_WITH_REF=false +INPUT_ADD_GIT_LABELS=false +INPUT_TAGS=push-test +INPUT_LABELS=a=a1,b=b1 +INPUT_REGISTRY=localhost:5000 +INPUT_REPOSITORY=my-repository diff --git a/go.mod b/go.mod index 14fe100..a55c953 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,11 @@ module github.com/docker/github-actions go 1.13 -require github.com/urfave/cli/v2 v2.1.1 +require ( + github.com/caarlos0/env/v6 v6.1.0 + github.com/hashicorp/go-multierror v1.0.0 + github.com/magiconair/properties v1.8.1 // indirect + github.com/spf13/cobra v0.0.6 + gotest.tools/v3 v3.0.2 + k8s.io/apimachinery v0.17.3 +) diff --git a/go.sum b/go.sum index 7731077..f11eb99 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,223 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= +github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/caarlos0/env/v6 v6.1.0 h1:4FbM+HmZA/Q5wdSrH2kj0KQXm7xnhuO8y3TuOTnOvqc= +github.com/caarlos0/env/v6 v6.1.0/go.mod h1:iUA6X3VCAOwDhoqvgKlTGjjwJzQseIJaFYApUqQkt+8= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= +github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= +github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= +github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= +github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= +github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs= +github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= +gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/apimachinery v0.17.3 h1:f+uZV6rm4/tHE7xXgLyToprg6xWairaClGVkm2t8omg= +k8s.io/apimachinery v0.17.3/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g= +k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= +k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= +sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/internal/command/args.go b/internal/command/args.go new file mode 100644 index 0000000..c4a776f --- /dev/null +++ b/internal/command/args.go @@ -0,0 +1,50 @@ +package command + +import ( + "github.com/docker/github-actions/internal/options" +) + +// LoginArgs converts login options into the cli arguments used to call `docker login` +func LoginArgs(o options.Login, registry string) []string { + args := []string{"login", "--username", o.Username, "--password", o.Password} + if registry != "" { + args = append(args, registry) + } + return args +} + +// BuildArgs converts build options into the cli arguments used to call `docker build` +func BuildArgs(o options.Build, github options.GitHub, tags []string) []string { + args := []string{"build"} + + for _, tag := range tags { + args = append(args, "-t", tag) + } + + for _, label := range options.GetLabels(o, github) { + args = append(args, "--label", label) + } + + if o.Dockerfile != "" { + args = append(args, "--file", o.Dockerfile) + } + + if o.Target != "" { + args = append(args, "--target", o.Target) + } + + if o.AlwaysPull { + args = append(args, "--pull") + } + + for _, buildArg := range o.BuildArgs { + args = append(args, "--build-arg", buildArg) + } + + return append(args, o.Path) +} + +// PushArgs converts tags into the cli arguments used to call `docker push` +func PushArgs(tag string) []string { + return []string{"push", tag} +} diff --git a/internal/command/args_test.go b/internal/command/args_test.go new file mode 100644 index 0000000..43f561c --- /dev/null +++ b/internal/command/args_test.go @@ -0,0 +1,107 @@ +package command + +import ( + "testing" + + "github.com/docker/github-actions/internal/options" + "gotest.tools/v3/assert" +) + +func TestLoginArgs(t *testing.T) { + expected := []string{"login", "--username", "username", "--password", "password"} + o := options.Login{ + Username: "username", + Password: "password", + } + args := LoginArgs(o, "") + + assert.DeepEqual(t, expected, args) + + args = LoginArgs(o, "registry") + expected = append(expected, "registry") + assert.DeepEqual(t, expected, args) +} + +func TestBuildArgs(t *testing.T) { + testCases := []struct { + name string + build options.Build + github options.GitHub + tags []string + expected []string + }{ + { + name: "basic", + build: options.Build{Path: "path"}, + expected: []string{"build", "path"}, + }, + { + name: "with-dockerfile", + build: options.Build{Path: ".", Dockerfile: "dockerfile"}, + expected: []string{"build", "--file", "dockerfile", "."}, + }, + { + name: "with-tags", + build: options.Build{Path: "."}, + tags: []string{"tag1", "tag2"}, + expected: []string{"build", "-t", "tag1", "-t", "tag2", "."}, + }, + { + name: "with-static-labels", + build: options.Build{ + Path: ".", + Labels: []string{"label1", "label2"}, + }, + expected: []string{"build", "--label", "label1", "--label", "label2", "."}, + }, + { + name: "with-git-labels", + build: options.Build{ + Path: ".", + AddGitLabels: true, + Labels: []string{"label1"}, + }, + github: options.GitHub{ + Actor: "actor", + Sha: "sha", + }, + expected: []string{"build", "--label", "label1", "--label", "com.docker.github-actions-actor=actor", "--label", "com.docker.github-actions-sha=sha", "."}, + }, + { + name: "with-target", + build: options.Build{ + Path: ".", + Target: "target", + }, + expected: []string{"build", "--target", "target", "."}, + }, + { + name: "with-always-pull", + build: options.Build{ + Path: ".", + AlwaysPull: true, + }, + expected: []string{"build", "--pull", "."}, + }, + { + name: "with-build-args", + build: options.Build{ + Path: ".", + BuildArgs: []string{"build-arg-1", "build-arg-2"}, + }, + expected: []string{"build", "--build-arg", "build-arg-1", "--build-arg", "build-arg-2", "."}, + }, + } + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + args := BuildArgs(tc.build, tc.github, tc.tags) + assert.DeepEqual(t, tc.expected, args) + }) + } +} + +func TestPushArgs(t *testing.T) { + args := PushArgs("tag1") + assert.DeepEqual(t, []string{"push", "tag1"}, args) +} diff --git a/internal/command/runner.go b/internal/command/runner.go new file mode 100644 index 0000000..60dded2 --- /dev/null +++ b/internal/command/runner.go @@ -0,0 +1,52 @@ +package command + +import ( + "os" + "os/exec" + + "github.com/docker/github-actions/internal/options" +) + +// Runner executes standard commands +type Runner interface { + // Run executes the given command with arguments + Run(name string, args ...string) error +} + +type execRunner struct{} + +// NewRunner returns a new Runner with the stdout and stderr defaulting to os +func NewRunner() Runner { + return execRunner{} +} + +// Run executes the given command with arguments using exec.Command +func (runner execRunner) Run(name string, args ...string) error { + cmd := exec.Command(name, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +// RunLogin runs a docker login +func RunLogin(cmd Runner, opt options.Login, registry string) error { + args := LoginArgs(opt, registry) + return cmd.Run("docker", args...) +} + +// RunBuild runs a docker build and tags the resulting image +func RunBuild(cmd Runner, opt options.Build, github options.GitHub, tags []string) error { + args := BuildArgs(opt, github, tags) + return cmd.Run("docker", args...) +} + +// RunPush runs a docker push for each tag +func RunPush(cmd Runner, tags []string) error { + for _, tag := range tags { + args := PushArgs(tag) + if err := cmd.Run("docker", args...); err != nil { + return err + } + } + return nil +} diff --git a/internal/options/build.go b/internal/options/build.go new file mode 100644 index 0000000..7d634e0 --- /dev/null +++ b/internal/options/build.go @@ -0,0 +1,62 @@ +package options + +import ( + "fmt" + "os" + "strings" + + "github.com/caarlos0/env/v6" +) + +const githubLabelPrefix = "com.docker.github-actions" + +// Build contains the parsed build action environment variables +type Build struct { + Path string `env:"INPUT_PATH"` + Dockerfile string `env:"INPUT_DOCKERFILE"` + AddGitLabels bool `env:"INPUT_ADD_GIT_LABELS"` + Target string `env:"INPUT_TARGET"` + AlwaysPull bool `env:"INPUT_ALWAYS_PULL"` + BuildArgs []string + Labels []string +} + +// GetBuildOptions gets the login action environment variables +func GetBuildOptions() (Build, error) { + var build Build + if err := env.Parse(&build); err != nil { + return build, err + } + + if buildArgs := os.Getenv("INPUT_BUILD_ARGS"); buildArgs != "" { + build.BuildArgs = strings.Split(buildArgs, ",") + } + + if labels := os.Getenv("INPUT_LABELS"); labels != "" { + build.Labels = strings.Split(labels, ",") + } + + return build, nil +} + +// GetLabels gets a list of all labels to build the image with including automatic labels created from github vars when AddGitLabels is true +func GetLabels(build Build, github GitHub) []string { + labels := []string{} + if build.Labels != nil { + labels = build.Labels + } + + if !build.AddGitLabels { + return labels + } + + if github.Actor != "" { + labels = append(labels, fmt.Sprintf("%s-actor=%s", githubLabelPrefix, github.Actor)) + } + + if github.Sha != "" { + labels = append(labels, fmt.Sprintf("%s-sha=%s", githubLabelPrefix, github.Sha)) + } + + return labels +} diff --git a/internal/options/build_test.go b/internal/options/build_test.go new file mode 100644 index 0000000..8e471a0 --- /dev/null +++ b/internal/options/build_test.go @@ -0,0 +1,76 @@ +package options + +import ( + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestGetBuildOptions(t *testing.T) { + _ = os.Setenv("INPUT_PATH", "path") + _ = os.Setenv("INPUT_DOCKERFILE", "dockerfile") + _ = os.Setenv("INPUT_REPOSITORY", "repository") + _ = os.Setenv("INPUT_BUILD_ARGS", "buildarg1=b1,buildarg2=b2") + _ = os.Setenv("INPUT_LABELS", "label1=l1,label2=l2") + _ = os.Setenv("INPUT_ADD_GIT_LABELS", "false") + _ = os.Setenv("INPUT_TARGET", "target") + _ = os.Setenv("INPUT_ALWAYS_PULL", "true") + + o, err := GetBuildOptions() + + assert.NilError(t, err) + assert.DeepEqual(t, Build{ + Path: "path", + Dockerfile: "dockerfile", + Target: "target", + AlwaysPull: true, + BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"}, + Labels: []string{"label1=l1", "label2=l2"}, + }, o) +} + +func TestGetLabels(t *testing.T) { + testCases := []struct { + name string + addGitLabels bool + labels []string + github GitHub + expected []string + }{ + { + name: "no-git-labels", + labels: []string{"label1", "label2"}, + expected: []string{"label1", "label2"}, + }, + { + name: "with-git-labels", + labels: []string{"label1", "label2"}, + addGitLabels: true, + github: GitHub{ + Actor: "actor", + Sha: "sha", + }, + expected: []string{ + "label1", + "label2", + "com.docker.github-actions-actor=actor", + "com.docker.github-actions-sha=sha", + }, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + labels := GetLabels( + Build{ + AddGitLabels: tc.addGitLabels, + Labels: tc.labels, + }, + tc.github, + ) + assert.DeepEqual(t, tc.expected, labels) + }) + } +} diff --git a/internal/options/github.go b/internal/options/github.go new file mode 100644 index 0000000..a984d33 --- /dev/null +++ b/internal/options/github.go @@ -0,0 +1,64 @@ +package options + +import ( + "os" + "strings" + + "github.com/caarlos0/env/v6" +) + +// GitReferenceType is the type of the git ref +type GitReferenceType int + +// Get reference types +const ( + GitRefUnknown GitReferenceType = iota + GitRefHead + GitRefPullRequest + GitRefTag +) + +// GitReference contains the type and name of the git ref +type GitReference struct { + Type GitReferenceType + Name string +} + +func parseGitRef(ref string) GitReference { + if split := strings.SplitN(ref, "/", 3); len(split) == 3 { + name := split[2] + switch split[1] { + case "heads": + return GitReference{GitRefHead, name} + case "pulls": + return GitReference{GitRefPullRequest, name} + case "tags": + return GitReference{GitRefTag, name} + } + } + return GitReference{GitRefUnknown, ""} +} + +// GitHub contains the parsed common github actions environment variables +// See https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables +type GitHub struct { + RunInActions bool `env:"GITHUB_ACTIONS"` + Workflow string `env:"GITHUB_WORKFLOW"` + Action string `env:"GITHUB_ACTION"` + Actor string `env:"GITHUB_ACTOR"` + Repository string `env:"GITHUB_REPOSITORY"` + EventName string `env:"GITHUB_EVENT_NAME"` + Sha string `env:"GITHUB_SHA"` + Reference GitReference +} + +// GetGitHubOptions gets the common github actions environment variables +func GetGitHubOptions() (GitHub, error) { + var github GitHub + err := env.Parse(&github) + if err != nil { + return github, err + } + github.Reference = parseGitRef(os.Getenv("GITHUB_REF")) + return github, nil +} diff --git a/internal/options/github_test.go b/internal/options/github_test.go new file mode 100644 index 0000000..9f10acc --- /dev/null +++ b/internal/options/github_test.go @@ -0,0 +1,83 @@ +package options + +import ( + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestGetGitHubOptions(t *testing.T) { + _ = os.Setenv("GITHUB_ACTIONS", "true") + _ = os.Setenv("GITHUB_WORKFLOW", "workflow") + _ = os.Setenv("GITHUB_ACTION", "action") + _ = os.Setenv("GITHUB_ACTOR", "actor") + _ = os.Setenv("GITHUB_REPOSITORY", "repository") + _ = os.Setenv("GITHUB_EVENT_NAME", "event-name") + _ = os.Setenv("GITHUB_SHA", "sha") + _ = os.Setenv("GITHUB_REF", "refs/heads/master") + + github, err := GetGitHubOptions() + assert.NilError(t, err) + assert.DeepEqual(t, GitHub{ + RunInActions: true, + Workflow: "workflow", + Action: "action", + Actor: "actor", + Repository: "repository", + EventName: "event-name", + Sha: "sha", + Reference: GitReference{ + Type: GitRefHead, + Name: "master", + }, + }, github) +} + +func TestParseGitRef(t *testing.T) { + testCases := []struct { + name string + ref string + expectedType GitReferenceType + expectedName string + }{ + { + name: "master-branch", + ref: "refs/heads/master", + expectedType: GitRefHead, + expectedName: "master", + }, + { + name: "different-branch", + ref: "refs/heads/different", + expectedType: GitRefHead, + expectedName: "different", + }, + { + name: "pull-request", + ref: "refs/pulls/pr1", + expectedType: GitRefPullRequest, + expectedName: "pr1", + }, + { + name: "tag", + ref: "refs/tags/tag1", + expectedType: GitRefTag, + expectedName: "tag1", + }, + } + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + ref := parseGitRef(tc.ref) + assert.DeepEqual(t, GitReference{Type: tc.expectedType, Name: tc.expectedName}, ref) + }) + } +} + +func TestGetGitHubOptionsNotInActions(t *testing.T) { + _ = os.Unsetenv("GITHUB_ACTIONS") + github, err := GetGitHubOptions() + assert.NilError(t, err) + assert.Equal(t, false, github.RunInActions) +} diff --git a/internal/options/helper.go b/internal/options/helper.go new file mode 100644 index 0000000..5f84774 --- /dev/null +++ b/internal/options/helper.go @@ -0,0 +1,14 @@ +package options + +import ( + "os" + "strconv" +) + +func readBoolOption(key string) (bool, error) { + o := os.Getenv(key) + if o == "" { + return false, nil + } + return strconv.ParseBool(o) +} diff --git a/internal/options/login.go b/internal/options/login.go new file mode 100644 index 0000000..f76a0c8 --- /dev/null +++ b/internal/options/login.go @@ -0,0 +1,30 @@ +package options + +import ( + "errors" + + "github.com/caarlos0/env/v6" +) + +// Login contains the parsed login action environment variables +type Login struct { + Username string `env:"INPUT_USERNAME"` + Password string `env:"INPUT_PASSWORD"` +} + +var errLoginVarValidation = errors.New("both username and password must be set to login") + +// GetLoginOptions gets the login action environment variables +func GetLoginOptions() (Login, error) { + var login Login + if err := env.Parse(&login); err != nil { + return login, err + } + + if login.Username != "" && login.Password == "" || + login.Username == "" && login.Password != "" { + return login, errLoginVarValidation + } + + return login, nil +} diff --git a/internal/options/login_test.go b/internal/options/login_test.go new file mode 100644 index 0000000..e18661b --- /dev/null +++ b/internal/options/login_test.go @@ -0,0 +1,36 @@ +package options + +import ( + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestGetLoginOptions(t *testing.T) { + _ = os.Setenv("INPUT_USERNAME", "username") + _ = os.Setenv("INPUT_PASSWORD", "password") + + o, err := GetLoginOptions() + assert.NilError(t, err) + assert.Equal(t, "username", o.Username) + assert.Equal(t, "password", o.Password) +} + +func TestLoginErrorNoPassword(t *testing.T) { + _ = os.Setenv("INPUT_USERNAME", "username") + _ = os.Unsetenv("INPUT_PASSWORD") + + _, err := GetLoginOptions() + + assert.Equal(t, err, errLoginVarValidation) +} + +func TestLoginErrorNoUsername(t *testing.T) { + _ = os.Setenv("INPUT_PASSWORD", "password") + _ = os.Unsetenv("INPUT_USERNAME") + + _, err := GetLoginOptions() + + assert.Equal(t, err, errLoginVarValidation) +} diff --git a/internal/options/push.go b/internal/options/push.go new file mode 100644 index 0000000..8c5d2fd --- /dev/null +++ b/internal/options/push.go @@ -0,0 +1,16 @@ +package options + +import ( + "errors" +) + +var errPushParse = errors.New("push input must be a valid boolean value") + +// ShouldPush returns true if the user has signalled a docker push should be performed +func ShouldPush() (bool, error) { + b, err := readBoolOption("INPUT_PUSH") + if err != nil { + return false, errPushParse + } + return b, nil +} diff --git a/internal/options/push_test.go b/internal/options/push_test.go new file mode 100644 index 0000000..849679f --- /dev/null +++ b/internal/options/push_test.go @@ -0,0 +1,42 @@ +package options + +import ( + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestShouldPush(t *testing.T) { + testCases := []struct { + name string + input string + expected bool + expectedErr error + }{ + { + name: "invalid", + input: "invalid", + expectedErr: errPushParse, + }, + { + name: "true", + input: "true", + expected: true, + }, + { + name: "false", + input: "false", + }, + } + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + _ = os.Setenv("INPUT_PUSH", tc.input) + defer os.Unsetenv("INPUT_PUSH") + should, err := ShouldPush() + assert.Equal(t, tc.expectedErr, err) + assert.Equal(t, tc.expected, should) + }) + } +} diff --git a/internal/options/registry.go b/internal/options/registry.go new file mode 100644 index 0000000..dff7a0f --- /dev/null +++ b/internal/options/registry.go @@ -0,0 +1,8 @@ +package options + +import "os" + +// GetRegistry gets the registry server from the github actions environment variables +func GetRegistry() string { + return os.Getenv("INPUT_REGISTRY") +} diff --git a/internal/options/registry_test.go b/internal/options/registry_test.go new file mode 100644 index 0000000..a35b029 --- /dev/null +++ b/internal/options/registry_test.go @@ -0,0 +1,17 @@ +package options + +import ( + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestGetRegistry(t *testing.T) { + _ = os.Unsetenv("INPUT_REGISTRY") + assert.Equal(t, "", GetRegistry()) + + defer os.Unsetenv("INPUT_REGISTRY") + _ = os.Setenv("INPUT_REGISTRY", "registry") + assert.Equal(t, "registry", GetRegistry()) +} diff --git a/internal/options/tag.go b/internal/options/tag.go new file mode 100644 index 0000000..57a2dc9 --- /dev/null +++ b/internal/options/tag.go @@ -0,0 +1,96 @@ +package options + +import ( + "errors" + "fmt" + "os" + "strings" +) + +var ( + errTagWithRefParse = errors.New("tag_with_ref input must be a valid boolean value") + errTagWithShaParse = errors.New("tag_with_sha input must be a valid boolean value") +) + +func tagWithRef() (bool, error) { + b, err := readBoolOption("INPUT_TAG_WITH_REF") + if err != nil { + return false, errTagWithRefParse + } + return b, nil +} + +func tagWithSha() (bool, error) { + b, err := readBoolOption("INPUT_TAG_WITH_SHA") + if err != nil { + return false, errTagWithShaParse + } + return b, nil +} + +func dockerRepo(github GitHub) string { + if repo := os.Getenv("INPUT_REPOSITORY"); repo != "" { + return repo + } + return strings.ToLower(github.Repository) +} + +func staticTags() []string { + if inputTags := os.Getenv("INPUT_TAGS"); inputTags != "" { + return strings.Split(inputTags, ",") + } + return nil +} + +func toFullTag(registry, repo, tag string) string { + tag = strings.TrimSpace(tag) + if registry != "" { + return fmt.Sprintf("%s/%s:%s", registry, repo, tag) + } + return fmt.Sprintf("%s:%s", repo, tag) +} + +// GetTags gets a list of all tags for including automatic tags from github vars when enabled along with the registry and repository +func GetTags(registry string, github GitHub) ([]string, error) { + repo := dockerRepo(github) + var tags []string + for _, t := range staticTags() { + tags = append(tags, toFullTag(registry, repo, t)) + } + if withRef, err := tagWithRef(); err != nil { + return nil, err + } else if withRef { + switch github.Reference.Type { + case GitRefHead: + if github.Reference.Name == "master" { + tags = append(tags, toFullTag(registry, repo, "latest")) + } else { + tags = appendGitRefTag(tags, registry, repo, github.Reference.Name) + } + case GitRefPullRequest: + tags = appendGitRefTag(tags, registry, repo, fmt.Sprintf("pr-%s", github.Reference.Name)) + + case GitRefTag: + tags = appendGitRefTag(tags, registry, repo, github.Reference.Name) + } + } + if withSha, err := tagWithSha(); err != nil { + return nil, err + } else if withSha { + tags = appendShortGitShaTag(tags, github, registry, repo) + } + return tags, nil +} + +func appendShortGitShaTag(tags []string, github GitHub, registry, repo string) []string { + if len(github.Sha) >= 7 { + tag := fmt.Sprintf("sha-%s", github.Sha[0:7]) + return append(tags, toFullTag(registry, repo, tag)) + } + return tags +} + +func appendGitRefTag(tags []string, registry, repo, refName string) []string { + t := strings.ReplaceAll(refName, "/", "-") + return append(tags, toFullTag(registry, repo, t)) +} diff --git a/internal/options/tag_test.go b/internal/options/tag_test.go new file mode 100644 index 0000000..c463202 --- /dev/null +++ b/internal/options/tag_test.go @@ -0,0 +1,125 @@ +package options + +import ( + "fmt" + "os" + "testing" + + "gotest.tools/v3/assert" +) + +func TestGetTags(t *testing.T) { + testCases := []struct { + name string + tagWithRef bool + tagWithSha bool + tags string + ref GitReference + registry string + expected []string + sha string + }{ + { + name: "no-standard-tags", + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2"}, + ref: GitReference{GitRefHead, "master"}, + }, + { + name: "with-registry", + tags: "tag1,tag2", + expected: []string{"registry/my/repo:tag1", "registry/my/repo:tag2"}, + registry: "registry", + ref: GitReference{GitRefHead, "master"}, + }, + { + name: "unknown-ref-type", + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2"}, + tagWithRef: true, + ref: GitReference{GitRefUnknown, "master"}, + }, + { + name: "master-branch", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:latest"}, + ref: GitReference{GitRefHead, "master"}, + }, + { + name: "different-branch", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:branch-name"}, + ref: GitReference{GitRefHead, "branch-name"}, + }, + { + name: "pull-request", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:pr-name"}, + ref: GitReference{GitRefPullRequest, "name"}, + }, + { + name: "tag", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:v1.0"}, + ref: GitReference{GitRefTag, "v1.0"}, + }, + { + name: "master-branch-with-sha", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:latest"}, + ref: GitReference{GitRefHead, "master"}, + sha: "1234567890", + }, + { + name: "pull-request-with-sha", + tagWithRef: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:pr-name"}, + ref: GitReference{GitRefPullRequest, "name"}, + sha: "1234567890", + }, + { + name: "tag-with-sha", + tagWithSha: true, + tags: "tag1,tag2", + expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:sha-1234567"}, + sha: "1234567890", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + defer os.Unsetenv("INPUT_TAGS") + defer os.Unsetenv("INPUT_REPOSITORY") + defer os.Unsetenv("INPUT_TAG_WITH_REF") + defer os.Unsetenv("INPUT_TAG_WITH_SHA") + _ = os.Setenv("INPUT_TAGS", tc.tags) + _ = os.Setenv("INPUT_REPOSITORY", "my/repo") + _ = os.Setenv("INPUT_TAG_WITH_REF", fmt.Sprint(tc.tagWithRef)) + _ = os.Setenv("INPUT_TAG_WITH_SHA", fmt.Sprint(tc.tagWithSha)) + + tags, err := GetTags( + tc.registry, + GitHub{Reference: tc.ref, Sha: tc.sha}, + ) + assert.NilError(t, err) + assert.DeepEqual(t, tc.expected, tags) + }) + } +} + +func TestGetTagsWithGitHubRepo(t *testing.T) { + defer os.Unsetenv("INPUT_TAGS") + _ = os.Setenv("INPUT_TAGS", "tag1") + + github := GitHub{Repository: "My/Repo"} + tags, err := GetTags("", github) + assert.NilError(t, err) + assert.DeepEqual(t, []string{"my/repo:tag1"}, tags) +}