ci: lint dagger using dagger

- `Makefile` now uses `dagger do lint` to lint
- GHA uses dagger to lint

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-04-04 18:21:16 -07:00
parent 7d2f279c59
commit 162949d87d
8 changed files with 116 additions and 134 deletions

View File

@ -45,41 +45,21 @@ jobs:
- name: "Expose GitHub Runtime" - name: "Expose GitHub Runtime"
uses: crazy-max/ghaction-github-runtime@v1 uses: crazy-max/ghaction-github-runtime@v1
- name: Prepare dagger # - name: "Set up dagger from source"
run: | # run: |
make dagger # make dagger
cp ./cmd/dagger/dagger /usr/local/bin # cp ./cmd/dagger/dagger /usr/local/bin
- name: "Set up dagger"
uses: dagger/dagger-for-github@v2
with:
install-only: true
- name: Build - name: Build
env: env:
DAGGER_LOG_LEVEL: "debug"
DAGGER_LOG_FORMAT: "plain"
DAGGER_CACHE_TO: "type=gha,mode=max,scope=dagger-ci-build" DAGGER_CACHE_TO: "type=gha,mode=max,scope=dagger-ci-build"
DAGGER_CACHE_FROM: "type=gha,scope=dagger-ci-build" DAGGER_CACHE_FROM: "type=gha,scope=dagger-ci-build"
run: | run: |
dagger do build dagger do build
lint:
name: "Lint"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: "Setup Go"
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: "Expose GitHub Runtime"
uses: crazy-max/ghaction-github-runtime@v1
- name: Prepare dagger
run: |
make dagger
cp ./cmd/dagger/dagger /usr/local/bin
- name: Lint
env:
DAGGER_CACHE_TO: "type=gha,mode=max,scope=dagger-ci-lint"
DAGGER_CACHE_FROM: "type=gha,scope=dagger-ci-lint"
run: |
dagger do lint

View File

@ -4,27 +4,27 @@ on:
push: push:
branches: [main] branches: [main]
paths: paths:
- '**.go' - "**.go"
- '**.sh' - "**.sh"
- '**.bash' - "**.bash"
- '**.cue' - "**.cue"
- 'docs/**' - "docs/**"
- '.golangci.yml' - ".golangci.yml"
- 'Makefile' - "Makefile"
- 'README.md' - "README.md"
- '.github/workflows/lint.yml' - ".github/workflows/lint.yml"
pull_request: pull_request:
branches: [main] branches: [main]
paths: paths:
- '**.go' - "**.go"
- '**.sh' - "**.sh"
- '**.bash' - "**.bash"
- '**.cue' - "**.cue"
- 'docs/**' - "docs/**"
- '.golangci.yml' - ".golangci.yml"
- 'Makefile' - "Makefile"
- 'README.md' - "README.md"
- '.github/workflows/lint.yml' - ".github/workflows/lint.yml"
jobs: jobs:
lint: lint:
@ -41,35 +41,24 @@ jobs:
with: with:
go-version: 1.16 go-version: 1.16
- name: "Install deps" - name: "Expose GitHub Runtime"
run: | uses: crazy-max/ghaction-github-runtime@v1
# Cue
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
echo "Installing cue version $CUE_VERSION"
curl -L https://github.com/cue-lang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL} | sudo tar zxf - -C /usr/local/bin
- name: "Lint go" # - name: "Set up dagger from source"
uses: golangci/golangci-lint-action@v2 # run: |
# make dagger
# cp ./cmd/dagger/dagger /usr/local/bin
- name: "Set up dagger"
uses: dagger/dagger-for-github@v2
with: with:
version: v1.45 install-only: true
skip-go-installation: true
args: --timeout=3m
- name: "Lint shell" - name: Lint
env:
DAGGER_LOG_LEVEL: "debug"
DAGGER_LOG_FORMAT: "plain"
DAGGER_CACHE_TO: "type=gha,mode=max,scope=dagger-ci-lint"
DAGGER_CACHE_FROM: "type=gha,scope=dagger-ci-lint"
run: | run: |
make shellcheck dagger do lint
- name: "Lint CUE"
run: |
make cuelint
- name: "Lint docs"
run: |
make docslint
- name: "Lint markdown"
uses: avto-dev/markdown-lint@v1
with:
config: ".markdownlint.yaml"
args: ./docs README.md

View File

