Skip to content

Commit

Permalink
Add CI example
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Feb 27, 2019
1 parent 8937e38 commit b3a141f
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
69 changes: 69 additions & 0 deletions example-ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
stages:
- build
- test
- release

compile:go1.11:
stage: build
image: golang:1.11
script:
- go build

compile:go1.10:
stage: build
image: golang:1.10
script:
- go build

test:
stage: test
image: golang:1.11
script:
- go test -cover

formatting:
stage: test
image: golang:1.11
script:
- test $(go fmt -l | wc -l) -eq 0

vet:
stage: test
image: golang:1.11
script:
- go vet .

lint:
stage: test
image: golang:1.11
before_script:
- GO111MODULE=off go get golang.org/x/lint/golint
script:
- golint -set_exit_status .

release-nightly:
stage: release
image:
name: goreleaser/goreleaser:v0.101.0
entrypoint: ["/bin/sh", "-c"]
script:
- goreleaser release --snapshot --skip-publish
artifacts:
paths:
- dist/*.tar.gz
expire_in: 1 week
only:
- master

release:
stage: release
image:
name: goreleaser/goreleaser:v0.101.0
entrypoint: ["/bin/sh", "-c"]
script:
- goreleaser release --skip-publish
artifacts:
paths:
- dist/*.tar.gz
only:
- tags
36 changes: 36 additions & 0 deletions example-ci/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project_name: helloworld
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
binary: hello
goos:
- darwin
- linux
- windows
- openbsd
- freebsd
goarch:
- amd64
- 386
- arm64
- arm
archive:
replacements:
darwin: macos
linux: linux
windows: windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
24 changes: 24 additions & 0 deletions example-ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3"
services:
gitlab:
image: gitlab/gitlab-ce:latest
ports:
- "80:80"
- "22:22"
volumes:
- config:/etc/gitlab
- logs:/var/log/gitlab
- data:/var/opt/gitlab
hostname: gitlab.local
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab'
runner:
image: gitlab/gitlab-runner:alpine
volumes:
- /var/run/docker.sock:/var/run/docker.sock
volumes:
config: {}
data: {}
logs: {}
1 change: 1 addition & 0 deletions example-ci/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/martin-helmich/go-tips/example-ci
20 changes: 20 additions & 0 deletions example-ci/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"fmt"
"io"
"os"
)

// PrintHello prints hello
func PrintHello(out io.Writer) error {
_, err := fmt.Fprintln(out, "Hello World")
return err
}

func main() {
err := PrintHello(os.Stdout)
if err != nil {
panic(err)
}
}
21 changes: 21 additions & 0 deletions example-ci/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"bytes"
"testing"
)

func TestPrintHelloPrintsHello(t *testing.T) {
buf := bytes.Buffer{}
err := PrintHello(&buf)

if err != nil {
t.Fatalf("err is expected nil, got: %s", err)
}

out := buf.String()

if out != "Hello World\n" {
t.Fatalf(`output is not "Hello World\n"; got: "%s"`, out)
}
}

0 comments on commit b3a141f

Please sign in to comment.