tests.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: Tests
  2. on: [push, pull_request]
  3. jobs:
  4. unit-tests:
  5. runs-on: ubuntu-latest
  6. strategy:
  7. matrix:
  8. go: ['1.20', '1.21']
  9. steps:
  10. - uses: actions/checkout@v4
  11. with:
  12. # clone in the gopath
  13. path: src/github.com/${{ github.repository }}
  14. fetch-depth: 0
  15. - uses: actions/setup-go@v5
  16. with:
  17. go-version: ${{ matrix.go }}
  18. - run: |
  19. # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
  20. # trick.
  21. echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  22. echo "GO111MODULE=on" >> $GITHUB_ENV
  23. - name: run unit tests
  24. run: |
  25. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  26. go get -v -t ./...
  27. echo "" > "${GITHUB_WORKSPACE}"/coverage.txt
  28. for d in $(go list ./...); do
  29. go test -v -race -coverprofile=profile.out -covermode=atomic "${d}"
  30. if [ -f profile.out ]; then
  31. cat profile.out >> "${GITHUB_WORKSPACE}"/coverage.txt
  32. rm profile.out
  33. fi
  34. done
  35. - name: report coverage to codecov
  36. uses: codecov/codecov-action@v4
  37. with:
  38. files: coverage.txt
  39. flags: unittests
  40. fail_ci_if_error: true
  41. verbose: true
  42. integration-tests:
  43. runs-on: ubuntu-latest
  44. strategy:
  45. matrix:
  46. go: ['1.20', '1.21']
  47. steps:
  48. - uses: actions/checkout@v4
  49. with:
  50. # clone in the gopath
  51. path: src/github.com/${{ github.repository }}
  52. fetch-depth: 0
  53. - uses: actions/setup-go@v5
  54. with:
  55. go-version: ${{ matrix.go }}
  56. - run: |
  57. # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
  58. # trick.
  59. echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  60. echo "GO111MODULE=on" >> $GITHUB_ENV
  61. - name: setup integ tests
  62. run: |
  63. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  64. ./.ci/setup-integ.sh
  65. - name: run integ tests
  66. run: |
  67. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}/integ
  68. go get -v -t -tags=integration ./...
  69. echo "" > "${GITHUB_WORKSPACE}"/coverage.txt
  70. for d in $(go list -tags=integration ./...); do
  71. go test -c -tags=integration -v -race -coverprofile=profile.out -covermode=atomic "${d}"
  72. testbin="./$(basename $d).test"
  73. # only run it if it was built - i.e. if there are integ tests
  74. test -x "${testbin}" && sudo "./${testbin}"
  75. if [ -f profile.out ]; then
  76. cat profile.out >> "${GITHUB_WORKSPACE}"/coverage.txt
  77. rm profile.out
  78. fi
  79. done
  80. - name: report coverage to codecov
  81. uses: codecov/codecov-action@v4
  82. with:
  83. files: coverage.txt
  84. flags: integtests
  85. fail_ci_if_error: true
  86. verbose: true