go-tests.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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@v44
  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. - name: List all changed files in pattern
  40. continue-on-error: true
  41. env:
  42. ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
  43. run: |
  44. for file in ${ALL_CHANGED_FILES}; do
  45. echo "$file was changed"
  46. done
  47. - name: Check Run
  48. id: check-run
  49. run: |
  50. if [ "${{ steps.check-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  51. echo 'run=true' >> "${GITHUB_OUTPUT}"
  52. else
  53. echo 'run=false' >> "${GITHUB_OUTPUT}"
  54. fi
  55. matrix:
  56. name: Generate Build Matrix
  57. runs-on: ubuntu-latest
  58. outputs:
  59. matrix: ${{ steps.get-version.outputs.matrix }}
  60. steps:
  61. - name: Checkout
  62. uses: actions/checkout@v4
  63. - name: Install dependencies
  64. run: |
  65. sudo apt-get update || true
  66. sudo apt-get install -y python3-packaging
  67. - name: Get Go version and modules
  68. id: get-version
  69. run: .github/scripts/get-go-version.py
  70. tests:
  71. name: Go toolchain tests
  72. runs-on: ubuntu-latest
  73. needs:
  74. - file-check
  75. - matrix
  76. strategy:
  77. fail-fast: false
  78. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  79. steps:
  80. - name: Skip Check
  81. id: skip
  82. if: needs.file-check.outputs.run != 'true'
  83. run: echo "SKIPPED"
  84. - name: Install Go
  85. uses: actions/setup-go@v5
  86. with:
  87. go-version: ${{ matrix.version }}
  88. - name: Checkout
  89. if: needs.file-check.outputs.run == 'true'
  90. uses: actions/checkout@v4
  91. with:
  92. submodules: recursive
  93. - name: Go mod download
  94. if: needs.file-check.outputs.run == 'true'
  95. run: go mod download
  96. working-directory: ${{ matrix.module }}
  97. - name: Compile
  98. if: needs.file-check.outputs.run == 'true'
  99. run: |
  100. CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
  101. /tmp/go-test-build --help || true
  102. working-directory: ${{ matrix.module }}
  103. - name: Go fmt
  104. if: needs.file-check.outputs.run == 'true'
  105. run: |
  106. go fmt ./... | tee modified-files
  107. [ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
  108. working-directory: ${{ matrix.module }}
  109. - name: Go vet
  110. if: needs.file-check.outputs.run == 'true'
  111. run: go vet ./...
  112. working-directory: ${{ matrix.module }}
  113. - name: Set up gotestfmt
  114. if: needs.file-check.outputs.run == 'true'
  115. uses: GoTestTools/gotestfmt-action@v2
  116. with:
  117. token: ${{ secrets.GITHUB_TOKEN }}
  118. version: v2.0.0
  119. - name: Go test
  120. if: needs.file-check.outputs.run == 'true'
  121. run: |
  122. set -euo pipefail
  123. go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
  124. working-directory: ${{ matrix.module }}