Skip to content

Commit

Permalink
Merge pull request hashicorp#1086 from hashicorp/crt-build-and-tests
Browse files Browse the repository at this point in the history
Migrate most of build-and-test CircleCI jobs to Github Actions
  • Loading branch information
curtbushko authored Mar 10, 2022
2 parents 27aeda3 + 8294f35 commit d246a8c
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 120 deletions.
57 changes: 4 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,57 +872,14 @@ workflows:
version: 2
test-and-build:
jobs:
# Fmt, vet, lint control plane and helm code
- go-fmt-and-vet-control-plane
- lint-control-plane
- go-fmt-and-vet-acceptance
- go-fmt-and-vet-helm-gen
# Unit test control plane
- test-control-plane:
requires:
- go-fmt-and-vet-control-plane
- lint-control-plane
- test-enterprise-control-plane:
filters:
branches:
# Forked pull requests have CIRCLE_BRANCH set to pull/XXX.
ignore: /pull\/[0-9]+/
requires:
- go-fmt-and-vet-control-plane
- lint-control-plane
# Unit test CLI
- unit-cli
# Unit tests for go modules in helm and bats tests for templates
- unit-acceptance-framework:
requires:
- go-fmt-and-vet-acceptance
- unit-helm-gen:
requires:
- go-fmt-and-vet-helm-gen
- validate-helm-gen
- unit-test-helm-templates
# Build control plane binaries
- build-distro:
OS: "freebsd linux windows"
ARCH: "386"
name: build-distros-386
requires:
- test-control-plane
- test-enterprise-control-plane
# Build this one control-plane binary so that acceptance and acceptance-tproxy will run
# The rest of these CircleCI jobs have been migrated to Github Actions. We need to wait until
# the summer of 2022 for larger puplic Github Action VMs be available before the acceptance tests can
# be moved
- build-distro:
OS: "darwin freebsd linux solaris windows"
ARCH: "amd64"
name: build-distros-amd64
requires:
- test-control-plane
- test-enterprise-control-plane
- build-distro:
OS: "linux"
ARCH: "arm arm64"
name: build-distros-arm-arm64
requires:
- test-control-plane
- test-enterprise-control-plane
- dev-upload-docker:
context: consul-ci
requires:
Expand All @@ -931,15 +888,9 @@ workflows:
- acceptance:
requires:
- dev-upload-docker
- unit-test-helm-templates
- unit-acceptance-framework
- unit-cli
- acceptance-tproxy:
requires:
- dev-upload-docker
- unit-test-helm-templates
- unit-acceptance-framework
- unit-cli
nightly-acceptance-tests:
triggers:
- schedule:
Expand Down
300 changes: 300 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
name: test-and-build
on:
push:

env:
TEST_RESULTS: /tmp/test-results # path to where test results are saved
CONSUL_VERSION: 1.11.2 # Consul's OSS version to use in tests
CONSUL_ENT_VERSION: 1.11.2+ent # Consul's enterprise version to use in tests
GOTESTSUM_VERSION: 1.6.4 # You cannot use environment variables with workflows. The gotestsum version is hardcoded in the reusable workflows too.

jobs:
validate-helm-gen:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.17.2

- name: Setup go mod cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Validate helm gen
working-directory: hack/helm-reference-gen
run: |
go run ./... -validate
golangci-lint-helm-gen:
uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main
with:
directory: hack/helm-reference-gen
go-version: 1.17.2
#TODO: This is a workaround in order to get pipelines working. godot and staticcheck fail for helm-reference-gen
args: "--no-config --disable-all --enable gofmt,govet"

unit-helm-gen:
needs: [golangci-lint-helm-gen, validate-helm-gen]
uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main
with:
directory: hack/helm-reference-gen
go-version: 1.17.2

unit-test-helm-templates:
needs: [unit-helm-gen]
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorpdev/consul-helm-test:0.10.0
options: --user 1001
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run Unit Tests
working-directory: charts/consul
run: bats --jobs 4 ./test/unit

lint-control-plane:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.17.2

- run: go get -u github.com/hashicorp/lint-consul-retry && lint-consul-retry

- name: Run lint
working-directory: control-plane
run: go run hack/lint-api-new-client/main.go

golangci-lint-control-plane:
uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main
with:
directory: control-plane
go-version: 1.17.2

test-control-plane:
needs: [lint-control-plane, golangci-lint-control-plane]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.17.2

- name: Setup go mod cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install gotestsum
run: |
wget https://github.com/gotestyourself/gotestsum/releases/download/v${{env.GOTESTSUM_VERSION}}/gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
sudo tar -C /usr/local/bin -xzf gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
rm gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
- run: mkdir -p ${{env.TEST_RESULTS}}
- run: echo "$HOME/bin" >> $GITHUB_PATH

- name: Download consul
working-directory: control-plane
run: |
mkdir -p $HOME/bin
wget https://releases.hashicorp.com/consul/${{env.CONSUL_VERSION}}/consul_${{env.CONSUL_VERSION}}_linux_amd64.zip && \
unzip consul_${{env.CONSUL_VERSION}}_linux_amd64.zip -d $HOME/bin && \
rm consul_${{env.CONSUL_VERSION}}_linux_amd64.zip
chmod +x $HOME/bin/consul
- name: Run go tests
working-directory: control-plane
run: |
PACKAGE_NAMES=$(go list ./...)
gotestsum --junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml -- -p 4 $PACKAGE_NAMES
test-enterprise-control-plane:
if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets
needs: [lint-control-plane, golangci-lint-control-plane]
runs-on: ubuntu-latest
env:
CONSUL_LICENSE: ${{secrets.CONSUL_LICENSE}}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.17.2

