go-tests.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y python3-packaging
  65. - name: Get Go version and modules
  66. id: get-version
  67. run: .github/scripts/get-go-version.py
  68. tests:
  69. name: Go toolchain tests
  70. runs-on: ubuntu-latest
  71. needs:
  72. - file-check
  73. - matrix
  74. strategy:
  75. fail-fast: false
  76. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  77. steps:
  78. - name: Skip Check
  79. id: skip
  80. if: needs.file-check.outputs.run != 'true'
  81. run: echo "SKIPPED"
  82. - name: Install Go
  83. uses: actions/setup-go@v5
  84. with:
  85. go-version: ${{ matrix.version }}
  86. - name: Checkout
  87. if: needs.file-check.outputs.run == 'true'
  88. uses: actions/checkout@v4
  89. with:
  90. submodules: recursive
  91. - name: Go mod download
  92. if: needs.file-check.outputs.run == 'true'
  93. run: go mod download
  94. working-directory: ${{ matrix.module }}
  95. - name: Compile
  96. if: needs.file-check.outputs.run == 'true'
  97. run: |
  98. CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
  99. /tmp/go-test-build --help || true
  100. working-directory: ${{ matrix.module }}
  101. - name: Go fmt
  102. if: needs.file-check.outputs.run == 'true'
  103. run: |
  104. go fmt ./... | tee modified-files
  105. [ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
  106. working-directory: ${{ matrix.module }}
  107. - name: Go vet
  108. if: needs.file-check.outputs.run == 'true'
  109. run: go vet ./...
  110. working-directory: ${{ matrix.module }}
  111. - name: Set up gotestfmt
  112. if: needs.file-check.outputs.run == 'true'
  113. uses: GoTestTools/gotestfmt-action@v2
  114. with:
  115. token: ${{ secrets.GITHUB_TOKEN }}
  116. version: v2.0.0
  117. - name: Go test
  118. if: needs.file-check.outputs.run == 'true'
  119. run: |
  120. set -euo pipefail
  121. go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
  122. working-directory: ${{ matrix.module }}