diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..c2848454 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,58 @@ +on: + pull_request: + push: + schedule: + - cron: 0 4 * * * + +jobs: + maketest: + name: Test ${{ matrix.test_block }} + runs-on: ${{ matrix.os }} + env: + GOPATH: /home/runner/work/mgmt/mgmt/go + strategy: + matrix: + os: + - ubuntu-latest + # macos tests are currently failing in CI + #- macos-latest + go_version: + # minimum required and latest published go_version + #- 1.13 + - 1.15 + test_block: + - basic + - shell + #- race + + steps: + # Do not shallow fetch, will fail when building bindata/ + # The path can't be absolute, so we need to move it to the + # expected location later. + - name: Clone mgmt + uses: actions/checkout@v2 + with: + submodules: recursive + fetch-depth: 0 + path: ./go/src/github.com/purpleidea/mgmt + + - name: Install Go ${{ matrix.go_version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go_version }} + + # Install & configure ruby, fixes gem permissions error + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: head + + - name: Install dependencies + working-directory: ./go/src/github.com/purpleidea/mgmt + run: | + make deps + + - name: Run test + working-directory: ./go/src/github.com/purpleidea/mgmt + run: | + TEST_BLOCK="${{ matrix.test_block }}" make test diff --git a/test/util.sh b/test/util.sh index 3e026a5f..e6997a0f 100755 --- a/test/util.sh +++ b/test/util.sh @@ -22,12 +22,14 @@ TIMEOUT="$timeout --kill-after=360s --signal=QUIT 300s" in_ci() { if [ $# -eq 0 ]; then - test -n "$CI" -o -n "$TRAVIS" -o -n "$JENKINS_URL" + test -n "$CI" -o -n "$GITHUB_ACTION" -o -n "$TRAVIS" -o -n "$JENKINS_URL" return $? fi for var in "$@"; do case "$var" in + github) + test -n "$GITHUB_ACTION" && return 0;; travis) test "$TRAVIS" = "true" && return 0;; jenkins) @@ -40,7 +42,11 @@ in_ci() { } fail_test() { - echo -e "FAIL: $@" + if in_ci github; then + echo "::error::$@" + else + echo -e "FAIL: $@" + fi exit 1 } @@ -53,10 +59,14 @@ function run-test() { fold_start() { if in_ci travis; then echo -e "travis_fold:start:$1\033[33;1m${@:2}\033[0m" + elif in_ci github; then + echo "::group::$@" fi } fold_end() { if in_ci travis; then echo -e "\ntravis_fold:end:$1\r" + elif in_ci github; then + echo "::endgroup::" fi }