@ -33,23 +33,24 @@ test: # Run all tests
go test -race -v ./... go test -race -v ./...
.PHONY: golint .PHONY: golint
golint: # Go lint golint: dagger # Go lint
golangci-lint run --timeout 3m ./cmd/dagger/dagger do lint go
.PHONY: cuefmt .PHONY: cuefmt
cuefmt: # Format all cue files cuefmt: # Format all cue files
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
.PHONY: cuelint .PHONY: cuelint
cuelint: cuefmt # Lint and format all cue files cuelint: dagger # Lint all cue files
@test -z "$$(git status -s . | grep -e "^ M" | grep "\.cue" | cut -d ' ' -f3 | tee /dev/stderr)" ./cmd/dagger/dagger do lint cue
.PHONY: shellcheck .PHONY: shellcheck
shellcheck: # Run shellcheck shellcheck: dagger # Run shellcheck
shellcheck $$(find . -type f \( -iname \*.bats -o -iname \*.bash -o -iname \*.sh \) -not -path "*/node_modules/*" -not -path "*/bats-*/*") ./cmd/dagger/dagger do lint shell
.PHONY: lint .PHONY: lint
lint: shellcheck cuelint golint docslint mdlint # Lint everything lint: dagger # Lint everything
./cmd/dagger/dagger do lint
.PHONY: integration .PHONY: integration
integration: core-integration universe-test doc-test # Run all integration tests integration: core-integration universe-test doc-test # Run all integration tests
@ -78,10 +79,6 @@ doc-test: dagger-debug # Test docs
docs: dagger # Generate docs docs: dagger # Generate docs
DAGGER_TELEMETRY_DISABLE=1 ./cmd/dagger/dagger doc --output ./docs/reference --format md DAGGER_TELEMETRY_DISABLE=1 ./cmd/dagger/dagger doc --output ./docs/reference --format md
.PHONY: docslint
docslint: docs # Generate & lint docs
@test -z "$$(git status -s . | grep -e "^ M" | grep docs/reference | cut -d ' ' -f3 | tee /dev/stderr)"
.PHONY: mdlint .PHONY: mdlint
mdlint: # Markdown lint for web mdlint: # Markdown lint for web
@markdownlint ./docs README.md @markdownlint ./docs README.md

46
ci.cue
View File

@ -5,12 +5,12 @@ import (
"universe.dagger.io/bash" "universe.dagger.io/bash"
"universe.dagger.io/alpine" "universe.dagger.io/alpine"
"universe.dagger.io/docker"
"universe.dagger.io/go" "universe.dagger.io/go"
"github.com/dagger/dagger/ci/golangci" "github.com/dagger/dagger/ci/golangci"
"github.com/dagger/dagger/ci/shellcheck" "github.com/dagger/dagger/ci/shellcheck"
"github.com/dagger/dagger/ci/markdownlint" "github.com/dagger/dagger/ci/markdownlint"
"github.com/dagger/dagger/ci/cue"
) )
dagger.#Plan & { dagger.#Plan & {
@ -102,48 +102,8 @@ dagger.#Plan & {
files: ["./docs", "README.md"] files: ["./docs", "README.md"]
} }
cue: docker.#Build & { "cue": cue.#Lint & {
// FIXME: spin off into its own package? source: _source
steps: [
alpine.#Build & {
packages: bash: _
packages: curl: _
packages: git: _
},
docker.#Copy & {
contents: _source
source: "go.mod"
dest: "go.mod"
},
// Install CUE
bash.#Run & {
script: contents: #"""
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
echo "Installing cue version $CUE_VERSION"
curl -L "https://github.com/cue-lang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL}" | tar zxf - -C /usr/local/bin
cue version
"""#
},
// CACHE: copy only *.cue files
docker.#Copy & {
contents: _source
include: ["*.cue"]
dest: "/cue"
},
// LINT
bash.#Run & {
workdir: "/cue"
script: contents: #"""
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -t -n 1 -P 8 cue fmt -s
test -z "$(git status -s . | grep -e "^ M" | grep "\.cue" | cut -d ' ' -f3 | tee /dev/stderr)"
"""#
},
]
} }
} }
} }

56
ci/cue/lint.cue Normal file
View File

@ -0,0 +1,56 @@
package cue
import (
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
"universe.dagger.io/bash"
)
#Lint: {
source: dagger.#FS
docker.#Build & {
steps: [
alpine.#Build & {
packages: bash: _
packages: curl: _
packages: git: _
},
docker.#Copy & {
contents: source
"source": "go.mod"
dest: "go.mod"
},
// Install CUE
bash.#Run & {
script: contents: #"""
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
echo "Installing cue version $CUE_VERSION"
curl -L "https://github.com/cue-lang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL}" | tar zxf - -C /usr/local/bin
cue version
"""#
},
// CACHE: copy only *.cue files
docker.#Copy & {
contents: source
include: ["*.cue"]
dest: "/cue"
},
// LINT
bash.#Run & {
workdir: "/cue"
script: contents: #"""
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -t -n 1 -P 8 cue fmt -s
test -z "$(git status -s . | grep -e "^ M" | grep "\.cue" | cut -d ' ' -f3 | tee /dev/stderr)"
"""#
},
]
}
}

View File

@ -22,7 +22,7 @@ import (
source: "golangci/golangci-lint:v\(version)" source: "golangci/golangci-lint:v\(version)"
} }
container: go.#Container & { go.#Container & {
"source": source "source": source
input: _image.output input: _image.output
command: { command: {

View File

@ -20,7 +20,7 @@ import (
source: "tmknom/markdownlint:\(version)" source: "tmknom/markdownlint:\(version)"
} }
container: docker.#Run & { docker.#Run & {
input: _image.output input: _image.output
mounts: "source": { mounts: "source": {
dest: "/src" dest: "/src"

View File

@ -17,7 +17,7 @@ import (
source: "koalaman/shellcheck-alpine:v\(version)" source: "koalaman/shellcheck-alpine:v\(version)"
} }
container: docker.#Run & { docker.#Run & {
input: _image.output input: _image.output
mounts: "source": { mounts: "source": {
dest: "/src" dest: "/src"