Skip to content

Dagger support #32

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.1.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.0/direnvrc" "sha256-FAT2R9yYvVg516v3LiogjIc8YfsbWbMM/itqWsm5xTA="
fi
use flake
41 changes: 41 additions & 0 deletions .github/workflows/dagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Dagger

on:
push:
branches:
- master
pull_request:

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.14', '1.15', '1.16', '1.17', '1.18']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Dagger
uses: dagger/dagger-for-github@v3
with:
cmds: |
project update
do check test go ${{ matrix.go }}

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Dagger
uses: dagger/dagger-for-github@v3
with:
cmds: |
project update
do check lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.direnv/
/tmp/
/vendor/

Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3'

tasks:
check:
cmds:
- dagger do check

lint:
cmds:
- dagger do check lint

fmt:
cmds:
- golangci-lint run --fix
74 changes: 74 additions & 0 deletions ci/codecov/image.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package codecov

import (
"universe.dagger.io/docker"
// "universe.dagger.io/alpine"
"universe.dagger.io/bash"
)

// Build a codecov base image
#Image: {
_packages: [pkgName=string]: {
// NOTE(samalba, gh issue #1532):
// it's not recommended to pin the version as it is already pinned by the major Alpine version
// version pinning is for future use (as soon as we support custom repositories like `community`,
// `testing` or `edge`)
version: string | *""
}
_packages: {
bash: _
curl: _
git: _
gnupg: _
coreutils: _
"perl-utils": _
}
docker.#Build & {
steps: [
// alpine.#Build & {
// packages: {
// bash: _
// curl: _
// gnupg: _
// coreutils: _
// "perl-utils": _
// }
// },
docker.#Pull & {
source: "index.docker.io/alpine:3.15.0@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300"
},
for pkgName, pkg in _packages {
docker.#Run & {
command: {
name: "apk"
args: ["add", "\(pkgName)\(pkg.version)"]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
bash.#Run & {
script: contents: """
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import

curl -Os https://uploader.codecov.io/latest/alpine/codecov

curl -Os https://uploader.codecov.io/latest/alpine/codecov.SHA256SUM

curl -Os https://uploader.codecov.io/latest/alpine/codecov.SHA256SUM.sig

gpgv codecov.SHA256SUM.sig codecov.SHA256SUM

shasum -a 256 -c codecov.SHA256SUM

chmod +x codecov

mv codecov /usr/local/bin
rm codecov.SHA256SUM codecov.SHA256SUM.sig
"""
},
]
}
}
11 changes: 11 additions & 0 deletions ci/codecov/test/image.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package codecov

import (
"dagger.io/dagger"

"emperror.dev/errors/ci/codecov"
)

dagger.#Plan & {
actions: test: codecov.#Image & {}
}
52 changes: 52 additions & 0 deletions ci/codecov/upload.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package codecov

import (
"dagger.io/dagger"

"universe.dagger.io/docker"
)

#Upload: {
// Source code
source: dagger.#FS

// Coverage files
file: string

// Codecov token (required for local runs and private repos)
token?: dagger.#Secret

// Don't upload files to Codecov
dryRun: bool | *false

_image: #Image

_sourcePath: "/src"

docker.#Run & {
input: *_image.output | docker.#Image
command: {
name: "codecov"
flags: {
"--file": file
"--verbose": true

if dryRun {
"--dryRun": true
}
}
}
env: {
if token != _|_ {
CODECOV_TOKEN: token
}
}
workdir: _sourcePath
mounts: {
"source": {
dest: _sourcePath
contents: source
}
}
}
}
3 changes: 3 additions & 0 deletions cue.mod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/gen/
/pkg/
/tmp/
1 change: 1 addition & 0 deletions cue.mod/dagger.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/sagikazarmark/dagger main
1 change: 1 addition & 0 deletions cue.mod/dagger.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/sagikazarmark/dagger h1:ekTs7tQbia01P9hMcMFSmA5TMFybb5F15Nlx8vYwU2g=
1 change: 1 addition & 0 deletions cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module: "emperror.dev/errors"
124 changes: 124 additions & 0 deletions dagger.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package main

import (
"dagger.io/dagger"
"dagger.io/dagger/core"

"universe.dagger.io/go"

"github.com/sagikazarmark/dagger/go/golangci"
"emperror.dev/errors/ci/codecov"
)

dagger.#Plan & {
client: filesystem: ".": read: exclude: [
".github",
"bin",
"build",
"tmp",
]
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
client: env: {
CI: string | *""
GITHUB_ACTIONS: string | *""
GITHUB_ACTION: string | *""
GITHUB_HEAD_REF: string | *""
GITHUB_REF: string | *""
GITHUB_REPOSITORY: string | *""
GITHUB_RUN_ID: string | *""
GITHUB_SERVER_URL: string | *""
GITHUB_SHA: string | *""
GITHUB_WORKFLOW: string | *""
CODECOV_TOKEN?: dagger.#Secret
}

actions: {
_source: client.filesystem["."].read.contents

check: {
test: {
"go": {
"1.14": _
"1.15": _
"1.16": _
"1.17": _
"1.18": _

[v=string]: {
_test: go.#Test & {
source: _source
name: "go_test_\(v)" // necessary to keep cache for different versions separate
package: "./..."

_image: go.#Image & {
version: v
}

input: _image.output
command: flags: {
"-race": true
"-covermode": "atomic"
"-coverprofile": "/coverage.out"
}

export: files: "/coverage.out": _
}

_coverage: codecov.#Upload & {
_write: core.#WriteFile & {
input: _source
path: "/coverage.out"
contents: _test.export.files."/coverage.out"
}

source: _write.output
file: "/src/coverage.out"

// Fixes https://github.com/dagger/dagger/issues/2680
// _env: client.env

// if _env.CODECOV_TOKEN != _|_ {
// token: _env.CODECOV_TOKEN
// }

// Fixes https://github.com/dagger/dagger/issues/2680
_token: client.env.CODECOV_TOKEN

if client.env.CODECOV_TOKEN != _|_ {
token: client.env.CODECOV_TOKEN
}

dryRun: client.env.CI != "true"

// token: client.env.CODECOV_TOKEN

env: {
// if client.env.CODECOV_TOKEN != _|_ {
// CODECOV_TOKEN: client.env.CODECOV_TOKEN
// }
GITHUB_ACTIONS: client.env.GITHUB_ACTIONS
GITHUB_ACTION: client.env.GITHUB_ACTION
GITHUB_HEAD_REF: client.env.GITHUB_HEAD_REF
GITHUB_REF: client.env.GITHUB_REF
GITHUB_REPOSITORY: client.env.GITHUB_REPOSITORY
GITHUB_RUN_ID: client.env.GITHUB_RUN_ID
GITHUB_SERVER_URL: client.env.GITHUB_SERVER_URL
GITHUB_SHA: client.env.GITHUB_SHA
GITHUB_WORKFLOW: client.env.GITHUB_WORKFLOW
}
}

export: files: "/coverage.out": _test.export.files."/coverage.out"
}
}
}

lint: {
"golangci": golangci.#Lint & {
source: _source
version: "1.46"
}
}
}
}
}
Loading