go-tests.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ---
  2. # Ci code for building release artifacts.
  3. name: Go Tests
  4. on:
  5. push: # Master branch checks only validate the build and generate artifacts for testing.
  6. branches:
  7. - master
  8. pull_request: null # PR checks only validate the build and generate artifacts for testing.
  9. concurrency: # This keeps multiple instances of the job from running concurrently for the same ref and event type.
  10. group: go-test-${{ github.ref }}-${{ github.event_name }}
  11. cancel-in-progress: true
  12. jobs:
  13. file-check: # Check what files changed if we’re being run in a PR or on a push.
  14. name: Check Modified Files
  15. runs-on: ubuntu-latest
  16. outputs:
  17. run: ${{ steps.check-run.outputs.run }}
  18. steps:
  19. - name: Checkout
  20. id: checkout
  21. uses: actions/checkout@v4
  22. with:
  23. fetch-depth: 0
  24. submodules: recursive
  25. - name: Check files
  26. id: check-files
  27. uses: tj-actions/changed-files@v45
  28. with:
  29. since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
  30. files: |
  31. **/*.cmake
  32. CMakeLists.txt
  33. .github/workflows/go-tests.yml
  34. packaging/cmake/
  35. src/go/**
  36. files_ignore: |
  37. **/*.md
  38. src/go/**/metadata.yaml
  39. packaging/repoconfig/
  40. - name: List all changed files in pattern
  41. continue-on-error: true
  42. env:
  43. ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
  44. run: |
  45. for file in ${ALL_CHANGED_FILES}; do
  46. echo "$file was changed"
  47. done
  48. - name: Check Run
  49. id: check-run
  50. run: |
  51. if [ "${{ steps.check-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  52. echo 'run=true' >> "${GITHUB_OUTPUT}"
  53. else
  54. echo 'run=false' >> "${GITHUB_OUTPUT}"
  55. fi
  56. matrix:
  57. name: Generate Build Matrix
  58. runs-on: ubuntu-latest
  59. outputs:
  60. matrix: ${{ steps.get-version.outputs.matrix }}
  61. steps:
  62. - name: Checkout
  63. uses: actions/checkout@v4
  64. - name: Install dependencies
  65. run: |
  66. sudo apt-get update || true
  67. sudo apt-get install -y python3-packaging
  68. - name: Get Go version and modules
  69. id: get-version
  70. run: .github/scripts/get-go-version.py
  71. tests:
  72. name: Go toolchain tests
  73. runs-on: ubuntu-latest
  74. needs:
  75. - file-check
  76. - matrix
  77. strategy:
  78. fail-fast: false
  79. matrix:
  80. include: ${{ fromJson(needs.matrix.outputs.matrix) }}
  81. steps:
  82. - name: Skip Check
  83. id: skip
  84. if: needs.file-check.outputs.run != 'true'
  85. run: echo "SKIPPED"
  86. - name: Install Go
  87. uses: actions/setup-go@v5
  88. with:
  89. go-version: ${{ matrix.version }}
  90. - name: Checkout
  91. if: needs.file-check.outputs.run == 'true'
  92. uses: actions/checkout@v4
  93. with:
  94. submodules: recursive
  95. - name: Go mod download
  96. if: needs.file-check.outputs.run == 'true'
  97. run: go mod download
  98. working-directory: ${{ matrix.module }}
  99. - name: Compile
  100. if: needs.file-check.outputs.run == 'true'
  101. run: |
  102. CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
  103. /tmp/go-test-build --help || true
  104. working-directory: ${{ matrix.module }}
  105. - name: Go fmt
  106. if: needs.file-check.outputs.run == 'true'
  107. run: |
  108. go fmt ./... | tee modified-files
  109. [ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
  110. working-directory: ${{ matrix.module }}
  111. - name: Go vet
  112. if: needs.file-check.outputs.run == 'true'
  113. run: go vet ./...
  114. working-directory: ${{ matrix.module }}
  115. - name: Set up gotestfmt
  116. if: needs.file-check.outputs.run == 'true'
  117. uses: GoTestTools/gotestfmt-action@v2
  118. with:
  119. token: ${{ secrets.GITHUB_TOKEN }}
  120. version: v2.0.0
  121. - name: Go test
  122. if: needs.file-check.outputs.run == 'true'
  123. run: |
  124. set -euo pipefail
  125. go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
  126. working-directory: ${{ matrix.module }}
  127. build-tests:
  128. name: Go build tests
  129. runs-on: ubuntu-latest
  130. needs:
  131. - file-check
  132. - matrix
  133. strategy:
  134. fail-fast: false
  135. matrix:
  136. platforms:
  137. - linux/386
  138. - linux/amd64
  139. - linux/arm
  140. - linux/arm64
  141. - linux/ppc64le
  142. - windows/amd64
  143. include: ${{ fromJson(needs.matrix.outputs.matrix) }}
  144. steps:
  145. - name: Skip Check
  146. id: skip
  147. if: needs.file-check.outputs.run != 'true'
  148. run: echo "SKIPPED"
  149. - name: Install Go
  150. uses: actions/setup-go@v5
  151. with:
  152. go-version: ${{ matrix.version }}
  153. - name: Checkout
  154. if: needs.file-check.outputs.run == 'true'
  155. uses: actions/checkout@v4
  156. with:
  157. submodules: recursive
  158. - name: Set GOOS and GOARCH
  159. run: |
  160. echo "GOOS=$(echo "${{ matrix.platform }}" | cut -f 1 -d '/')" >> "${GITHUB_ENV}"
  161. echo "GOARCH=$(echo "${{ matrix.platform }}" | cut -f 2 -d '/')" >> "${GITHUB_ENV}"
  162. - name: Go mod download
  163. if: needs.file-check.outputs.run == 'true'
  164. run: go mod download
  165. working-directory: ${{ matrix.module }}
  166. - name: Compile
  167. if: needs.file-check.outputs.run == 'true'
  168. run: |
  169. CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
  170. working-directory: ${{ matrix.module }}