Skip to content

Commit

Permalink
feat: Improve pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
dbellinghoven committed Jun 7, 2019
1 parent 9e21ba4 commit 7230495
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 76 deletions.
54 changes: 54 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[run]
deadline = "5m"

[issues]
exclude = [
# golint: False positives for multi-file packages
'should have a package comment',
# gosec: Duplicate of errcheck
'G104: Errors unhandled',
]
exclude-rules = [
{
path = '_test\.go',
linters = [
'dupl',
'goconst',
'gocyclo',
'scopelint',
'lll',
]
},
]
exclude-use-default = false

[linters]
enable-all = true
disable = [
"gochecknoglobals", # There are valid use cases for globals
"maligned", # Readability is more important than saving bytes
]

[linters-settings]

[linters-settings.errcheck]
exclude = "./ci/lint/errcheck-exclude.txt"

[linters-settings.goconst]
min-len = 0
min-occurrences = 3

[linters-settings.gocyclo]
min-complexity = 10

[linters-settings.golint]
min-confidence = 0.0

[linters-settings.govet]
check-shadowing = true

[linters-settings.misspell]
locale = "US"

[linters-settings.nakedret]
max-func-lines = 0
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ LOCAL_BINARY=bin/$(BINARY_NAME)

all: build

update_deps:
@GO111MODULE=on go mod tidy -v && go mod vendor -v
.PHONY: update_deps

docker: Dockerfile
scripts/docker-build.sh
.PHONY: docker
Expand All @@ -40,10 +36,6 @@ $(LOCAL_BINARY): $(SOURCES)
@sh -c "'./scripts/build-binary.sh' '$(shell git describe --tags --abbrev=0)' '$(shell git rev-parse --short HEAD)' '$(REPO)'"
@echo "==> Done. Your binary can be found at bin/go-elasticsearch-alerts."

test:
@GO111MODULE=on go test -v -cover ./...
.PHONY: test

git_chglog_check:
if [ -z "$(shell which git-chglog)" ]; then \
GOPATH=$(shell pwd) PATH=$$PATH:$(shell pwd)/bin go get -u -v github.com/git-chglog/git-chglog/cmd/git-chglog && GOPATH=$(shell pwd) PATH=$$PATH:$(shell pwd)/bin git-chglog --version; \
Expand Down Expand Up @@ -79,7 +71,9 @@ set_pipeline: check_fly
--config ci/pipeline.yml \
--pipeline $(CONCOURSE_PIPELINE) \
--non-interactive \
-v github-repo="$$(git config remote.origin.url)"
-v github-repo="$$(git config remote.origin.url)" \
-v github-actor="Dilan Bellinghoven" \
-v github-email="dbellinghoven@morningconsult.com"

$(FLY) --target mci-ci-oss unpause-pipeline \
--pipeline $(CONCOURSE_PIPELINE)
Expand Down
4 changes: 4 additions & 0 deletions ci/lint/errcheck-exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(io.Closer).Close
(net/http.ResponseWriter).Write
os.Setenv
(github.com/hashicorp/consul/api.Lock).Unlock
108 changes: 85 additions & 23 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,40 @@ resource_types:
#
# ====================================
resources:
- name: test-pull-request
- name: go-elasticsearch-alerts-pr
type: pull-request
source:
repository: morningconsult/go-elasticsearch-alerts
access_token: ((github-access-token))

- name: new-release
- name: go-elasticsearch-alerts
type: git
source:
private_key: ((github-private-key))
access_token: ((github-access-token))
uri: ((github-repo))
branch: master
clean_tags: true

- name: go-elasticsearch-alerts-bumped
type: git
source:
private_key: ((github-private-key))
access_token: ((github-access-token))
uri: ((github-repo))
branch: master
tag_filter: 'v*'

- name: golang
type: registry-image
source:
repository: golang
tag: 1.11.4-alpine3.8
tag: 1.12-alpine3.9

- name: python
type: registry-image
source:
repository: python
tag: 3.7.3-alpine3.9

- name: slack
type: slack-alert
Expand All @@ -55,50 +69,98 @@ resources:
#
# ====================================
jobs:
- name: test-pr
- name: validate-pull-request
build_logs_to_retain: 30
serial: true
plan:
- in_parallel:
- get: test-pull-request
- get: go-elasticsearch-alerts-pr
trigger: true
- get: golang
- put: test-pull-request
- put: go-elasticsearch-alerts-pr
params:
path: test-pull-request
path: go-elasticsearch-alerts-pr
status: pending
context: test-pr
- task: test-pr
- task: validate-pull-request
image: golang
file: test-pull-request/ci/tasks/test-pull-request.yml
file: go-elasticsearch-alerts-pr/ci/tasks/validate.yml
input_mapping: {repo: go-elasticsearch-alerts-pr}
on_failure:
put: test-pull-request
put: go-elasticsearch-alerts-pr
params:
path: test-pull-request
path: go-elasticsearch-alerts-pr
status: failure
context: test-pr
on_abort:
put: test-pull-request
put: go-elasticsearch-alerts-pr
params:
path: test-pull-request
path: go-elasticsearch-alerts-pr
status: error
context: test-pr
- put: test-pull-request
- put: go-elasticsearch-alerts-pr
params:
path: test-pull-request
path: go-elasticsearch-alerts-pr
status: success
context: test-pr

