From 49cf99f4d9a0e41af66e57cd551cb8d0e4e3857e Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Tue, 10 Aug 2021 19:02:37 -0700 Subject: [PATCH] ci: add initial config for gitlab CI Just checks linting, and build/test. --- .gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++++ .gitlab-ci/check_gofmt.sh | 11 ++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100755 .gitlab-ci/check_gofmt.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..27d9b2f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,43 @@ +--- + +# global settings +image: alpine:latest + +stages: + - lint + - build + +# defaults for "only" +# We need to run the CI jobs in a "merge request specific context", if CI is +# running in a merge request. Otherwise the environment variable that holds the +# merge request ID is not available. This means, we must set the "only" +# variable accordingly - and if we only do it for one job, all other jobs will +# not get executed. So have the defaults here, and use them in all jobs that +# should run on both the master branch, and in merge requests. +# https://docs.gitlab.com/ee/ci/merge_request_pipelines/index.html#excluding-certain-jobs +.only-default: &only-default + only: + - master + - merge_requests + - tags + +# device documentation +gofmt linting: + stage: lint + allow_failure: true + <<: *only-default + before_script: + - apk -q add go + script: + - .gitlab-ci/check_gofmt.sh + +build: + stage: build + <<: *only-default + before_script: + - apk -q add go + script: + - go build -v + - go test ./... + artifacts: + expire_in: 1 week diff --git a/.gitlab-ci/check_gofmt.sh b/.gitlab-ci/check_gofmt.sh new file mode 100755 index 0000000..dd24d7d --- /dev/null +++ b/.gitlab-ci/check_gofmt.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +files="$(gofmt -l .)" + +[ -z "$files" ] && exit 0 + +# run gofmt to print out the diff of what needs to be changed + +gofmt -d -e . + +exit 1