Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Sep 10, 2023
1 parent 8915738 commit feea767
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
22 changes: 12 additions & 10 deletions .gitlab/all.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.build validation image:
stage: pre test
extends: .rules all
image: docker:20
services: [ docker:20-dind ]
Expand All @@ -10,17 +9,19 @@
- docker push ${VALIDATION_IMAGE}

go build:
stage: test
extends: [ .rules all, .go ]
needs: []
needs:
- job: build-image:golang
optional: true
variables:
GIT_SUBMODULE_STRATEGY: recursive
script: go build -v ./...

.go test:
stage: test
extends: [ .rules all, .go ]
needs: []
needs:
- job: build-image:golang
optional: true
variables:
GIT_SUBMODULE_STRATEGY: recursive
artifacts:
Expand Down Expand Up @@ -53,26 +54,28 @@ go test 1/2:
- go run gotest.tools/gotestsum --junitfile report.xml --format testname -- -timeout 30m ./test/validate -short -test.validate.network "$PWD/.nodes/node-1/dnn/" -run TestValidateNetwork

lint:
stage: test
extends: [ .rules all, .go ]
needs: []
needs:
- job: build-image:golang
optional: true
variables:
GIT_DEPTH: 0
before_script:
- function die { echo -e "${BOLD_RED}${1}${NO_COLOR}"; false; }
- function check-diff { git diff --quiet "$@" && return 0; git --no-pager -c color.ui=always diff; return 1; }
script:
- echo -e "${SECTION}section_start:`date +%s`:lint\r${SECTION}Lint"
- go run ./tools/cmd/golangci-lint run --verbose --timeout 20m
- echo -e "${SECTION}section_end:`date +%s`:lint\r${SECTION}"

- echo -e "${SECTION}section_start:`date +%s`:tidy\r${SECTION}Verify go.mod is tidy"
- go mod tidy
- git diff --quiet go.mod go.sum || die "Go mod files are not tidy. Please run \`go mod tidy\`."
- check-diff go.mod go.sum || die "Go mod files are not tidy. Please run \`go mod tidy\`."
- echo -e "${SECTION}section_end:`date +%s`:tidy\r${SECTION}"

- echo -e "${SECTION}section_start:`date +%s`:generate\r${SECTION}Verify generated files are up to date"
- go generate -x ./...
- git diff --quiet || die "Generated files are not up to date. Please run \`go generate ./...\`."
- check-diff || die "Generated files are not up to date. Please run \`go generate ./...\`."
- echo -e "${SECTION}section_end:`date +%s`:generate\r${SECTION}"

- echo -e "${SECTION}section_start:`date +%s`:imports\r${SECTION}Verify code is correctly formatted"
Expand All @@ -83,7 +86,6 @@ lint:
.cleanup images:
# Once validation is done, delete the images
# Disabled because it doesn't appear to work, though it was copied from GitLab's docs
stage: post test
extends: .rules all
image: docker:20
services: [ docker:20-dind ]
Expand Down
41 changes: 20 additions & 21 deletions .gitlab/common.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
stages:
- pre test
- test
- post test
- pre deploy
- deploy
- post deploy
- test

variables:
BOLD_RED: '\e[1;31m'
NO_COLOR: '\e[0m'
SECTION: '\e[0K'
PRODUCTION_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
VALIDATION_IMAGE: ${CI_REGISTRY_IMAGE}/validation:${CI_COMMIT_REF_SLUG}
GO_CI_IMAGE: ${CI_REGISTRY_IMAGE}/ci-golang

build-image:golang:
stage: test
image: docker:20
needs: []
rules:
- changes:
- .gitlab/**/*
- scripts/images/**/*
services:
- name: docker:20-dind
command: [ --experimental ] # Do we need this?
script:
- docker build -t ${GO_CI_IMAGE} scripts/images/ci-golang
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push ${GO_CI_IMAGE}

.go:
image: golang:1.20
stage: test
image: ${GO_CI_IMAGE}
cache:
key: go-mod-cache
paths:
Expand All @@ -23,20 +36,6 @@ variables:
variables:
GOMODCACHE: ${CI_PROJECT_DIR}/.go-mod-cache
GOLANGCI_LINT_CACHE: ${CI_PROJECT_DIR}/.golangci-cache
before_script:
- |
function build-daemon {
export GOOS=$1
export GOARCH=$2
BIN=accumulated
[ -z "$GOOS" ] || BIN=${BIN}-${GOOS}
[ -z "$GOARCH" ] || BIN=${BIN}-${GOARCH}
[[ $GOOS == windows ]] && BIN=${BIN}.exe
export BUILDFLAGS="-o ${BIN}"
echo -e "${SECTION}section_start:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}Build accumulated for $GOOS $GOARCH"
make GIT_COMMIT=${CI_COMMIT_SHA} GIT_DESCRIBE=${GIT_DESCRIBE}
echo -e "${SECTION}section_end:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}";
}

.rules all:
rules:
Expand Down
22 changes: 18 additions & 4 deletions .gitlab/release.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- if: ($CI_COMMIT_BRANCH == 'release-1.0' || $CI_COMMIT_TAG != null) && $CI_PIPELINE_SOURCE != 'merge_request_event'

git describe:
stage: pre deploy
stage: test
extends: .rules all
needs: []
script:
Expand All @@ -14,7 +14,7 @@ git describe:
dotenv: git.env

docker buildx:
stage: pre deploy
stage: test
extends: .rules release
image: docker:20-git
needs: []
Expand All @@ -31,7 +31,7 @@ docker buildx:
- docker build --platform=local -o . ./docker-buildx

build main image:
stage: pre deploy
stage: test
extends: .rules release
needs: [ docker buildx ]
image: docker:20
Expand All @@ -49,12 +49,26 @@ build main image:
- docker buildx build --platform linux/amd64,linux/arm64 --push -t ${PRODUCTION_IMAGE} .

build binaries:
stage: pre deploy
stage: test
extends: [ .rules release, .go ]
needs: [ git describe ]
# rules:
# - if: ($CI_COMMIT_BRANCH != 'develop' && $CI_COMMIT_TAG == null) || $CI_PIPELINE_SOURCE == 'merge_request_event'
# when: manual
before_script:
- |
function build-daemon {
export GOOS=$1
export GOARCH=$2
BIN=accumulated
[ -z "$GOOS" ] || BIN=${BIN}-${GOOS}
[ -z "$GOARCH" ] || BIN=${BIN}-${GOARCH}
[[ $GOOS == windows ]] && BIN=${BIN}.exe
export BUILDFLAGS="-o ${BIN}"
echo -e "${SECTION}section_start:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}Build accumulated for $GOOS $GOARCH"
make GIT_COMMIT=${CI_COMMIT_SHA} GIT_DESCRIBE=${GIT_DESCRIBE}
echo -e "${SECTION}section_end:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}";
}
script:
- build-daemon linux amd64
- build-daemon linux arm64
Expand Down
3 changes: 3 additions & 0 deletions scripts/images/ci-golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM golang:1.20

RUN apt update -y && apt install -y git-lfs

0 comments on commit feea767

Please sign in to comment.