Skip to content

Commit

Permalink
Merge pull request spacemonkeygo#13 from mendersoftware/men_3880_ci_p…
Browse files Browse the repository at this point in the history
…ipeline

MEN-3880 CI pipeline added
  • Loading branch information
merlin-northern authored Aug 17, 2020
2 parents dafbd08 + 8d575f6 commit 5dbd681
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
include:
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-github-status-updates.yml'

stages:
- test
- publish

test:unit:
image: golang:1.14
stage: test

before_script:
# Rename the branch we're on, so that it's not in the way for the
# subsequent fetch. It's ok if this fails, it just means we're not on any
# branch.
- git branch -m temp-branch || true
# Git trick: Fetch directly into our local branches instead of remote
# branches.
- git fetch origin 'refs/heads/*:refs/heads/*'
# Get last remaining tags, if any.
- git fetch --tags origin

# Prepare GO path
- mkdir -p /go/src/github.com/mendersoftware
- cp -r $CI_PROJECT_DIR /go/src/github.com/mendersoftware/openssl
- cd /go/src/github.com/mendersoftware/openssl

# Install code coverage / coveralls tooling
- go get -u github.com/axw/gocov/gocov
- go get -u golang.org/x/tools/cmd/cover

# Install OpenSSL
- apt-get update && apt-get install -yyq liblzma-dev libssl-dev

script:
# Test if code was formatted with 'go fmt'
# Command will format code and return modified files
# fail if any have been modified.
- if [ -n "$(go fmt)" ]; then echo 'Code is not formatted with "go fmt"'; false; fi

# Perform static code analysys
- go vet `go list ./... | grep -v vendor`

# go list supply import paths for all sub directories.
# Exclude vendor directory, we don't want to run tests and coverage for all dependencies every time,
# also including their coverage may introduce to much noice. Concentrate on the coverage of local packages.
# Execute go test on every local subpackage (resolved as dependencies) and generate covreage report for each.
# Test packages pararell (xargs -P)
- go list ./... | grep -v vendor | xargs -n1 -I {} -P 4 go test -v -covermode=atomic -coverprofile=../../../{}/coverage.txt {} || exit $?

# Collect coverage reports
- mkdir -p tests/unit-coverage && find . -name 'coverage.txt' -exec cp --parents {} ./tests/unit-coverage \;
- tar -cvf $CI_PROJECT_DIR/unit-coverage.tar tests/unit-coverage

artifacts:
expire_in: 2w
paths:
- unit-coverage.tar

publish:tests:
image: alpine
stage: publish
before_script:
- apk add --no-cache bash curl findutils git
dependencies:
- test:unit
script:
- tar -xvf unit-coverage.tar
- bash -c "bash <(curl -s https://codecov.io/bash) -Z -s ./tests/unit-coverage"

0 comments on commit 5dbd681

Please sign in to comment.