Skip to content

Commit

Permalink
Release via CI (#7)
Browse files Browse the repository at this point in the history
 * [x] go-code version cleanup
 * [x] extend tests (vet & format)
 * [x] build & publish docker
  • Loading branch information
6543 authored Oct 7, 2021
1 parent ba6dc75 commit 29fa7a0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 24 deletions.
30 changes: 25 additions & 5 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@ clone:
image: plugins/git:next

pipeline:
test:
lint:
image: golang:1.16
commands:
- go test -race -cover ./...
- make vet
- make formatcheck

vet:
test:
image: golang:1.16
commands:
- go vet ./...
- make test

build:
image: golang:1.16
commands:
- go build
- make build

dryrun:
image: plugins/docker
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
repo: woodpeckerci/plugin-s3
tags: latest
when:
event: pull_request

publish:
image: plugins/docker
dockerfile: docker/Dockerfile.linux.amd64
repo: woodpeckerci/plugin-s3
tags: latest
secrets: [ docker_username, docker_password ]
when:
branch: master
event: push
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)

VERSION ?= next
ifneq ($(DRONE_TAG),)
VERSION := $(DRONE_TAG:v%=%)
endif

# append commit-sha to next version
BUILD_VERSION := $(VERSION)
ifeq ($(BUILD_VERSION),next)
BUILD_VERSION := $(shell echo "next-$(shell echo ${DRONE_COMMIT_SHA} | head -c 8)")
endif

LDFLAGS := -s -w -extldflags "-static" -X main.version=${BUILD_VERSION}

all: build

vendor:
go mod tidy
go mod vendor

formatcheck:
@([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR) | head)" ]) || (echo "Source is unformatted"; exit 1)

format:
@gofmt -w ${GOFILES_NOVENDOR}

.PHONY: clean
clean:
go clean -i ./...
rm -rf release/

.PHONY: vet
vet:
@echo "Running go vet..."
@go vet $(GO_PACKAGES)

test:
go test -race -cover ./...

build:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux/amd64/plugin-s3
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux/arm64/plugin-s3
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/linux/arm/plugin-s3
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/windows/amd64/plugin-s3
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/darwin/amd64/plugin-s3
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/darwin/arm64/plugin-s3

.PHONY: version
version:
@echo ${VERSION}
8 changes: 2 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package main

import (
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

var (
version = "0.0.0"
build = "0"
)
var version = "0.0.0+0"

func main() {
app := cli.NewApp()
app.Name = "s3 plugin"
app.Usage = "s3 plugin"
app.Version = fmt.Sprintf("%s+%s", version, build)
app.Version = version
app.Action = run
app.Flags = []cli.Flag{
cli.StringFlag{
Expand Down
13 changes: 0 additions & 13 deletions renovate.json

This file was deleted.

0 comments on commit 29fa7a0

Please sign in to comment.