ci: refactor build tools and ci setup (#23)

This commit is contained in:
Robert Kaussow 2022-04-25 12:56:05 +02:00 committed by GitHub
parent b44e83cdfe
commit dd498d9592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 261 additions and 283 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
*
!dist/

View File

@ -1,6 +1,5 @@
local PipelineTest = {
kind: 'pipeline',
image_pull_secrets: ['docker_config'],
name: 'test',
platform: {
os: 'linux',
@ -8,14 +7,14 @@ local PipelineTest = {
},
steps: [
{
name: 'staticcheck',
name: 'deps',
image: 'golang:1.18',
commands: [
'go run honnef.co/go/tools/cmd/staticcheck ./...',
'make deps',
],
volumes: [
{
name: 'gopath',
name: 'godeps',
path: '/go',
},
],
@ -24,24 +23,11 @@ local PipelineTest = {
name: 'lint',
image: 'golang:1.18',
commands: [
'go run golang.org/x/lint/golint -set_exit_status ./...',
'make lint',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'vet',
image: 'golang:1.18',
commands: [
'go vet ./...',
],
volumes: [
{
name: 'gopath',
name: 'godeps',
path: '/go',
},
],
@ -50,11 +36,11 @@ local PipelineTest = {
name: 'test',
image: 'golang:1.18',
commands: [
'go test -cover ./...',
'make test',
],
volumes: [
{
name: 'gopath',
name: 'godeps',
path: '/go',
},
],
@ -62,7 +48,7 @@ local PipelineTest = {
],
volumes: [
{
name: 'gopath',
name: 'godeps',
temp: {},
},
],
@ -74,7 +60,6 @@ local PipelineTest = {
local PipelineBuildBinaries = {
kind: 'pipeline',
image_pull_secrets: ['docker_config'],
name: 'build-binaries',
platform: {
os: 'linux',
@ -85,34 +70,14 @@ local PipelineBuildBinaries = {
name: 'build',
image: 'techknowlogick/xgo:go-1.18.x',
commands: [
'[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}',
'mkdir -p release/',
"xgo -ldflags \"-s -w -X main.version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm-7,linux/arm64' -out drone-yaml .",
'mv /build/* /drone/src/release/',
'ls -l /drone/src/release/',
'make release',
],
},
{
name: 'executable',
image: 'alpine',
commands: [
'$(find release/ -executable -type f | grep drone-yaml-linux-amd64) --help',
],
},
{
name: 'compress',
image: 'alpine',
commands: [
'apk add upx',
'find release/ -maxdepth 1 -executable -type f -exec upx {} \\;',
'ls -lh release/',
],
},
{
name: 'checksum',
image: 'alpine',
commands: [
'cd release/ && sha256sum * > sha256sum.txt',
'$(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help',
],
},
{
@ -139,7 +104,7 @@ local PipelineBuildBinaries = {
api_key: {
from_secret: 'github_token',
},
files: ['release/*'],
files: ['dist/*'],
title: '${DRONE_TAG}',
note: 'CHANGELOG.md',
},
@ -160,7 +125,6 @@ local PipelineBuildBinaries = {
local PipelineBuildContainer(arch='amd64') = {
kind: 'pipeline',
image_pull_secrets: ['docker_config'],
name: 'build-container-' + arch,
platform: {
os: 'linux',
@ -171,20 +135,16 @@ local PipelineBuildContainer(arch='amd64') = {
name: 'build',
image: 'golang:1.18',
commands: [
'[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}',
'go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/' + arch + '/drone-yaml',
'make build',
],
},
{
name: 'dryrun',
image: 'thegeeklab/drone-docker:19',
settings: {
config: { from_secret: 'docker_config' },
dry_run: true,
dockerfile: 'docker/Dockerfile.' + arch,
repo: 'thegeeklab/${DRONE_REPO_NAME}',
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
},
depends_on: ['build'],
when: {
@ -195,7 +155,6 @@ local PipelineBuildContainer(arch='amd64') = {
name: 'publish-dockerhub',
image: 'thegeeklab/drone-docker:19',
settings: {
config: { from_secret: 'docker_config' },
auto_tag: true,
auto_tag_suffix: arch,
dockerfile: 'docker/Dockerfile.' + arch,
@ -212,7 +171,6 @@ local PipelineBuildContainer(arch='amd64') = {
name: 'publish-quay',
image: 'thegeeklab/drone-docker:19',
settings: {
config: { from_secret: 'docker_config' },
auto_tag: true,
auto_tag_suffix: arch,
dockerfile: 'docker/Dockerfile.' + arch,
@ -292,7 +250,6 @@ local PipelineDocs = {
local PipelineNotifications = {
kind: 'pipeline',
image_pull_secrets: ['docker_config'],
name: 'notifications',
platform: {
os: 'linux',

View File

@ -7,45 +7,34 @@ platform:
arch: amd64
steps:
- name: staticcheck
- name: deps
image: golang:1.18
commands:
- go run honnef.co/go/tools/cmd/staticcheck ./...
- make deps
volumes:
- name: gopath
- name: godeps
path: /go
- name: lint
image: golang:1.18
commands:
- go run golang.org/x/lint/golint -set_exit_status ./...
- make lint
volumes:
- name: gopath
path: /go
- name: vet
image: golang:1.18
commands:
- go vet ./...
volumes:
- name: gopath
- name: godeps
path: /go
- name: test
image: golang:1.18
commands:
- go test -cover ./...
- make test
volumes:
- name: gopath
- name: godeps
path: /go
volumes:
- name: gopath
- name: godeps
temp: {}
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -64,28 +53,12 @@ steps:
- name: build
image: techknowlogick/xgo:go-1.18.x
commands:
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
- mkdir -p release/
- xgo -ldflags "-s -w -X main.version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm-7,linux/arm64' -out drone-yaml .
- mv /build/* /drone/src/release/
- ls -l /drone/src/release/
- make release
- name: executable
image: alpine
commands:
- $(find release/ -executable -type f | grep drone-yaml-linux-amd64) --help
- name: compress
image: alpine
commands:
- apk add upx
- find release/ -maxdepth 1 -executable -type f -exec upx {} \;
- ls -lh release/
- name: checksum
image: alpine
commands:
- cd release/ && sha256sum * > sha256sum.txt
- $(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help
- name: changelog-generate
image: thegeeklab/git-chglog
@ -105,7 +78,7 @@ steps:
api_key:
from_secret: github_token
files:
- release/*
- dist/*
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
@ -113,9 +86,6 @@ steps:
ref:
- refs/tags/**
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -137,21 +107,14 @@ steps:
- name: build
image: golang:1.18
commands:
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
- go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/amd64/drone-yaml
- make build
- name: dryrun
image: thegeeklab/drone-docker:19
settings:
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.amd64
dry_run: true
password:
from_secret: docker_password
repo: thegeeklab/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/pull/**
@ -163,8 +126,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: amd64
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.amd64
password:
from_secret: docker_password
@ -183,8 +144,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: amd64
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.amd64
password:
from_secret: quay_password
@ -199,9 +158,6 @@ steps:
depends_on:
- dryrun
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -223,21 +179,14 @@ steps:
- name: build
image: golang:1.18
commands:
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
- go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/arm64/drone-yaml
- make build
- name: dryrun
image: thegeeklab/drone-docker:19
settings:
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm64
dry_run: true
password:
from_secret: docker_password
repo: thegeeklab/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/pull/**
@ -249,8 +198,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: arm64
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm64
password:
from_secret: docker_password
@ -269,8 +216,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: arm64
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm64
password:
from_secret: quay_password
@ -285,9 +230,6 @@ steps:
depends_on:
- dryrun
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -309,21 +251,14 @@ steps:
- name: build
image: golang:1.18
commands:
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
- go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/arm/drone-yaml
- make build
- name: dryrun
image: thegeeklab/drone-docker:19
settings:
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm
dry_run: true
password:
from_secret: docker_password
repo: thegeeklab/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/pull/**
@ -335,8 +270,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: arm
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm
password:
from_secret: docker_password
@ -355,8 +288,6 @@ steps:
settings:
auto_tag: true
auto_tag_suffix: arm
config:
from_secret: docker_config
dockerfile: docker/Dockerfile.arm
password:
from_secret: quay_password
@ -371,9 +302,6 @@ steps:
depends_on:
- dryrun
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -513,9 +441,6 @@ steps:
- success
- failure
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
@ -529,6 +454,6 @@ depends_on:
---
kind: signature
hmac: 25fac6a51457126375ef3ab41ceeaa46bebe5160da848528d47ee0ae395db561
hmac: 314420aab55fd338afc0a5edf1255fe25d017742c3ee5dd1a47833f64c408f00
...

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/dist/
/release/
/drone-yaml*

31
.golangci.yml Normal file
View File

@ -0,0 +1,31 @@
linters:
enable:
- gosimple
- deadcode
- typecheck
- govet
- errcheck
- staticcheck
- unused
- structcheck
- varcheck
- dupl
- gofmt
- misspell
- gocritic
- bidichk
- ineffassign
- revive
- gofumpt
- depguard
enable-all: false
disable-all: true
fast: false
run:
timeout: 3m
linters-settings:
gofumpt:
extra-rules: true
lang-version: "1.18"

96
Makefile Normal file
View File

@ -0,0 +1,96 @@
# renovate: datasource=github-releases depName=mvdan/gofumpt
GOFUMPT_PACKAGE_VERSION := v0.3.1
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.45.2
EXECUTABLE := drone-yaml
DIST := dist
DIST_DIRS := $(DIST)
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
GO ?= go
CWD ?= $(shell pwd)
PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GENERATE ?=
XGO_VERSION := go-1.18.x
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
TAGS ?= netgo
ifndef VERSION
ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
else
VERSION ?= $(shell git rev-parse --short HEAD)
endif
endif
ifndef DATE
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
endif
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
.PHONY: all
all: clean build
.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf $(DIST_DIRS)
.PHONY: fmt
fmt:
$(GO) run $(GOFUMPT_PACKAGE) -extra -w $(SOURCES)
.PHONY: golangci-lint
golangci-lint:
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
.PHONY: lint
lint: golangci-lint
.PHONY: generate
generate:
$(GO) generate $(GENERATE)
.PHONY: test
test:
$(GO) test -v -coverprofile coverage.out $(PACKAGES)
.PHONY: build
build: $(DIST)/$(EXECUTABLE)
$(DIST)/$(EXECUTABLE): $(SOURCES)
$(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
$(DIST_DIRS):
mkdir -p $(DIST_DIRS)
.PHONY: xgo
xgo: | $(DIST_DIRS)
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
cp /build/* $(CWD)/$(DIST)
ls -l $(CWD)/$(DIST)
.PHONY: checksum
checksum:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
ls -l $(CWD)/$(DIST)
.PHONY: release
release: xgo checksum
.PHONY: deps
deps:
$(GO) mod download
$(GO) install $(GOFUMPT_PACKAGE)
$(GO) install $(GOLANGCI_LINT_PACKAGE)
$(GO) install $(XGO_PACKAGE)

View File

@ -27,7 +27,7 @@ export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go build -v -a -tags netgo -o release/linux/amd64/drone-yaml
make build
```
Build the Docker image with the following command:

View File

@ -46,7 +46,7 @@ func runFormat() error {
pretty.Print(b, m)
if *formatSave {
return ioutil.WriteFile(f.Name(), b.Bytes(), 0644)
return ioutil.WriteFile(f.Name(), b.Bytes(), 0o644)
}
_, err = io.Copy(os.Stderr, b)
return err

View File

@ -7,5 +7,5 @@ LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-yaml"
ADD release/amd64/drone-yaml /bin/
ADD dist/drone-yaml /bin/
ENTRYPOINT [ "/bin/drone-yaml" ]

View File

@ -7,5 +7,5 @@ LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-yaml"
ADD release/arm/drone-yaml /bin/
ADD dist/drone-yaml /bin/
ENTRYPOINT [ "/bin/drone-yaml" ]

View File

@ -7,5 +7,5 @@ LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-yaml"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-yaml"
ADD release/arm64/drone-yaml /bin/
ADD dist/drone-yaml /bin/
ENTRYPOINT [ "/bin/drone-yaml" ]

7
go.mod
View File

@ -6,22 +6,15 @@ require (
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/docker/go-units v0.4.0
github.com/google/go-cmp v0.5.7
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.3.0
)
require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20220328175248-053ad81199eb // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)

25
go.sum
View File

@ -1,5 +1,3 @@
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
@ -23,27 +21,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp/typeparams v0.0.0-20220328175248-053ad81199eb h1:fP6C8Xutcp5AlakmT/SkQot0pMicROAsEX7OfNPuG10=
golang.org/x/exp/typeparams v0.0.0-20220328175248-053ad81199eb/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a h1:ofrrl6c6NG5/IOSx/R1cyiQxxjqlur0h/TvbUhkH0II=
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -55,5 +32,3 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
honnef.co/go/tools v0.3.0 h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
honnef.co/go/tools v0.3.0/go.mod h1:vlRD9XErLMGT+mDuofSr0mMMquscM/1nQqtRSsh6m70=

View File

@ -1,8 +0,0 @@
// +build tools
package tools
import (
_ "golang.org/x/lint/golint"
_ "honnef.co/go/tools/cmd/staticcheck"
)

View File

@ -67,7 +67,7 @@ func (c *Condition) Excludes(v string) bool {
func (c *Condition) UnmarshalYAML(unmarshal func(interface{}) error) error {
var out1 string
var out2 []string
var out3 = struct {
out3 := struct {
Include []string
Exclude []string
}{}
@ -78,14 +78,16 @@ func (c *Condition) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}
unmarshal(&out2)
unmarshal(&out3)
_ = unmarshal(&out2)
_ = unmarshal(&out3)
c.Exclude = out3.Exclude
c.Include = append(
out3.Include = append(
out3.Include,
out2...,
)
c.Exclude = out3.Exclude
c.Include = out3.Include
return nil
}

View File

@ -14,7 +14,7 @@ import (
var ErrDuplicatePipelineName = errors.New("linter: duplicate pipeline names")
// ErrMissingPipelineDependency is returned when a Pipeline
// defines dependencies that are invlid or unknown.
// defines dependencies that are invalid or unknown.
var ErrMissingPipelineDependency = errors.New("linter: invalid or unknown pipeline dependency")
// ErrCyclicalPipelineDependency is returned when a Pipeline
@ -51,6 +51,8 @@ func checkPipelines(manifest *yaml.Manifest, trusted bool) error {
return err
}
}
default:
continue
}
}
return nil

View File

@ -26,7 +26,7 @@ var arch = map[string]struct{}{
var ErrDuplicateStepName = errors.New("linter: duplicate step names")
// ErrMissingDependency is returned when a Pipeline step
// defines dependencies that are invlid or unknown.
// defines dependencies that are invalid or unknown.
var ErrMissingDependency = errors.New("linter: invalid or unknown step dependency")
// ErrCyclicalDependency is returned when a Pipeline step

View File

@ -135,7 +135,7 @@ type (
Path string `json:"path,omitempty"`
}
// Workspace represents the pipeline workspace configuraiton.
// Workspace represents the pipeline workspace configuration.
Workspace struct {
Base string `json:"base,omitempty"`
Path string `json:"path,omitempty"`

View File

@ -64,7 +64,7 @@ func printContainer(w writer, v *yaml.Container) {
if len(v.DependsOn) > 0 {
printDependsOn(w, v.DependsOn)
}
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}
@ -132,10 +132,10 @@ func printPorts(w writer, v []*yaml.Port) {
w.WriteTag("ports")
for _, v := range v {
if shortPort(v) {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
w.WriteByte('-')
w.WriteByte(' ')
_ = w.WriteByte('-')
_ = w.WriteByte(' ')
writeInt(w, v.Port)
continue
}

View File

@ -7,13 +7,13 @@ import "github.com/drone/drone-yaml/yaml"
// helper function pretty prints the cron resource.
func printCron(w writer, v *yaml.Cron) {
w.WriteString("---")
_, _ = w.WriteString("---")
w.WriteTagValue("version", v.Version)
w.WriteTagValue("kind", v.Kind)
w.WriteTagValue("name", v.Name)
printSpec(w, v)
w.WriteByte('\n')
w.WriteByte('\n')
_ = w.WriteByte('\n')
_ = w.WriteByte('\n')
}
// helper function pretty prints the spec block.

View File

@ -9,12 +9,12 @@ import (
// helper function to pretty print the pipeline resource.
func printPipeline(w writer, v *yaml.Pipeline) {
w.WriteString("---")
_, _ = w.WriteString("---")
w.WriteTagValue("version", v.Version)
w.WriteTagValue("kind", v.Kind)
w.WriteTagValue("type", v.Type)
w.WriteTagValue("name", v.Name)
w.WriteByte('\n')
_ = w.WriteByte('\n')
if !isPlatformEmpty(v.Platform) {
printPlatform(w, v.Platform)
@ -61,30 +61,30 @@ func printPipeline(w writer, v *yaml.Pipeline) {
if len(v.Volumes) != 0 {
printVolumes(w, v.Volumes)
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
if len(v.PullSecrets) > 0 {
w.WriteTagValue("image_pull_secrets", v.PullSecrets)
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
if len(v.Node) > 0 {
printNode(w, v.Node)
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
if !isConditionsEmpty(v.Trigger) {
printConditions(w, "trigger", v.Trigger)
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
if len(v.DependsOn) > 0 {
printDependsOn(w, v.DependsOn)
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
w.WriteByte('\n')
_ = w.WriteByte('\n')
}
// helper function pretty prints the clone block.
@ -94,7 +94,7 @@ func printClone(w writer, v yaml.Clone) {
w.WriteTagValue("depth", v.Depth)
w.WriteTagValue("disable", v.Disable)
w.WriteTagValue("skip_verify", v.SkipVerify)
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}
@ -103,7 +103,7 @@ func printConcurrency(w writer, v yaml.Concurrency) {
w.WriteTag("concurrency")
w.IndentIncrease()
w.WriteTagValue("limit", v.Limit)
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}
@ -148,7 +148,7 @@ func printConditions(w writer, name string, v yaml.Conditions) {
func printCondition(w writer, k string, v yaml.Condition) {
w.WriteTag(k)
if len(v.Include) != 0 && len(v.Exclude) == 0 {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentIncrease()
w.Indent()
writeValue(w, v.Include)
@ -179,7 +179,7 @@ func printPlatform(w writer, v yaml.Platform) {
w.WriteTagValue("arch", v.Arch)
w.WriteTagValue("variant", v.Variant)
w.WriteTagValue("version", v.Version)
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}
@ -190,7 +190,7 @@ func printPlatformDefault(w writer) {
w.IndentIncrease()
w.WriteTagValue("os", "linux")
w.WriteTagValue("arch", "amd64")
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}
@ -207,9 +207,9 @@ func printVolumes(w writer, v []*yaml.Volume) {
if v := v.EmptyDir; v != nil {
s.WriteTag("temp")
if isEmptyDirEmpty(v) {
w.WriteByte(' ')
w.WriteByte('{')
w.WriteByte('}')
_ = w.WriteByte(' ')
_ = w.WriteByte('{')
_ = w.WriteByte('}')
} else {
s.IndentIncrease()
s.WriteTagValue("medium", v.Medium)
@ -236,7 +236,7 @@ func printWorkspace(w writer, v yaml.Workspace) {
w.IndentIncrease()
w.WriteTagValue("base", v.Base)
w.WriteTagValue("path", v.Path)
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.IndentDecrease()
}

View File

@ -26,5 +26,5 @@ func Print(w io.Writer, v *yaml.Manifest) {
}
state.WriteString("...")
state.WriteByte('\n')
w.Write(state.Bytes())
_, _ = w.Write(state.Bytes())
}

View File

@ -13,7 +13,7 @@ import (
// helper function to pretty prints the signature resource.
func printSecret(w writer, v *yaml.Secret) {
w.WriteString("---")
_, _ = w.WriteString("---")
w.WriteTagValue("version", v.Version)
w.WriteTagValue("kind", v.Kind)
w.WriteTagValue("type", v.Type)
@ -24,11 +24,11 @@ func printSecret(w writer, v *yaml.Secret) {
}
if !isSecretGetEmpty(v.Get) {
w.WriteTagValue("name", v.Name)
w.WriteByte('\n')
_ = w.WriteByte('\n')
printGet(w, v.Get)
}
w.WriteByte('\n')
w.WriteByte('\n')
_ = w.WriteByte('\n')
_ = w.WriteByte('\n')
}
// helper function prints the get block.
@ -43,14 +43,14 @@ func printGet(w writer, v yaml.SecretGet) {
func printData(w writer, d string) {
w.WriteTag("data")
w.WriteByte(' ')
w.WriteByte('>')
_ = w.WriteByte(' ')
_ = w.WriteByte('>')
w.IndentIncrease()
d = spaceReplacer.Replace(d)
for _, s := range chunk(d, 60) {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
w.WriteString(s)
_, _ = w.WriteString(s)
}
w.IndentDecrease()
}

View File

@ -9,10 +9,10 @@ import (
// helper function pretty prints the signature resource.
func printSignature(w writer, v *yaml.Signature) {
w.WriteString("---")
_, _ = w.WriteString("---")
w.WriteTagValue("version", v.Version)
w.WriteTagValue("kind", v.Kind)
w.WriteTagValue("hmac", v.Hmac)
w.WriteByte('\n')
w.WriteByte('\n')
_ = w.WriteByte('\n')
_ = w.WriteByte('\n')
}

View File

@ -71,7 +71,7 @@ type baseWriter struct {
func (w *baseWriter) Indent() {
for i := 0; i < w.depth; i++ {
w.WriteString(" ")
_, _ = w.WriteString(" ")
}
}
@ -92,10 +92,10 @@ func (w *baseWriter) ExcludeZero() {
}
func (w *baseWriter) WriteTag(v interface{}) {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
writeValue(w, v)
w.WriteByte(':')
_ = w.WriteByte(':')
}
func (w *baseWriter) WriteTagValue(k, v interface{}) {
@ -103,18 +103,19 @@ func (w *baseWriter) WriteTagValue(k, v interface{}) {
return
}
w.WriteTag(k)
if isPrimative(v) {
w.WriteByte(' ')
switch {
case isPrimative(v):
_ = w.WriteByte(' ')
writeValue(w, v)
} else if isSlice(v) {
w.WriteByte('\n')
case isSlice(v):
_ = w.WriteByte('\n')
w.IndentIncrease()
w.Indent()
writeValue(w, v)
w.IndentDecrease()
} else {
default:
w.depth++
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
writeValue(w, v)
w.depth--
@ -140,18 +141,18 @@ func (w *indexWriter) ExcludeZero() {
}
func (w *indexWriter) WriteTag(v interface{}) {
w.WriteByte('\n')
_ = w.WriteByte('\n')
if w.index == 0 {
w.IndentDecrease()
w.Indent()
w.IndentIncrease()
w.WriteByte('-')
w.WriteByte(' ')
_ = w.WriteByte('-')
_ = w.WriteByte(' ')
} else {
w.Indent()
}
writeValue(w, v)
w.WriteByte(':')
_ = w.WriteByte(':')
w.index++
}
@ -160,18 +161,19 @@ func (w *indexWriter) WriteTagValue(k, v interface{}) {
return
}
w.WriteTag(k)
if isPrimative(v) {
w.WriteByte(' ')
switch {
case isPrimative(v):
_ = w.WriteByte(' ')
writeValue(w, v)
} else if isSlice(v) {
w.WriteByte('\n')
case isSlice(v):
_ = w.WriteByte('\n')
w.IndentIncrease()
w.Indent()
writeValue(w, v)
w.IndentDecrease()
} else {
default:
w.IndentIncrease()
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
writeValue(w, v)
w.IndentDecrease()
@ -183,45 +185,45 @@ func (w *indexWriter) WriteTagValue(k, v interface{}) {
//
func writeBool(w writer, v bool) {
w.WriteString(
_, _ = w.WriteString(
strconv.FormatBool(v),
)
}
func writeFloat(w writer, v float64) {
w.WriteString(
_, _ = w.WriteString(
strconv.FormatFloat(v, 'g', -1, 64),
)
}
func writeInt(w writer, v int) {
w.WriteString(
_, _ = w.WriteString(
strconv.Itoa(v),
)
}
func writeInt64(w writer, v int64) {
w.WriteString(
_, _ = w.WriteString(
strconv.FormatInt(v, 10),
)
}
func writeEncode(w writer, v string) {
if len(v) == 0 {
w.WriteByte('"')
w.WriteByte('"')
_ = w.WriteByte('"')
_ = w.WriteByte('"')
return
}
if isQuoted(v) {
fmt.Fprintf(w, "%q", v)
} else {
w.WriteString(v)
_, _ = w.WriteString(v)
}
}
func writeValue(w writer, v interface{}) {
if v == nil {
w.WriteByte('~')
_ = w.WriteByte('~')
return
}
switch v := v.(type) {
@ -257,17 +259,17 @@ func writeScalar(w writer, v interface{}) {
func writeSequence(w writer, v []interface{}) {
if len(v) == 0 {
w.WriteByte('[')
w.WriteByte(']')
_ = w.WriteByte('[')
_ = w.WriteByte(']')
return
}
for i, v := range v {
if i != 0 {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
}
w.WriteByte('-')
w.WriteByte(' ')
_ = w.WriteByte('-')
_ = w.WriteByte(' ')
w.IndentIncrease()
writeValue(w, v)
w.IndentDecrease()
@ -276,25 +278,25 @@ func writeSequence(w writer, v []interface{}) {
func writeSequenceStr(w writer, v []string) {
if len(v) == 0 {
w.WriteByte('[')
w.WriteByte(']')
_ = w.WriteByte('[')
_ = w.WriteByte(']')
return
}
for i, v := range v {
if i != 0 {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
}
w.WriteByte('-')
w.WriteByte(' ')
_ = w.WriteByte('-')
_ = w.WriteByte(' ')
writeEncode(w, v)
}
}
func writeMapping(w writer, v map[interface{}]interface{}) {
if len(v) == 0 {
w.WriteByte('{')
w.WriteByte('}')
_ = w.WriteByte('{')
_ = w.WriteByte('}')
return
}
var keys []string
@ -306,20 +308,20 @@ func writeMapping(w writer, v map[interface{}]interface{}) {
for i, k := range keys {
v := v[k]
if i != 0 {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
}
writeEncode(w, k)
w.WriteByte(':')
_ = w.WriteByte(':')
if v == nil || isPrimative(v) || isZero(v) {
w.WriteByte(' ')
_ = w.WriteByte(' ')
writeValue(w, v)
} else {
slice := isSlice(v)
if !slice {
w.IndentIncrease()
}
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
writeValue(w, v)
if !slice {
@ -331,8 +333,8 @@ func writeMapping(w writer, v map[interface{}]interface{}) {
func writeMappingStr(w writer, v map[string]string) {
if len(v) == 0 {
w.WriteByte('{')
w.WriteByte('}')
_ = w.WriteByte('{')
_ = w.WriteByte('}')
return
}
var keys []string
@ -343,12 +345,12 @@ func writeMappingStr(w writer, v map[string]string) {
for i, k := range keys {
v := v[k]
if i != 0 {
w.WriteByte('\n')
_ = w.WriteByte('\n')
w.Indent()
}
writeEncode(w, k)
w.WriteByte(':')
w.WriteByte(' ')
_ = w.WriteByte(':')
_ = w.WriteByte(' ')
writeEncode(w, v)
}
}

View File

@ -22,7 +22,7 @@ type (
}
// SecretGet defines a request to get a secret from
// an external sevice at the specified path, or with the
// an external service at the specified path, or with the
// specified name.
SecretGet struct {
Path string `json:"path,omitempty"`