- name: build-release
- name: validate-master
build_logs_to_retain: 30
serial: true
plan:
- in_parallel:
- get: go-elasticsearch-alerts
trigger: true
- get: golang
- task: validate-master
image: golang
file: go-elasticsearch-alerts/ci/tasks/validate.yml
input_mapping: {repo: go-elasticsearch-alerts}
on_failure:
put: slack
params: {alert_type: failed}
on_abort:
put: slack
params: {alert_type: aborted}

- name: build-new-release
build_logs_to_retain: 30
serial: true
plan:
- in_parallel:
- get: go-elasticsearch-alerts
trigger: true
passed: [validate-master]
- get: python
- task: build-release
image: python
file: go-elasticsearch-alerts/ci/tasks/build-release.yml
input_mapping: {repo: go-elasticsearch-alerts}
output_mapping: {repo-dirty: go-elasticsearch-alerts-dirty}
params:
GITHUB_ACTOR: ((github-actor))
GITHUB_EMAIL: ((github-email))
on_success:
put: go-elasticsearch-alerts-bumped
params:
repository: go-elasticsearch-alerts-dirty
merge: true
on_failure:
put: slack
params: {alert_type: failed}
on_abort:
put: slack
params: {alert_type: aborted}

- name: publish-release
build_logs_to_retain: 30
serial: true
plan:
- in_parallel:
- get: new-release
- get: go-elasticsearch-alerts-bumped
trigger: true
passed: [build-new-release]
- get: golang
- task: test-and-build
image: golang
file: new-release/ci/tasks/build-release.yml
file: go-elasticsearch-alerts-bumped/ci/tasks/publish-release.yml
input_mapping: {repo: go-elasticsearch-alerts-bumped}
params:
GITHUB_TOKEN: ((github-access-token))
on_failure:
Expand Down
55 changes: 55 additions & 0 deletions ci/release/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh
# Copyright 2019 The Morning Consult, LLC or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -eu

apk add -qU --no-cache --no-progress git

git config --global user.email "${GITHUB_EMAIL}"
git config --global user.name "${GITHUB_ACTOR}"

readonly GIT_CHGLOG_VERSION="0.8.0"

# Download git-chglog
wget --output-document=/usr/local/bin/git-chglog --quiet \
"https://github.com/git-chglog/git-chglog/releases/download/${GIT_CHGLOG_VERSION}/git-chglog_linux_amd64"

# Make it executable
chmod a+x /usr/local/bin/git-chglog

# Clone the repo
git clone repo repo-dirty

cd repo-dirty

# Install dependencies
pip install --quiet --requirement ./ci/release/requirements.txt

# Get the latest version
readonly VERSION="$( python ./ci/release/version.py )"

if [ "${VERSION}" = "" ]; then
exit 0
fi

echo "${VERSION}" > ./VERSION

git-chglog --output ./CHANGELOG.md

# Add and commit changed files
git add ./VERSION ./CHANGELOG.md
git commit -m "chore: Bump version and update changelog [ci skip]"

# Tag the repo with the latest version
git tag "${VERSION}"
14 changes: 5 additions & 9 deletions ci/build-release.sh → ci/release/publish-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@
set -e

readonly PROJECT="github.com/morningconsult/go-elasticsearch-alerts"
readonly GORELEASER_VERSION=v0.104.0
readonly GORELEASER_VERSION="v0.108.0"

echo "==> Installing APK dependencies"

apk add -qU --no-cache --no-progress \
make \
bash \
git \
gnupg \
bzr
gnupg

echo "==> Installing goreleaser $GORELEASER_VERSION"

wget --quiet -O /tmp/goreleaser.tar.gz https://github.com/goreleaser/goreleaser/releases/download/${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz
tar xzf /tmp/goreleaser.tar.gz -C /tmp
mv /tmp/goreleaser /usr/local/bin
wget --quiet -O /tmp/goreleaser.tar.gz "https://github.com/goreleaser/goreleaser/releases/download/${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz"
tar xzf /tmp/goreleaser.tar.gz -C /usr/local/bin

echo "==> Running unit tests"

CGO_ENABLED=0 make test
CGO_ENABLED=0 GO111MODULE=on go test ./...

goreleaser release \
--rm-dist
2 changes: 2 additions & 0 deletions ci/release/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GitPython
semantic_version
Loading

0 comments on commit 7230495

Please sign in to comment.