build_ydb_cli.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. name: Build-YDB-CLI
  2. run-name: Build YDB CLI
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. build-linux:
  7. type: boolean
  8. description: Build YDB CLI for Linux
  9. default: true
  10. build-darwin-amd:
  11. type: boolean
  12. description: Build YDB CLI for Darwin amd64
  13. default: true
  14. build-windows:
  15. type: boolean
  16. description: Build YDB CLI for Windows
  17. default: true
  18. commit_sha:
  19. type: string
  20. default: ""
  21. s3_host:
  22. type: string
  23. default: "storage.yandexcloud.net"
  24. description: "S3 endpoint. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
  25. s3_bucket:
  26. type: string
  27. default: "yandexcloud-ydb"
  28. description: "S3 bucket. S3Uri (without hostname). Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
  29. s3_dns_host_bucket:
  30. type: string
  31. default: "%(bucket)s.storage.yandexcloud.net"
  32. description: "S3 DNS-style bucket+hostname:port template for accessing a bucket. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
  33. s3_region:
  34. type: string
  35. default: "ru-central1"
  36. description: "S3 region. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
  37. defaults:
  38. run:
  39. shell: bash
  40. jobs:
  41. build-matrix:
  42. name: Build platform matrix
  43. runs-on: ubuntu-latest
  44. outputs:
  45. matrix: ${{ steps.set-matrix.outputs.matrix }}
  46. steps:
  47. - name: Create file with future platform list
  48. id: set-matrix
  49. run: |
  50. MATRIX='{"include":[]}'
  51. if [ "${{ inputs.build-linux }}" == "true" ]; then
  52. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "linux", "runner": "ubuntu-latest", "shell": "bash", "binary": "ydb"}]')
  53. echo "Matrix after adding linux: $MATRIX"
  54. fi
  55. if [ "${{ inputs.build-darwin-amd }}" == "true" ]; then
  56. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "darwin-amd", "runner": "macos-13", "shell": "bash", "binary": "ydb"}]')
  57. echo "Matrix after adding darwin-amd: $MATRIX"
  58. fi
  59. if [ "${{ inputs.build-windows }}" == "true" ]; then
  60. MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "windows", "runner": "windows-latest", "shell": "bash", "binary": "ydb.exe"}]')
  61. echo "Matrix after adding windows: $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 }} YDB CLI 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. cat 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' }}
  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' }}
  93. run: ./ya make ydb/apps/ydb -r -DUSE_SSE4=no
  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 binary
  116. if: ${{ inputs.build-linux }}
  117. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/linux/amd64
  118. - name: Prepare directory for Darwin amd binary
  119. if: ${{ inputs.build-darwin-amd }}
  120. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/darwin/amd64
  121. - name: Prepare directory for Windows binary
  122. if: ${{ inputs.build-windows }}
  123. run: mkdir -p ${{ steps.getver.outputs.cli_version }}/windows/amd64/unsigned
  124. - name: Copy linux binary
  125. if: ${{ inputs.build-linux }}
  126. uses: actions/download-artifact@v4
  127. with:
  128. name: linux-binary
  129. path: ${{ steps.getver.outputs.cli_version }}/linux/amd64/
  130. - name: Copy darwin amd64 binary
  131. if: ${{ inputs.build-darwin-amd }}
  132. uses: actions/download-artifact@v4
  133. with:
  134. name: darwin-amd-binary
  135. path: ${{ steps.getver.outputs.cli_version }}/darwin/amd64/
  136. - name: Copy windows binary (unsigned)
  137. if: ${{ inputs.build-windows }}
  138. uses: actions/download-artifact@v4
  139. with:
  140. name: windows-binary
  141. path: ${{ steps.getver.outputs.cli_version }}/windows/amd64/unsigned/
  142. - name: Print resulting file hierarchy
  143. run: find ${{ steps.getver.outputs.cli_version }} | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
  144. - name: Download s3
  145. run: wget https://github.com/s3tools/s3cmd/releases/download/v2.4.0/s3cmd-2.4.0.tar.gz
  146. - name: Unzip s3
  147. run: tar -xf s3cmd-2.4.0.tar.gz
  148. - name: Install s3
  149. run: |
  150. cd s3cmd-2.4.0
  151. sudo python3 setup.py install
  152. cd ..
  153. - name: Upload to S3
  154. run: s3cmd --access_key=${{ secrets.CLI_S3_KEY_ID }} --secret_key=${{ secrets.CLI_S3_KEY_SECRET_ID }} --host=${{ inputs.s3_host }} --host-bucket="${{ inputs.s3_dns_host_bucket }}" --region=${{ inputs.s3_region }} sync --recursive ${{ steps.getver.outputs.cli_version }} s3://${{ inputs.s3_bucket }}/release/