build_ydb_cli.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. name: Build-YDB-CLI
  2. run-name: Build YDB CLI
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. commit_sha:
  7. type: string
  8. default: ""
  9. build-linux-amd:
  10. type: boolean
  11. description: Build YDB CLI for Linux (amd64)
  12. default: true
  13. build-linux-arm:
  14. type: boolean
  15. description: Build YDB CLI for Linux (arm64)
  16. default: true
  17. build-darwin-amd:
  18. type: boolean
  19. description: Build YDB CLI for MacOS (amd64)
  20. default: true
  21. build-darwin-arm:
  22. type: boolean
  23. description: Build YDB CLI for MacOS (arm64)
  24. default: true
  25. build-windows-amd:
  26. type: boolean
  27. description: Build YDB CLI for Windows (amd64)
  28. default: true
  29. defaults:
  30. run:
  31. shell: bash
  32. jobs:
  33. build-matrix:
  34. name: Build platform matrix
  35. runs-on: ubuntu-latest
  36. outputs:
  37. matrix: ${{ steps.set-matrix.outputs.matrix }}
  38. steps:
  39. - name: Create file with future platform list
  40. id: set-matrix
  41. run: |
  42. MATRIX='{"include":[]}'
  43. if [ "${{ inputs.build-linux-amd }}" == "true" ]; then
  44. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "linux-amd", "runner": "ubuntu-latest", "shell": "bash", "binary": "ydb", "platform": "DEFAULT-LINUX-X86_64"}]')
  45. echo "Matrix after adding linux-amd: $MATRIX"
  46. fi
  47. if [ "${{ inputs.build-linux-arm }}" == "true" ]; then
  48. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "linux-arm", "runner": "ubuntu-latest", "shell": "bash", "binary": "ydb", "platform": "DEFAULT-LINUX-AARCH64"}]')
  49. echo "Matrix after adding linux-arm: $MATRIX"
  50. fi
  51. if [ "${{ inputs.build-darwin-amd }}" == "true" ]; then
  52. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "darwin-amd", "runner": "macos-13", "shell": "bash", "binary": "ydb", "platform": "DEFAULT-DARWIN-X86_64"}]')
  53. echo "Matrix after adding darwin-amd: $MATRIX"
  54. fi
  55. if [ "${{ inputs.build-darwin-arm }}" == "true" ]; then
  56. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "darwin-arm", "runner": "macos-13", "shell": "bash", "binary": "ydb", "platform": "DEFAULT-DARWIN-ARM64"}]')
  57. echo "Matrix after adding darwin-arm: $MATRIX"
  58. fi
  59. if [ "${{ inputs.build-windows-amd }}" == "true" ]; then
  60. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "windows-amd", "runner": "windows-latest", "shell": "bash", "binary": "ydb.exe", "platform": "DEFAULT-WIN-X86_64"}]')
  61. echo "Matrix after adding windows-amd: $MATRIX"
  62. fi
  63. echo "Final output matrix: $MATRIX"
  64. echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
  65. MATRIX=$(echo $MATRIX | jq '.')
  66. echo "Final pretty printed matrix: $MATRIX"
  67. echo "Platform matrix: $MATRIX" >> "$GITHUB_STEP_SUMMARY"
  68. build-platform-specific-binary:
  69. strategy:
  70. matrix: ${{ fromJSON(needs.build-matrix.outputs.matrix) }}
  71. name: Build ${{ matrix.os }} binary
  72. needs: build-matrix
  73. runs-on: ${{ matrix.runner }}
  74. defaults:
  75. run:
  76. shell: ${{ matrix.shell }}
  77. steps:
  78. - name: Checkout
  79. uses: actions/checkout@v4
  80. with:
  81. ref: ${{ inputs.commit_sha }}
  82. - name: Print debug information
  83. run: |
  84. uname -a
  85. echo "YDB CLI version: $(cat ydb/apps/ydb/version.txt) (read from ydb/apps/ydb/version.txt)"
  86. # Turns out it is crucial to prepare VS environment and build in one step due to env variable visibility
  87. - name: Prepare Visual Studio environment and build windows binary with ya make
  88. if: ${{ matrix.os == 'windows-amd' }}
  89. shell: cmd
  90. run: ${{ '"%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=amd64' }} && python ya make ydb/apps/ydb -r -DUSE_SSE4=no -o ./
  91. - name: Build unix binary with ya make
  92. if: ${{ matrix.os != 'windows-amd' }}
  93. run: ./ya make ydb/apps/ydb -r -DUSE_SSE4=no --target-platform ${{ matrix.platform }}
  94. - name: Upload binary to artifact
  95. uses: actions/upload-artifact@v4
  96. with:
  97. name: ${{ matrix.os }}-binary
  98. path: ydb/apps/ydb/${{ matrix.binary }}
  99. if-no-files-found: error
  100. retention-days: 1
  101. gather-and-push-to-s3:
  102. name: Gather built binaries and push to s3
  103. needs: build-platform-specific-binary
  104. runs-on: ubuntu-latest
  105. steps:
  106. - name: Checkout
  107. uses: actions/checkout@v4
  108. with:
  109. ref: ${{ inputs.commit_sha }}
  110. - name: Get YDB CLI version from ydb/apps/ydb/version.txt
  111. id: getver
  112. run: echo "cli_version=$(cat ydb/apps/ydb/version.txt)" >> $GITHUB_OUTPUT
  113. - name: Print YDB CLI version ${{ steps.getver.outputs.cli_version }}
  114. run: echo ${{ steps.getver.outputs.cli_version }}
  115. - name: Prepare directory for linux-amd binary
  116. if: ${{ inputs.build-linux-amd }}
  117. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/linux/amd64
  118. - name: Prepare directory for linux-arm binary
  119. if: ${{ inputs.build-linux-arm }}
  120. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/linux/arm64
  121. - name: Prepare directory for darwin-amd binary
  122. if: ${{ inputs.build-darwin-amd }}
  123. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/darwin/amd64
  124. - name: Prepare directory for darwin-arm binary
  125. if: ${{ inputs.build-darwin-arm }}
  126. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/darwin/arm64
  127. - name: Prepare directory for windows-amd binary
  128. if: ${{ inputs.build-windows-amd }}
  129. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/windows/amd64/unsigned
  130. - name: Copy linux-amd binary
  131. if: ${{ inputs.build-linux-amd }}
  132. uses: actions/download-artifact@v4
  133. with:
  134. name: linux-amd-binary
  135. path: ${{ steps.getver.outputs.cli_version }}/linux/amd64/
  136. - name: Copy linux-arm binary
  137. if: ${{ inputs.build-linux-arm }}
  138. uses: actions/download-artifact@v4
  139. with:
  140. name: linux-arm-binary
  141. path: ${{ steps.getver.outputs.cli_version }}/linux/arm64/
  142. - name: Copy darwin amd64 binary
  143. if: ${{ inputs.build-darwin-amd }}
  144. uses: actions/download-artifact@v4
  145. with:
  146. name: darwin-amd-binary
  147. path: ${{ steps.getver.outputs.cli_version }}/darwin/amd64/
  148. - name: Copy darwin arm64 binary
  149. if: ${{ inputs.build-darwin-arm }}
  150. uses: actions/download-artifact@v4
  151. with:
  152. name: darwin-arm-binary
  153. path: ${{ steps.getver.outputs.cli_version }}/darwin/arm64/
  154. - name: Copy windows-amd binary (unsigned)
  155. if: ${{ inputs.build-windows-amd }}
  156. uses: actions/download-artifact@v4
  157. with:
  158. name: windows-amd-binary
  159. path: ${{ steps.getver.outputs.cli_version }}/windows/amd64/unsigned/
  160. - name: Print resulting file hierarchy
  161. run: find ${{ steps.getver.outputs.cli_version }} | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
  162. - name: Download s3
  163. run: wget https://github.com/s3tools/s3cmd/releases/download/v2.4.0/s3cmd-2.4.0.tar.gz
  164. - name: Unzip s3
  165. run: tar -xf s3cmd-2.4.0.tar.gz
  166. - name: Install s3
  167. run: |
  168. cd s3cmd-2.4.0
  169. sudo python3 setup.py install
  170. cd ..
  171. - name: Upload to S3
  172. env:
  173. S3_HOST: "storage.yandexcloud.net"
  174. S3_BUCKET: "yandexcloud-ydb"
  175. S3_DNS_HOST_BUCKET: "%(bucket)s.storage.yandexcloud.net"
  176. S3_REGION: ru-central1
  177. run: s3cmd --access_key=${{ secrets.CLI_S3_KEY_ID }} --secret_key=${{ secrets.CLI_S3_KEY_SECRET_ID }} --host="$S3_HOST" --host-bucket="$S3_DNS_HOST_BUCKET" --region="$S3_REGION" sync --recursive ${{ steps.getver.outputs.cli_version }} "s3://$S3_BUCKET/release/"