go-tests.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: ${{ fromJson(needs.matrix.outputs.matrix) }}
  80. steps:
  81. - name: Skip Check
  82. id: skip
  83. if: needs.file-check.outputs.run != 'true'
  84. run: echo "SKIPPED"
  85. - name: Install Go
  86. uses: actions/setup-go@v5
  87. with:
  88. go-version: ${{ matrix.version }}
  89. - name: Checkout
  90. if: needs.file-check.outputs.run == 'true'
  91. uses: actions/checkout@v4
  92. with:
  93. submodules: recursive
  94. - name: Go mod download
  95. if: needs.file-check.outputs.run == 'true'
  96. run: go mod download
  97. working-directory: ${{ matrix.module }}
  98. - name: Compile
  99. if: needs.file-check.outputs.run == 'true'
  100. run: |
  101. CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
  102. /tmp/go-test-build --help || true
  103. working-directory: ${{ matrix.module }}
  104. - name: Go fmt
  105. if: needs.file-check.outputs.run == 'true'
  106. run: |
  107. go fmt ./... | tee modified-files
  108. [ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
  109. working-directory: ${{ matrix.module }}
  110. - name: Go vet
  111. if: needs.file-check.outputs.run == 'true'
  112. run: go vet ./...
  113. working-directory: ${{ matrix.module }}
  114. - name: Set up gotestfmt
  115. if: needs.file-check.outputs.run == 'true'
  116. uses: GoTestTools/gotestfmt-action@v2
  117. with:
  118. token: ${{ secrets.GITHUB_TOKEN }}
  119. version: v2.0.0
  120. - name: Go test
  121. if: needs.file-check.outputs.run == 'true'
  122. run: |
  123. set -euo pipefail
  124. go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
  125. working-directory: ${{ matrix.module }}