- name: Setup go mod cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install gotestsum
run: |
wget https://github.com/gotestyourself/gotestsum/releases/download/v${{env.GOTESTSUM_VERSION}}/gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
sudo tar -C /usr/local/bin -xzf gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
rm gotestsum_${{env.GOTESTSUM_VERSION}}_linux_amd64.tar.gz
- run: mkdir -p ${{env.TEST_RESULTS}}
- run: echo "$HOME/bin" >> $GITHUB_PATH

- name: Download consul
working-directory: control-plane
run: |
mkdir -p $HOME/bin
wget https://releases.hashicorp.com/consul/${{env.CONSUL_ENT_VERSION}}/consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip && \
unzip consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip -d $HOME/bin && \
rm consul_${{env.CONSUL_ENT_VERSION}}_linux_amd64.zip
chmod +x $HOME/bin/consul
- name: Run go tests
working-directory: control-plane
run: |
PACKAGE_NAMES=$(go list ./...)
gotestsum --junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml -- -tags=enterprise -p 4 $PACKAGE_NAMES
build-distros:
needs: [test-control-plane, test-enterprise-control-plane]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- {go: "1.17.2", goos: "linux", goarch: "386"}
- {go: "1.17.2", goos: "linux", goarch: "amd64"}
- {go: "1.17.2", goos: "linux", goarch: "arm"}
- {go: "1.17.2", goos: "linux", goarch: "arm64"}
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Build
working-directory: control-plane
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
XC_OS=${{ matrix.goos }} XC_ARCH=${{ matrix.goarch }} ./build-support/scripts/build-local.sh
zip -r -j consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip bin
- uses: actions/upload-artifact@v2
with:
name: consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip
path: control-plane/consul-k8s_${{ matrix.goos }}_${{ matrix.goarch }}.zip

golangci-lint-acceptance:
uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main
with:
directory: acceptance
go-version: 1.17.2

unit-acceptance-framework:
needs: golangci-lint-acceptance
uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main
with:
directory: acceptance/framework
go-version: 1.17.2

golangci-lint-cli:
uses: hashicorp/consul-k8s/.github/workflows/reusable-golangci-lint.yml@main
with:
directory: cli
go-version: 1.17.2

unit-cli:
needs: golangci-lint-cli
uses: hashicorp/consul-k8s/.github/workflows/reusable-unit.yml@main
with:
directory: cli
go-version: 1.17.2

# Disabling for now until we get faster VMs to run acceptance tests. Faster VMs for Github Actions are supposed
# to be available in the summer of 2022. For now, run the dev-upload docker and acceptance tests in CircleCI
# dev-upload-docker:
# if: github.repository_owner == 'hashicorp' # Do not run on forks as this requires secrets
# needs: build-distros
# runs-on: ubuntu-latest
#
# env:
# GITHUB_PULL_REQUEST: ${{github.event.pull_request.number}}
# DOCKER_USER: ${{secrets.DOCKER_USER}}
# DOCKER_PASS: ${{secrets.DOCKER_PASS}}
# steps:
# - uses: actions/checkout@v2
#
# - run: mkdir -p control-plane/pkg/bin/linux_amd64
#
# - uses: actions/download-artifact@v3
# with:
# name: consul-k8s_linux_amd64.zip
# path: control-plane
#
# - name: Docker build
# working-directory: control-plane
# run: |
# unzip consul-k8s_linux_amd64.zip -d ./pkg/bin/linux_amd64
# make ci.dev-docker-github
#
# acceptance-tproxy:
# needs: [unit-cli, dev-upload-docker, unit-acceptance-framework, unit-test-helm-templates]
# needs: dev-upload-docker
# uses: hashicorp/consul-k8s/.github/workflows/reusable-acceptance.yml@main
# with:
# name: acceptance-tproxy
# directory: acceptance/tests
# go-version: 1.17.2
# additional-flags: "-use-kind -kubecontext=kind-dc1 -secondary-kubecontext=kind-dc2 -enable-transparent-proxy"
# gotestsum-version: 1.6.4
# secrets:
# CONSUL_ENT_LICENSE: ${{ secrets.CONSUL_ENT_LICENSE }}
#
# acceptance:
# #needs: [unit-cli, dev-upload-docker, unit-acceptance-framework, unit-test-helm-templates]
# needs: dev-upload-docker
# uses: hashicorp/consul-k8s/.github/workflows/reusable-acceptance.yml@main
# with:
# name: acceptance
# directory: acceptance/tests
# go-version: 1.17.2
# additional-flags: "-use-kind -kubecontext=kind-dc1 -secondary-kubecontext=kind-dc2"
# gotestsum-version: 1.6.4
# secrets:
# CONSUL_ENT_LICENSE: ${{ secrets.CONSUL_ENT_LICENSE }}


Loading

0 comments on commit d246a8c

Please sign in to comment.