Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests from TravisCI to GitHub Action #66

Merged
merged 1 commit into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
name: Pull request testing
name: Pull request

on:
pull_request:
branches: [ master ]

env:
GO111MODULE: on
INSTALL_DEPS: true

defaults:
run:
shell: bash

jobs:
build:
runs-on: ubuntu-latest
unit-test:
strategy:
fail-fast: false
matrix:
go-version: [1.14.x, 1.15.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: "Initial Action Step"
run: echo "Initial Action"
go-version: ${{ matrix.go-version }}
- name: "Build and unit-test with Go ${{ matrix.go-version }}"
run: make test-unit
- name: "Hammer unit-test with ${{ matrix.go-version }}"
run: make test-hammer
code-quality-test:
strategy:
fail-fast: false
matrix:
go-version: [1.14.x, 1.15.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: "Code Quality Analysis"
run: make test-lint
integration-test:
strategy:
fail-fast: false
matrix:
go-version: [1.14.x, 1.15.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- if: matrix.os == 'windows-latest'
run: echo "BINARY_EXT=.exe" >> $GITHUB_ENV
- name: "Integration testing with ${{ matrix.go-version }}"
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_INTEGRATION_TESTS }}
run: |
echo "${{ env.BINARY_PATH }}"
make test-integration
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DEFAULT_GOAL = all

ROOT_DIR:=$(dir $(abspath $(firstword $(MAKEFILE_LIST))))

# enable module support across all go commands.
export GO111MODULE = on
# enable consistent Go 1.12/1.13 GOPROXY behavior.
Expand All @@ -8,12 +10,17 @@ export GOPROXY = https://proxy.golang.org
all: build-race test-unit test-integration test-lint
.PHONY: all

# When running integration tests on windows machine
# it cannot execute binary without extension.
# It needs to be parametrized, so we can override it on CI.
export BINARY_PATH = $(ROOT_DIR)/codeowners-validator$(BINARY_EXT)

############
# Building #
############

build:
go build -o codeowners-validator ./main.go
go build -o $(BINARY_PATH) ./main.go
.PHONY: build

build-race:
Expand All @@ -29,7 +36,7 @@ test-unit:
.PHONY: test-unit

test-integration: build
env BINARY_PATH=$(PWD)/codeowners-validator ./hack/run-test-integration.sh
./hack/run-test-integration.sh
.PHONY: test-integration

test-lint:
Expand Down
11 changes: 9 additions & 2 deletions hack/run-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ set -E # needs to be set if we want the ERR trap
readonly CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly ROOT_PATH=$( cd "${CURRENT_DIR}/.." && pwd )
readonly GOLANGCI_LINT_VERSION="v1.31.0"
readonly TMP_DIR=$(mktemp -d)

# shellcheck source=./hack/lib/utilities.sh
source "${CURRENT_DIR}/lib/utilities.sh" || { echo 'Cannot load CI utilities.'; exit 1; }

host::install::golangci() {
shout "Install the golangci-lint in version ${GOLANGCI_LINT_VERSION}"
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b "$GOPATH"/bin ${GOLANGCI_LINT_VERSION}
mkdir -p "${TMP_DIR}/bin"
export PATH="${TMP_DIR}/bin:${PATH}"

shout "Install the golangci-lint ${GOLANGCI_LINT_VERSION} locally to a tempdir..."
curl -sfSL -o "${TMP_DIR}/golangci-lint.sh" https://install.goreleaser.com/github.com/golangci/golangci-lint.sh
chmod 700 "${TMP_DIR}/golangci-lint.sh"

"${TMP_DIR}/golangci-lint.sh" -b "${TMP_DIR}/bin" ${GOLANGCI_LINT_VERSION}

echo -e "${GREEN}√ install golangci-lint${NC}"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func normalizeTimeDurations(in string) string {
duration := regexp.MustCompile(`\([0-9]+.[0-9]+(ns|us|µs|ms|s|m|h)\)`)
duration := regexp.MustCompile(`\(\d+(\.\d+)?(ns|us|µs|ms|s|m|h)\)`)
return duration.ReplaceAllString(in, "(<duration>)")
}

Expand Down
11 changes: 9 additions & 2 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package integration

import (
"os"
"runtime"
"testing"
"time"

Expand All @@ -28,8 +29,9 @@ const (
func TestCheckSuccess(t *testing.T) {
type Envs map[string]string
tests := []struct {
name string
envs Envs
name string
envs Envs
skipOS string
}{
{
name: "files",
Expand Down Expand Up @@ -58,10 +60,15 @@ func TestCheckSuccess(t *testing.T) {
"CHECKS": "disable-all",
"EXPERIMENTAL_CHECKS": "notowned",
},
skipOS: "windows",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if runtime.GOOS == tc.skipOS {
t.Skip("this test is marked as skipped for this OS")
}

// given
repoDir, cleanup := CloneRepo(t, codeownersSamplesRepo, "happy-path")
defer cleanup()
Expand Down