Эх сурвалжийг харах

Migrate to GitHub Actions

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Andrea Barberio 4 жил өмнө
parent
commit
77079c4798

+ 0 - 0
.travis/checklicenses_config.json → .ci/checklicenses_config.json


+ 0 - 0
.travis/setup-integ.sh → .ci/setup-integ.sh


+ 0 - 0
.travis/tests.sh → .ci/tests.sh


+ 63 - 0
.github/workflows/build.yml

@@ -0,0 +1,63 @@
+name: Build
+
+on: [push, pull_request]
+
+jobs:
+  coredhcp:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go: ['1.14', '1.15']
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          # clone in the gopath
+          path: src/github.com/${{ github.repository }}
+      - uses: actions/setup-go@v2
+        with:
+          stable: false
+          go-version: ${{ matrix.go }}
+      - name: setup environment
+        run: |
+          # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
+          # trick.
+          echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
+          echo "GO111MODULE=on" >> $GITHUB_ENV
+      - name: build coredhcp
+        run: |
+          set -exu
+          cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}/cmds/coredhcp
+          go build
+  coredhcp-generator:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go: ['1.14', '1.15']
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          # clone in the gopath
+          path: src/github.com/${{ github.repository }}
+      - uses: actions/setup-go@v2
+        with:
+          stable: false
+          go-version: ${{ matrix.go }}
+      - name: setup environment
+        run: |
+          # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
+          # trick.
+          echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
+          echo "GOBIN=$GITHUB_WORKSPACE/bin" >> $GITHUB_ENV
+          echo "GO111MODULE=off" >> $GITHUB_ENV # until we solve this for coredhcp-generator
+      - name: build coredhcp-generator
+        run: |
+          set -exu
+          cd "${GITHUB_WORKSPACE}"/src/github.com/${{ github.repository }}/cmds/coredhcp-generator
+          GO111MODULE=on go build
+          builddir=$(./coredhcp-generator -f core-plugins.txt)
+          cd "${builddir}"
+          ls -l
+          go get -v ./...
+          go build
+          gofmt -w "${builddir}/coredhcp.go"
+          diff -u "${builddir}/coredhcp.go" "${GITHUB_WORKSPACE}"/src/github.com/${{ github.repository }}/cmds/coredhcp/main.go

+ 39 - 0
.github/workflows/lint.yml

@@ -0,0 +1,39 @@
+name: Lint
+
+on:
+  push:
+    tags:
+      - v*
+    branches:
+      - master
+  pull_request:
+
+jobs:
+  golangci:
+    name: golangci-lint
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: golangci-lint
+        uses: golangci/golangci-lint-action@v2
+        with:
+          version: v1.29
+
+          # Optional: golangci-lint command line arguments.
+          # args: --issues-exit-code=0
+
+          # Optional: show only new issues if it's a pull request. The default value is `false`.
+          # only-new-issues: true
+
+          # Optional: if set to true then the action will use pre-installed Go
+          # skip-go-installation: true
+  checklicenses:
+    name: checklicenses
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: check license headers
+        run: |
+          set -exu
+          go get -u github.com/u-root/u-root/tools/checklicenses
+          $(go env GOPATH)/bin/checklicenses -c .ci/checklicenses_config.json

+ 74 - 0
.github/workflows/tests.yml

@@ -0,0 +1,74 @@
+name: Tests
+
+on: [push, pull_request]
+
+jobs:
+  unit-tests:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go: ['1.14', '1.15']
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          # clone in the gopath
+          path: src/github.com/${{ github.repository }}
+      - uses: actions/setup-go@v2
+        with:
+          stable: false
+          go-version: ${{ matrix.go }}
+      - run: |
+          # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
+          # trick.
+          echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
+          echo "GO111MODULE=on" >> $GITHUB_ENV
+      - name: run unit tests
+        run: |
+          cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
+          go get -v -t ./...
+          echo "" > coverage.txt
+          for d in $(go list ./...); do
+              go test -v -race -coverprofile=profile.out -covermode=atomic "${d}"
+              if [ -f profile.out ]; then
+                cat profile.out >> coverage.txt
+                rm profile.out
+              fi
+          done
+      - name: report to codecov
+        run: bash <(curl -s https://codecov.io/bash) -c -f coverage.txt -F unittest
+  integration-tests:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        go: ['1.14', '1.15']
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          # clone in the gopath
+          path: src/github.com/${{ github.repository }}
+      - uses: actions/setup-go@v2
+        with:
+          stable: false
+          go-version: ${{ matrix.go }}
+      - run: |
+          # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
+          # trick.
+          echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
+          echo "GO111MODULE=on" >> $GITHUB_ENV
+      - name: run integ tests
+        run: |
+          cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
+          go get -v -t ./...
+          echo "" > coverage.txt
+          for d in $(go list ./...); do
+              go test -c -tags=integration -v -race -coverprofile=profile.out -covermode=atomic "${d}"
+              testbin="./$(basename $d).test"
+              # only run it if it was built - i.e. if there are integ tests
+              test -x "${testbin}" && sudo "./${testbin}"
+              if [ -f profile.out ]; then
+                cat profile.out >> coverage.txt
+                rm profile.out
+              fi
+          done
+      - name: report to codecov
+        run: bash <(curl -s https://codecov.io/bash) -c -f coverage.txt -F integtest

+ 1 - 0
.gitignore

@@ -6,3 +6,4 @@ cmds/coredhcp/coredhcp
 cmds/client/client
 cmds/coredhcp-generator/coredhcp-generator
 .vscode
+coverage.txt

+ 0 - 40
.travis.yml

@@ -1,40 +0,0 @@
-language: go
-
-os: linux
-dist: bionic
-
-# The first element in this list will be the default for the non-matrix jobs,
-# so you usually want the latest version first
-go:
-  - 1.14.x
-  - 1.13.x
-  - master
-
-env:
-  global:
-    - GO111MODULE=on
-
-before_install:
-  - go get -t -v ./...
-  - go get -t -v github.com/stretchr/testify/...
-
-# This is the script for the matrix tests (ran with each version of go)
-script: |
-      ./.travis/setup-integ.sh
-      ./.travis/tests.sh
-
-after_success:
-  - bash <(curl -s https://codecov.io/bash)
-
-
-# These are individual jobs unrelated to the matrix tests
-jobs:
-  include:
-    - name: Generator/main entrypoint drift
-      script: ./.travis/check-generator-main.sh
-    - name: license headers
-      before_install: go get -u github.com/u-root/u-root/tools/checklicenses
-      script: checklicenses -c .travis/checklicenses_config.json
-    - name: golangci-lint
-      before_install: go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0
-      script: golangci-lint run

+ 0 - 12
.travis/check-generator-main.sh

@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-
-set -ex
-
-# Build the generator version
-pushd cmds/coredhcp-generator
-go build
-generated=$(./coredhcp-generator -from core-plugins.txt)/coredhcp.go
-popd
-
-gofmt -w $generated
-diff -u $generated cmds/coredhcp/main.go