Skip to content

Commit

Permalink
Merge pull request #224 from crazy-max/ci-test
Browse files Browse the repository at this point in the history
Test stage and ci jobs
  • Loading branch information
thaJeztah committed Aug 20, 2022
2 parents 8fee112 + 6f1a1a1 commit ab7fd12
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
66 changes: 65 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -11,10 +11,71 @@ on:

env:
DESTDIR: ./bin
GO_VERSION: 1.16.7

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- macOS-11
- windows-2022
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
-
name: Install deps
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
sudo apt-get update
sudo apt-get install -y dbus-x11 gnome-keyring libsecret-1-dev pass
-
name: Test
run: |
go test -short -v -coverprofile=./coverage.txt -covermode=atomic ./...
go tool cover -func=./coverage.txt
shell: bash
-
name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt

test-sandboxed:
runs-on: ubuntu-20.04
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Test
uses: docker/bake-action@v2
with:
targets: test
set: |
*.cache-from=type=gha,scope=test
*.cache-to=type=gha,scope=test,mode=max
-
name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ${{ env.DESTDIR }}//coverage.txt

build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
-
name: Checkout
Expand All @@ -30,6 +91,9 @@ jobs:
uses: docker/bake-action@v2
with:
targets: binaries
set: |
*.cache-from=type=gha,scope=build
*.cache-to=type=gha,scope=build,mode=max
-
name: Move artifacts
run: |
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Expand Up @@ -30,6 +30,18 @@ FROM gobase AS base
ARG TARGETPLATFORM
RUN xx-apk add musl-dev gcc libsecret-dev pass

FROM base AS test
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod <<EOT
set -e
xx-go test -short -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./...
xx-go tool cover -func=/tmp/coverage.txt
EOT

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage.txt /coverage.txt

FROM base AS build-linux
ARG TARGETOS
ARG TARGETARCH
Expand Down
22 changes: 20 additions & 2 deletions README.md
@@ -1,3 +1,9 @@
[![GitHub release](https://img.shields.io/github/release/docker/docker-credential-helpers.svg?style=flat-square)](https://github.com/docker/docker-credential-helpers/releases/latest)
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square&logo=go&logoColor=white)](https://pkg.go.dev/github.com/docker/docker-credential-helpers)
[![Build Status](https://img.shields.io/github/workflow/status/docker/docker-credential-helpers/build?label=build&logo=github&style=flat-square)](https://github.com/docker/docker-credential-helpers/actions?query=workflow%3Abuild)
[![Codecov](https://img.shields.io/codecov/c/github/docker/docker-credential-helpers?logo=codecov&style=flat-square)](https://codecov.io/gh/docker/docker-credential-helpers)
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/docker-credential-helpers?style=flat-square)](https://goreportcard.com/report/github.com/docker/docker-credential-helpers)

## Introduction

docker-credential-helpers is a suite of programs to use native stores to keep Docker credentials safe.
Expand All @@ -6,9 +12,21 @@ docker-credential-helpers is a suite of programs to use native stores to keep Do

Go to the [Releases](https://github.com/docker/docker-credential-helpers/releases) page and download the binary that works better for you. Put that binary in your `$PATH`, so Docker can find it.

### Building from scratch
## Building

You can build the credential helpers using Docker:

```shell
# create builder
$ docker buildx create --use
# build credential helpers from remote repository and output to ./bin/build
$ docker buildx bake "https://github.com/docker/docker-credential-helpers.git"
# or from local source
$ git clone https://github.com/docker/docker-credential-helpers.git
$ docker buildx bake
```

The programs in this repository are written with the Go programming language. These instructions assume that you have previous knowledge about the language and you have it installed in your machine.
Or if the toolchain is already installed on your machine:

1 - Download the source and put it in your `$GOPATH` with `go get`.

Expand Down
16 changes: 14 additions & 2 deletions docker-bake.hcl
@@ -1,8 +1,14 @@
variable "GO_VERSION" {
default = "1.16.7"
}

# Defines the output folder
variable "DESTDIR" {
default = "./bin"
default = ""
}
function "bindir" {
params = [defaultdir]
result = DESTDIR != "" ? DESTDIR : "./bin/${defaultdir}"
}

target "_common" {
Expand All @@ -15,10 +21,16 @@ group "default" {
targets = ["binaries"]
}

target "test" {
inherits = ["_common"]
target = "test-coverage"
output = [bindir("coverage")]
}

target "binaries" {
inherits = ["_common"]
target = "binaries"
output = [DESTDIR]
output = [bindir("build")]
platforms = [
"darwin/amd64",
"darwin/arm64",
Expand Down

0 comments on commit ab7fd12

Please sign in to comment.