Skip to content

Commit

Permalink
Merge pull request #275 from atc0005/i165-use-docker-containers-for-c…
Browse files Browse the repository at this point in the history
…i-work

Use Docker-based GitHub Actions Workflows
  • Loading branch information
atc0005 authored Aug 3, 2020
2 parents abc5ca1 + 547a12d commit 71db243
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 63 deletions.
102 changes: 45 additions & 57 deletions .github/workflows/lint-and-build-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,79 +20,67 @@ name: Validate Codebase
# `synchronized` seems to equate to pushing new commits to a linked branch
# (whether force-pushed or not)
on:
#push:
pull_request:
types: [opened, synchronize]

jobs:
lint_and_build_code:
name: Lint and Build codebase
runs-on: ${{ matrix.os }}
# Default: 360 minutes
lint_code:
name: Lint codebase
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
# Supported versions of Go
go-version: [1.13.x, 1.14.x]
container:
image: index.docker.io/atc0005/go-ci:go-ci-lint-only

# Supported LTS and latest version of Ubuntu Linux
#os: [ubuntu-16.04, ubuntu-18.04, ubuntu-latest]
steps:
- name: Check out code
uses: actions/[email protected]

# This should be good enough until we learn otherwise
os: [ubuntu-latest]
- name: Run golangci-lint using repo-provided config file settings
run: golangci-lint run -v

steps:
- name: Set up Go
# https://github.com/actions/setup-go
uses: actions/[email protected]
with:
go-version: ${{ matrix.go-version }}
id: go
# This is the very latest stable version of staticcheck provided by the
# atc0005/go-ci container. The version included with golangci-lint often
# lags behind the official stable releases.
- name: Run staticcheck
run: staticcheck $(go list -mod=vendor ./... | grep -v /vendor/)

# This could prove useful if we need to troubleshoot odd results and
# tie them back to a specific version of Go
- name: Print go version
run: |
go version
test_code:
name: Run tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
container-image: ["go-ci-oldstable", "go-ci-stable", "go-ci-unstable"]

- name: Check out code into the Go module directory
uses: actions/[email protected]
container:
image: "index.docker.io/atc0005/go-ci:${{ matrix.container-image}}"

# NOTE: Disabled in favor of top-level `vendor` folder
#
# - name: Get dependencies
# run: |
# go get -v -t -d ./...
steps:
- name: Check out code
uses: actions/[email protected]

# Force tests to run early as it isn't worth doing much else if the
# tests fail to run properly.
# Note: The `vendor` top-level folder appears to be skipped by default.
- name: Run all tests
run: go test -mod=vendor -v ./...

- name: Install Go linting tools
run: |
# add executables installed with go get to PATH
# TODO: this will hopefully be fixed by
# https://github.com/actions/setup-go/issues/14
export PATH=${PATH}:$(go env GOPATH)/bin
make lintinstall
build_code:
name: Build codebase
runs-on: ubuntu-latest
# Default: 360 minutes
timeout-minutes: 10
strategy:
matrix:
container-image: ["go-ci-oldstable", "go-ci-stable", "go-ci-unstable"]

- name: Install Ubuntu packages
if: contains(matrix.os, 'ubuntu')
run: sudo apt update && sudo apt install -y --no-install-recommends make gcc
container:
image: "index.docker.io/atc0005/go-ci:${{ matrix.container-image}}"

- name: Run Go linting tools using project Makefile
run: |
# add executables installed with go get to PATH
# TODO: this will hopefully be fixed by
# https://github.com/actions/setup-go/issues/14
export PATH=${PATH}:$(go env GOPATH)/bin
make linting
steps:
- name: Print go version
run: go version

- name: Build with (mostly) default options
# Note: We use the `-mod=vendor` flag to explicitly request that our
# top-level vendor folder be used instead of fetching remote packages
run: go build -v -mod=vendor ./cmd/elbow
- name: Check out code
uses: actions/[email protected]

- name: Build using project Makefile
run: make all
- name: Build using vendored dependencies
run: go build -v -mod=vendor ./cmd/elbow
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
# https://www.gnu.org/software/make/manual/html_node/Recipe-Syntax.html#Recipe-Syntax
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
# https://github.com/golangci/golangci-lint#install
# https://github.com/golangci/golangci-lint/releases/latest


SHELL = /bin/bash
Expand All @@ -45,10 +47,6 @@ TESTENVDIR2 = $(TESTENVBASEDIR)/path2
# https://github.com/atc0005/elbow/issues/54
VERSION = $(shell git describe --always --long --dirty)

# https://github.com/golangci/golangci-lint#install
# https://github.com/golangci/golangci-lint/releases/latest
GOLANGCI_LINT_VERSION = v1.25.1

# The default `go build` process embeds debugging information. Building
# without that debugging information reduces the binary size by around 28%.
BUILDCMD = go build -mod=vendor -a -ldflags="-s -w -X $(VERSION_VAR_PKG).version=$(VERSION)"
Expand Down Expand Up @@ -100,8 +98,8 @@ lintinstall:
@echo "Explicitly enabling Go modules mode per command"
(cd; GO111MODULE="on" go get honnef.co/go/tools/cmd/staticcheck)

@echo Installing golangci-lint ${GOLANGCI_LINT_VERSION} per official binary installation docs ...
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
@echo Installing latest stable golangci-lint version per official installation script ...
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin
golangci-lint --version

@echo "Finished updating linting tools"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Elbow, Elbow grease.
[![GoDoc](https://godoc.org/github.com/atc0005/elbow?status.svg)](https://godoc.org/github.com/atc0005/elbow)
![Validate Codebase](https://github.com/atc0005/elbow/workflows/Validate%20Codebase/badge.svg)
![Validate Docs](https://github.com/atc0005/elbow/workflows/Validate%20Docs/badge.svg)
![Lint and Build using Makefile](https://github.com/atc0005/elbow/workflows/Lint%20and%20Build%20using%20Makefile/badge.svg)
![Quick Validation](https://github.com/atc0005/elbow/workflows/Quick%20Validation/badge.svg)

- [elbow](#elbow)
- [Project home](#project-home)
Expand Down

0 comments on commit 71db243

Please sign in to comment.