From e84e9866777624e53934a8d89b51d31f5864cd9d Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Mon, 28 Sep 2020 13:47:27 -0500 Subject: [PATCH] Simplify CI Signed-off-by: Ed Warnicke --- .github/workflows/ci.yaml | 118 ++++++++------------------------------ .golangci.yml | 10 ++++ exechelper_test.go | 8 +-- 3 files changed, 37 insertions(+), 99 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d04eefe..79f014c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,80 +9,22 @@ on: - master jobs: build: - name: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - run: | - go build -race ./... - build-win: - name: build-win - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - run: | - go build -race ./... - build-osx: - name: build-osx - runs-on: macos-latest + name: build-and-test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - run: | - go build -race ./... - test: - name: test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - name: Install gotestsum - run: go get gotest.tools/gotestsum@v0.4.0 - - name: Run tests - run: | - eval $(go env) - mkdir -p ~/junit/ - ${GOPATH}/bin/gotestsum --junitfile ~/junit/unit-tests.xml -- -race -short $(go list ./...) - test-win: - name: test-win - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - name: Install gotestsum - run: go get gotest.tools/gotestsum@v0.4.0 - - name: Run tests - run: | - $env:Path += ";$(go env GOPATH)\bin" - mkdir $home/junit - gotestsum --junitfile $home\junit\unit-tests.xml -- -race -short $(go list .\...) - test-osx: - name: test-osx - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v1 with: go-version: 1.13.4 - - name: Install gotestsum - run: go get gotest.tools/gotestsum@v0.4.0 - - name: Run tests - run: | - eval $(go env) - mkdir -p ~/junit/ - ${GOPATH}/bin/gotestsum --junitfile ~/junit/unit-tests.xml -- -race -short $(go list ./...) + - name: Build + run: go build -race ./... + - name: Test + run: go test -race ./... golangci-lint: name: golangci-lint runs-on: ubuntu-latest @@ -91,10 +33,11 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Pull golangci-lint docker container - run: docker pull ${GOLANGCI_LINT_CONTAINER} - - name: Run golangci-lint - run: docker run --rm -v $(pwd):/app -w /app ${GOLANGCI_LINT_CONTAINER} golangci-lint run + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.31 checkgomod: name: check go.mod and go.sum runs-on: ubuntu-latest @@ -107,20 +50,6 @@ jobs: - name: Check for changes in go.mod or go.sum run: | git diff --name-only --exit-code $(ls -1 go.*) || ( echo "Run go tidy" && false ) - license: - name: license header check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.13.4 - - name: Install go-header - run: 'go get github.com/denis-tingajkin/go-header@v0.2.2' - - name: Run go-header - run: | - eval $(go env) - ${GOPATH}/bin/go-header excludereplace: name: Exclude replace in go.mod runs-on: ubuntu-latest @@ -137,9 +66,8 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Setup Python - uses: actions/setup-python@v1 - - name: Install yamllint - run: pip install --user yamllint - - name: Run yamllint - run: ~/.local/bin/yamllint -c .ci/yamllint.yml --strict . + - name: yaml-lint + uses: ibiqlik/action-yamllint@v1 + with: + config_file: .ci/yamllint.yml + strict: true diff --git a/.golangci.yml b/.golangci.yml index ae1e7c5..495c955 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,6 +7,16 @@ run: linters-settings: funlen: lines: 80 + goheader: + template-path: ".license/template.txt" + values: + const: + year: 2020 + regexp: + year-range: ((\d\d\d\d-{{year}})|({{year}})) + company: .* + copyright-holder: Copyright \(c\) {{year-range}} {{company}}\n\n + copyright-holders: ({{copyright-holder}})+ gosec: settings: exclude: "G204" diff --git a/exechelper_test.go b/exechelper_test.go index d30f5b1..d80ec02 100644 --- a/exechelper_test.go +++ b/exechelper_test.go @@ -177,11 +177,11 @@ func TestWithEnvKV(t *testing.T) { func TestWithGracePeriodWithContext(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - graceperiod := 200 * time.Millisecond + graceperiod := 500 * time.Millisecond err := exechelper.Run("go build ./testcmds/afterterm") require.NoError(t, err) errCh := exechelper.Start( - fmt.Sprintf("./afterterm %s", graceperiod-50*time.Millisecond), + fmt.Sprintf("./afterterm %s", graceperiod-100*time.Millisecond), exechelper.WithContext(ctx), exechelper.WithGracePeriod(graceperiod), exechelper.WithStdout(os.Stdout), @@ -194,7 +194,7 @@ func TestWithGracePeriodWithContext(t *testing.T) { select { case err, ok = <-errCh: require.NoError(t, err) - case <-time.After(graceperiod + 50*time.Millisecond): + case <-time.After(graceperiod + 100*time.Millisecond): require.Failf(t, "", "failed to stop within graceperiod(%s): %s", graceperiod+50*time.Millisecond, time.Since(cancelTime)) ok = false } @@ -203,7 +203,7 @@ func TestWithGracePeriodWithContext(t *testing.T) { func TestWithGracePeriodExceeded(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - graceperiod := 200 * time.Millisecond + graceperiod := 500 * time.Millisecond err := exechelper.Run("go build ./testcmds/afterterm") require.NoError(t, err) errCh := exechelper.Start(