aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/build_ydb_dstool.yml
blob: f7e79837bbb4bcf0c7e76d51284ba618454d082c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Build-YDB-DSTool
run-name: Build YDB DSTool
on:
  workflow_dispatch:
    inputs:
      build-linux:
        type: boolean
        description: Build YDB DSTool for Linux
        default: true
      build-darwin-amd:
        type: boolean
        description: Build YDB DSTool for Darwin amd64
        default: true
      build-windows:
        type: boolean
        description: Build YDB DSTool for Windows
        default: true
      commit_sha:
        type: string
        default: ""
      s3_host:
        type: string
        default: "storage.yandexcloud.net"
        description: "S3 endpoint. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
      s3_bucket:
        type: string
        default: "yandexcloud-ydb-dstool"
        description: "S3 bucket. S3Uri (without hostname). Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
      s3_dns_host_bucket:
        type: string
        default: "%(bucket)s.storage.yandexcloud.net"
        description: "S3 DNS-style bucket+hostname:port template for accessing a bucket. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
      s3_region:
        type: string
        default: "ru-central1"
        description: "S3 region. Details: https://yandex.cloud/en/docs/storage/tools/s3cmd"
defaults:
  run:
    shell: bash

jobs:
  build-matrix:
    name: Build platform matrix
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Create file with future platform list
        id: set-matrix
        run: |
          MATRIX='{"include":[]}'
          if [ "${{ inputs.build-linux }}" == "true" ]; then
            MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "linux", "runner": "ubuntu-latest", "shell": "bash", "binary": "ydb-dstool"}]')
            echo "Matrix after adding linux: $MATRIX"
          fi
          if [ "${{ inputs.build-darwin-amd }}" == "true" ]; then
            MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "darwin-amd", "runner": "macos-13", "shell": "bash", "binary": "ydb-dstool"}]')
            echo "Matrix after adding darwin-amd: $MATRIX"
          fi
          if [ "${{ inputs.build-windows }}" == "true" ]; then
            MATRIX=$(echo $MATRIX | jq -c '.include += [{"os": "windows", "runner": "windows-latest", "shell": "bash", "binary": "ydb-dstool.exe"}]')
            echo "Matrix after adding windows: $MATRIX"
          fi

          echo "Final output matrix: $MATRIX"
          echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
          MATRIX=$(echo $MATRIX | jq '.')
          echo "Final pretty printed matrix: $MATRIX"
          echo "Platform matrix: $MATRIX" >> "$GITHUB_STEP_SUMMARY"

  build-platform-specific-binary:
    strategy:
      matrix: ${{ fromJSON(needs.build-matrix.outputs.matrix) }}
    name: Build ${{ matrix.os }} YDB CLI binary
    needs: build-matrix
    runs-on: ${{ matrix.runner }}
    defaults:
      run:
        shell: ${{ matrix.shell }}
    steps:
    - name: Checkout
      uses: actions/checkout@v4
      with:
        ref: ${{ inputs.commit_sha }}

    - name: Print debug information
      run: |
        uname -a
        cat ydb/apps/dstool/version.txt

    # Turns out it is crucial to prepare VS environment and build in one step due to env variable visibility
    - name: Prepare Visual Studio environment and build windows binary with ya make
      if: ${{ matrix.os == 'windows' }}
      shell: cmd
      run: ${{ '"%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=amd64' }} && python ya make ydb/apps/dstool -r -DUSE_SSE4=no -o ./
    
    - name: Build unix binary with ya make
      if: ${{ matrix.os != 'windows' }}
      run: ./ya make ydb/apps/dstool -r -DUSE_SSE4=no

    - name: Upload binary to artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.os }}-binary
        path: ydb/apps/dstool/${{ matrix.binary }}
        if-no-files-found: error
        retention-days: 1

  gather-and-push-to-s3:
    name: Gather built binaries and push to s3
    needs: build-platform-specific-binary
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ inputs.commit_sha }}
      - name: Get YDB CLI version from ydb/apps/dstool/version.txt
        id: getver
        run: echo "dstool_version=$(cat ydb/apps/dstool/version.txt)" >> $GITHUB_OUTPUT
      - name: Print YDB CLI version ${{ steps.getver.outputs.dstool_version }}
        run: echo ${{ steps.getver.outputs.dstool_version }}

      - name: Prepare directory for linux binary
        if: ${{ inputs.build-linux }}
        run: mkdir -p ${{ steps.getver.outputs.dstool_version }}/linux/amd64
      - name: Prepare directory for Darwin amd binary
        if: ${{ inputs.build-darwin-amd }}
        run: mkdir -p ${{ steps.getver.outputs.dstool_version }}/darwin/amd64
      - name: Prepare directory for Windows binary
        if: ${{ inputs.build-windows }}
        run: mkdir -p ${{ steps.getver.outputs.dstool_version }}/windows/amd64/unsigned

      - name: Copy linux binary
        if: ${{ inputs.build-linux }}
        uses: actions/download-artifact@v4
        with:
          name: linux-binary
          path: ${{ steps.getver.outputs.dstool_version }}/linux/amd64/
      - name: Copy darwin amd64 binary
        if: ${{ inputs.build-darwin-amd }}
        uses: actions/download-artifact@v4
        with:
          name: darwin-amd-binary
          path: ${{ steps.getver.outputs.dstool_version }}/darwin/amd64/
      - name: Copy windows binary (unsigned)
        if: ${{ inputs.build-windows }}
        uses: actions/download-artifact@v4
        with:
          name: windows-binary
          path: ${{ steps.getver.outputs.dstool_version }}/windows/amd64/unsigned/

      - name: Print resulting file hierarchy
        run: find ${{ steps.getver.outputs.dstool_version }} | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"

      - name: Download s3
        run: wget https://github.com/s3tools/s3cmd/releases/download/v2.4.0/s3cmd-2.4.0.tar.gz
      - name: Unzip s3
        run: tar -xf s3cmd-2.4.0.tar.gz
      - name: Install s3
        run: |
          cd s3cmd-2.4.0
          sudo python3 setup.py install
          cd ..

      - name: Upload to S3
        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.dstool_version }} s3://${{ inputs.s3_bucket }}/release/