tests.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
  28. - name: report coverage to codecov
  29. uses: codecov/codecov-action@v4
  30. with:
  31. files: coverage.txt
  32. disable_search: true
  33. flags: unittests
  34. fail_ci_if_error: true
  35. verbose: true
  36. root_dir: ${{ github.workspace }}/src/github.com/${{ github.repository }}
  37. working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}
  38. env:
  39. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  40. integration-tests:
  41. runs-on: ubuntu-latest
  42. strategy:
  43. matrix:
  44. go: ['1.20', '1.21']
  45. steps:
  46. - uses: actions/checkout@v4
  47. with:
  48. # clone in the gopath
  49. path: src/github.com/${{ github.repository }}
  50. fetch-depth: 0
  51. - uses: actions/setup-go@v5
  52. with:
  53. go-version: ${{ matrix.go }}
  54. - run: |
  55. # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
  56. # trick.
  57. echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  58. echo "GO111MODULE=on" >> $GITHUB_ENV
  59. - name: setup integ tests
  60. run: |
  61. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  62. ./.ci/setup-integ.sh
  63. - name: run integ tests
  64. env:
  65. GOCOVERDIR: ${{github.workspace}}/.cover
  66. run: |
  67. mkdir $GOCOVERDIR
  68. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  69. go get -v -t -tags=integration ./integ/...
  70. for d in integ/*; do
  71. pushd "$d"
  72. go build -tags=integration -race -cover -coverpkg=github.com/coredhcp/coredhcp/... .
  73. testbin=$(basename $d)
  74. test -x "${testbin}" || echo "::error file=${d}::missing binary for integration test ${d}"
  75. # only run it if it was built - i.e. if there are integ tests
  76. test -x "${testbin}" && sudo --preserve-env=GOCOVERDIR "./${testbin}"
  77. if [ $? -ne 0 ]; then
  78. echo "::error file=${d}::Execution of integration tests for ${d} failed"
  79. fi
  80. popd
  81. done
  82. go tool covdata textfmt -i=$GOCOVERDIR -o=coverage.txt
  83. - name: report coverage to codecov
  84. uses: codecov/codecov-action@v4
  85. with:
  86. files: coverage.txt
  87. disable_search: true
  88. flags: integtests
  89. fail_ci_if_error: true
  90. verbose: true
  91. root_dir: ${{ github.workspace }}/src/github.com/${{ github.repository }}
  92. working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}
  93. env:
  94. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}