build.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. on:
  5. push:
  6. branches: [ main ]
  7. pull_request:
  8. branches: [ main ]
  9. jobs:
  10. core:
  11. runs-on: ubuntu-latest
  12. strategy:
  13. fail-fast: false
  14. matrix:
  15. # Looking at https://hub.docker.com/_/swift, the version only tags (i.e.
  16. # - 5.9.2) can use different Ubuntu releases. But just to be safe we use
  17. # the specific OS release.
  18. #
  19. # We could use less specific tags (i.e. - 5.9), so they "float" as
  20. # new point release come, but to help make history/logs more clear,
  21. # being explicit (at the cost of having to update with point releases)
  22. # seems better. This should also ensure protobuf caching changes with
  23. # each new image incase system in the Swift image are changed/updated.
  24. swift:
  25. - version: 6.1.0-noble
  26. hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
  27. - version: 6.0.3-noble
  28. hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
  29. - version: 5.10.1-noble
  30. # No "hook", see https://github.com/apple/swift-protobuf/issues/1560 for the
  31. # current issue with using -warnings-as-errors on linux.
  32. # protobuf_git can reference a commit, tag, or branch
  33. # commit: "commits/6935eae45c99926a000ecbef0be20dfd3d159e71"
  34. # tag: "ref/tags/v3.11.4"
  35. # branch: "ref/heads/main"
  36. protobuf_git: ["ref/heads/main"]
  37. container:
  38. image: swift:${{ matrix.swift.version }}
  39. steps:
  40. - name: Checkout
  41. uses: actions/checkout@v4
  42. with:
  43. path: swift-protobuf
  44. - name: Update and install dependencies
  45. # dependencies from https://github.com/protocolbuffers/protobuf/blob/main/src/README.md
  46. # this step is run before get-sha because we need curl and jq for get-sha
  47. run: apt-get update && apt-get install -y curl make g++ cmake jq
  48. - name: Get Protobuf Commit SHA
  49. id: get-sha
  50. run: |
  51. set -eu
  52. url="https://api.github.com/repos/protocolbuffers/protobuf/git/${{ matrix.protobuf_git }}"
  53. case ${{ matrix.protobuf_git }} in
  54. ref/*)
  55. echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .object.sha )" >> $GITHUB_OUTPUT
  56. ;;
  57. commits/*)
  58. echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .sha )" >> $GITHUB_OUTPUT
  59. ;;
  60. esac
  61. - name: Build
  62. working-directory: swift-protobuf
  63. run: make build ${{ matrix.swift.hook }}
  64. - name: Test runtime
  65. working-directory: swift-protobuf
  66. run: make test-runtime ${{ matrix.swift.hook }}
  67. - name: Cache protobuf
  68. id: cache-protobuf
  69. uses: actions/cache@v4
  70. with:
  71. path: protobuf
  72. # NOTE: for refs that can float like 'main' the cache might be out of date!
  73. key: ${{ runner.os }}-${{ matrix.swift.version}}-protobuf-${{ steps.get-sha.outputs.sha }}
  74. - name: Checkout protobuf repo
  75. if: steps.cache-protobuf.outputs.cache-hit != 'true'
  76. uses: actions/checkout@v4
  77. with:
  78. repository: protocolbuffers/protobuf
  79. ref: ${{ steps.get-sha.outputs.sha }}
  80. submodules: true
  81. path: protobuf
  82. - name: Build protobuf
  83. if: steps.cache-protobuf.outputs.cache-hit != 'true'
  84. working-directory: protobuf
  85. # https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md#c-version
  86. run: |
  87. mkdir cmake_build
  88. cd cmake_build
  89. cmake \
  90. -DCMAKE_CXX_STANDARD=17 \
  91. -DCMAKE_BUILD_TYPE=Release \
  92. -Dprotobuf_BUILD_TESTS=OFF \
  93. -Dprotobuf_INSTALL=OFF \
  94. -Dprotobuf_BUILD_CONFORMANCE=ON \
  95. -S ..
  96. NUM_CPUS=$(getconf _NPROCESSORS_ONLN)
  97. make -j "${NUM_CPUS}" protoc conformance_test_runner
  98. - name: Test plugin
  99. working-directory: swift-protobuf
  100. run: make test-plugin PROTOC=../protobuf/cmake_build/protoc
  101. - name: Test conformance
  102. working-directory: swift-protobuf
  103. run: make test-conformance CONFORMANCE_TEST_RUNNER=../protobuf/cmake_build/conformance_test_runner
  104. - name: Test SPM plugin
  105. working-directory: swift-protobuf
  106. run: make test-spm-plugin PROTOC=../protobuf/cmake_build/protoc
  107. - name: Compilation Tests
  108. working-directory: swift-protobuf
  109. run: make compile-tests PROTOC=../protobuf/cmake_build/protoc
  110. api-breakage:
  111. name: Api Breakage Compared to main branch
  112. # Only on pull requests
  113. if: github.event_name == 'pull_request'
  114. runs-on: ubuntu-latest
  115. container:
  116. # Test on the latest Swift release. This could run on all the support
  117. # Swift versions, but that doesn't seem worth it until there are Swift
  118. # version specific conditionals to justify it.
  119. image: swift:latest
  120. steps:
  121. - name: Checkout
  122. uses: actions/checkout@v4
  123. with:
  124. fetch-depth: 0
  125. - name: Mark the workspace as safe
  126. # https://github.com/actions/checkout/issues/766
  127. run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
  128. - name: Check for API breaking changes
  129. run: swift package diagnose-api-breaking-changes origin/main
  130. format-check:
  131. name: swift-format Check
  132. # Only on pull requests
  133. if: github.event_name == 'pull_request'
  134. runs-on: ubuntu-latest
  135. container:
  136. # Use use the latest Swift release and that's the version of swift-format
  137. # people should use.
  138. image: swift:latest
  139. steps:
  140. - name: Checkout
  141. uses: actions/checkout@v4
  142. - name: Mark the workspace as safe
  143. # https://github.com/actions/checkout/issues/766
  144. run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
  145. - name: Run format check
  146. run: |
  147. set -eu
  148. git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
  149. GIT_PAGER='' git diff --exit-code '*.swift'
  150. # Disabled as it produces multiple warnings at the moment.
  151. # - name: Run format lint check
  152. # run: |
  153. # set -eu
  154. # git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
  155. sanitizer_testing:
  156. runs-on: ubuntu-latest
  157. strategy:
  158. fail-fast: false
  159. matrix:
  160. sanitizer: ["address", "thread"]
  161. swiftpm_config: ["debug", "release"]
  162. container:
  163. # Test on the latest Swift release.
  164. image: swift:latest
  165. steps:
  166. - uses: actions/checkout@v4
  167. - name: Test
  168. run: |
  169. set -eu
  170. # Trim out the generate files that are just compile tests, they take a while to compile and
  171. # are covered in core instead.
  172. rm Tests/SwiftProtobufTests/generated_swift_names*
  173. # On linux, the tests seem to always see leaks that don't show up on macOS. Disable the
  174. # leak detection and just assume it is a Linux Swift issue. This still gets validation
  175. # for other memory errors. Maybe https://bugs.swift.org/browse/SR-6848.
  176. if [ "${{ matrix.sanitizer }}" = "address" ] ; then
  177. export ASAN_OPTIONS=detect_leaks=0
  178. fi
  179. # 'release' doesn't support @testable, force it on.
  180. if [ "${{ matrix.swiftpm_config }}" = "release" ] ; then
  181. EXTRAS="-Xswiftc -enable-testing"
  182. fi
  183. swift test -c ${{ matrix.swiftpm_config }} --sanitize=${{ matrix.sanitizer }} ${EXTRAS:-}
  184. fuzzing_regressions:
  185. runs-on: ubuntu-latest
  186. strategy:
  187. fail-fast: false
  188. matrix:
  189. swiftpm_config: ["debug", "release"]
  190. container:
  191. # Test on the latest Swift release.
  192. image: swift:latest
  193. steps:
  194. - uses: actions/checkout@v4
  195. - name: Build
  196. run: FuzzTesting/do_build.sh --${{ matrix.swiftpm_config }}-only --run-regressions