build.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. name: Build and Test
  2. # NOTE: If making changes to most of the steps, please also look to update
  3. # regular_conformance.yml also.
  4. permissions:
  5. contents: read
  6. on:
  7. push:
  8. branches: [ main ]
  9. pull_request:
  10. branches: [ main ]
  11. jobs:
  12. core:
  13. runs-on: ubuntu-latest
  14. strategy:
  15. fail-fast: false
  16. matrix:
  17. # We "float" the bug fix so we pick up new ones. This helps since the GitHub CI
  18. # is set to ensure the actions pass, thus updates are only needed when the
  19. # "major.minor" pairs changes.
  20. #
  21. # Looking at https://hub.docker.com/_/swift, the version only tags (i.e. - 6.1)
  22. # could use different Ubuntu releases. At the moment they are all the "noble",
  23. # which is also what would be desired, so we don't bother listing explicit ones.
  24. swift:
  25. - version: "6.2"
  26. hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
  27. - version: "6.1"
  28. hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
  29. - version: "6.0"
  30. hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
  31. - version: "5.10"
  32. # No "hook", see https://github.com/apple/swift-protobuf/issues/1560 for the
  33. # current issue with using -warnings-as-errors on linux.
  34. container:
  35. image: swift:${{ matrix.swift.version }}
  36. steps:
  37. - name: Checkout
  38. uses: actions/checkout@v4
  39. with:
  40. submodules: true
  41. - name: Update and install dependencies
  42. # dependencies from https://github.com/protocolbuffers/protobuf/blob/main/src/README.md
  43. run: apt-get update && apt-get install -y make g++ cmake
  44. - name: Build
  45. run: make build ${{ matrix.swift.hook }}
  46. - name: Test runtime
  47. run: make test-runtime ${{ matrix.swift.hook }}
  48. - name: Build protobuf
  49. working-directory: Sources/protobuf/protobuf
  50. # https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md#c-version
  51. run: |
  52. mkdir cmake_build
  53. cd cmake_build
  54. cmake \
  55. -DCMAKE_CXX_STANDARD=17 \
  56. -DCMAKE_BUILD_TYPE=Release \
  57. -Dprotobuf_BUILD_TESTS=OFF \
  58. -Dprotobuf_INSTALL=OFF \
  59. -Dprotobuf_BUILD_CONFORMANCE=ON \
  60. -S ..
  61. NUM_CPUS=$(getconf _NPROCESSORS_ONLN)
  62. make -j "${NUM_CPUS}" protoc conformance_test_runner
  63. - name: Test plugin
  64. run: make test-plugin PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
  65. - name: Test conformance
  66. run: make test-conformance CONFORMANCE_TEST_RUNNER=Sources/protobuf/protobuf/cmake_build/conformance_test_runner
  67. - name: Test SPM plugin
  68. run: make test-spm-plugin PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
  69. - name: Compilation Tests
  70. run: make compile-tests PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
  71. api-breakage:
  72. name: Api Breakage Compared to main branch
  73. # Only on pull requests
  74. if: github.event_name == 'pull_request'
  75. runs-on: ubuntu-latest
  76. container:
  77. # Test on the latest Swift release. This could run on all the support
  78. # Swift versions, but that doesn't seem worth it until there are Swift
  79. # version specific conditionals to justify it.
  80. image: swift:latest
  81. steps:
  82. - name: Checkout
  83. uses: actions/checkout@v4
  84. with:
  85. fetch-depth: 0
  86. submodules: true
  87. - name: Mark the workspace as safe
  88. # https://github.com/actions/checkout/issues/766
  89. run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
  90. - name: Check for API breaking changes
  91. run: swift package diagnose-api-breaking-changes origin/main
  92. format-check:
  93. name: swift-format Check
  94. # Only on pull requests
  95. if: github.event_name == 'pull_request'
  96. runs-on: ubuntu-latest
  97. container:
  98. # Use use the latest Swift release and that's the version of swift-format
  99. # people should use.
  100. image: swift:latest
  101. steps:
  102. - name: Checkout
  103. uses: actions/checkout@v4
  104. with:
  105. submodules: true
  106. - name: Mark the workspace as safe
  107. # https://github.com/actions/checkout/issues/766
  108. run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
  109. - name: Run format check
  110. run: |
  111. set -eu
  112. git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
  113. GIT_PAGER='' git diff --exit-code '*.swift'
  114. # Disabled as it produces multiple warnings at the moment.
  115. # - name: Run format lint check
  116. # run: |
  117. # set -eu
  118. # git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
  119. sanitizer_testing:
  120. runs-on: ubuntu-latest
  121. strategy:
  122. fail-fast: false
  123. matrix:
  124. sanitizer: ["address", "thread"]
  125. swiftpm_config: ["debug", "release"]
  126. exclude: # Excluded due to a clang crasher that is fixed in a more recent clang https://github.com/llvm/llvm-project/issues/95928
  127. - sanitizer: "address"
  128. swiftpm_config: "debug"
  129. container:
  130. # Test on the latest Swift release.
  131. image: swift:latest
  132. steps:
  133. - uses: actions/checkout@v4
  134. with:
  135. submodules: true
  136. - name: Test
  137. run: |
  138. set -eu
  139. # Trim out the generate files that are just compile tests, they take a while to compile and
  140. # are covered in core instead.
  141. rm Tests/SwiftProtobufTests/generated_swift_names*
  142. # On linux, the tests seem to always see leaks that don't show up on macOS. Disable the
  143. # leak detection and just assume it is a Linux Swift issue. This still gets validation
  144. # for other memory errors. Maybe https://bugs.swift.org/browse/SR-6848.
  145. if [ "${{ matrix.sanitizer }}" = "address" ] ; then
  146. export ASAN_OPTIONS=detect_leaks=0
  147. fi
  148. # 'release' doesn't support @testable, force it on.
  149. if [ "${{ matrix.swiftpm_config }}" = "release" ] ; then
  150. EXTRAS="-Xswiftc -enable-testing"
  151. fi
  152. swift test -c ${{ matrix.swiftpm_config }} --sanitize=${{ matrix.sanitizer }} ${EXTRAS:-}
  153. fuzzing_regressions:
  154. runs-on: ubuntu-latest
  155. strategy:
  156. fail-fast: false
  157. matrix:
  158. swiftpm_config: ["debug", "release"]
  159. container:
  160. # Test on the latest Swift release.
  161. image: swift:latest
  162. steps:
  163. - uses: actions/checkout@v4
  164. with:
  165. submodules: true
  166. - name: Build
  167. run: FuzzTesting/do_build.sh --${{ matrix.swiftpm_config }}-only --run-regressions