kuma

Форк
0
328 строк · 13.5 Кб
1
on:
2
  workflow_call:
3
    inputs:
4
      matrix:
5
        required: true
6
        type: string
7
      runnersByArch:
8
        type: string
9
        required: false
10
        default: '{"amd64": "ubuntu-latest", "arm64": "circleci"}'
11
    secrets:
12
      circleCIToken:
13
        required: true
14
permissions:
15
  contents: read
16
env:
17
  E2E_PARAM_K8S_VERSION: ${{ fromJSON(inputs.matrix).k8sVersion }}
18
  E2E_PARAM_CNI_NETWORK_PLUGIN: ${{ fromJSON(inputs.matrix).cniNetworkPlugin }}
19
  E2E_PARAM_ARCH: ${{ fromJSON(inputs.matrix).arch }}
20
  E2E_PARAM_SIDECAR_CONTAINERS: ${{ fromJSON(inputs.matrix).sidecarContainers }}
21
  E2E_PARAM_TARGET: ${{ fromJSON(inputs.matrix).target }}
22
  E2E_PARAM_PARALLELISM: ${{ fromJSON(inputs.matrix).parallelism }}
23
  CI_TOOLS_DIR: /home/runner/work/kuma/kuma/.ci_tools
24
jobs:
25
  e2e:
26
    timeout-minutes: 60
27
    # use the runner from the map, if the runner is circleci or '' then use ubuntu-latest
28
    runs-on: ${{ contains(fromJSON('["circleci", ""]'), fromJSON(inputs.runnersByArch)[fromJSON(inputs.matrix).arch]) && 'ubuntu-latest' || fromJSON(inputs.runnersByArch)[fromJSON(inputs.matrix).arch]}}
29
    strategy:
30
      fail-fast: false
31
      matrix:
32
        parallelRunnerId: ${{ fromJSON((fromJSON(inputs.matrix).parallelism == '4' && '[0, 1, 2, 3]') || '[0]') }}
33
    steps:
34
      - name: "Print parameters"
35
        id: eval-params
36
        run: |
37
          RUN_TYPE=""
38
          RUNNER="${{ fromJSON(inputs.runnersByArch)[env.E2E_PARAM_ARCH] }}"
39
          if [[ "$RUNNER" == "circleci" ]]; then
40
            RUN_TYPE="circleci"
41
          elif [[ "$RUNNER" != "" ]]; then
42
            RUN_TYPE="github"
43
          fi
44
          echo "Running with: ${{ toJSON(inputs) }} ${{ toJSON(env) }}"
45
          echo "run-type=$RUN_TYPE">> $GITHUB_OUTPUT
46
      - name: "GitHub Actions: check out code"
47
        if: steps.eval-params.outputs.run-type == 'github'
48
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
49
        with:
50
          fetch-depth: 0
51
      - name: "GitHub Actions: setup go"
52
        if: steps.eval-params.outputs.run-type == 'github'
53
        uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
54
        with:
55
          go-version-file: go.mod
56
      - name: "GitHub Actions: set up cache"
57
        if: steps.eval-params.outputs.run-type == 'github'
58
        uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
59
        with:
60
          path: |
61
            ${{ env.CI_TOOLS_DIR }}
62
          key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
63
          restore-keys: |
64
            ${{ runner.os }}-${{ runner.arch }}-devtools
65
      - if: steps.eval-params.outputs.run-type == 'github'
66
        run: |
67
          make dev/tools
68
      - name: "Github Actions: Free up disk space for the Runner"
69
        if: steps.eval-params.outputs.run-type == 'github'
70
        run: |
71
          echo "Disk usage before cleanup"
72
          sudo df -h
73
          echo "Removing big directories"
74
          sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
75
          echo "Pruning images"
76
          docker system prune --all -f
77
          echo "Disk usage after cleanup"
78
          sudo df -h
79
      - name: "Github Actions: build"
80
        if: steps.eval-params.outputs.run-type == 'github'
81
        run: |
82
          make build
83
      - name: "Github Actions: distributions"
84
        if: steps.eval-params.outputs.run-type == 'github'
85
        run: |
86
          make -j build/distributions
87
      - name: "Github Actions: images"
88
        if: steps.eval-params.outputs.run-type == 'github'
89
        run: |
90
          make -j images
91
          make -j docker/save
92
      - name: "GitHub Actions: setup helm"
93
        if: steps.eval-params.outputs.run-type == 'github'
94
        run: |
95
          make dev/set-kuma-helm-repo
96
      - name: "GitHub Actions: enable ipv6 for docker"
97
        if: ${{ steps.eval-params.outputs.run-type == 'github' && env.E2E_PARAM_K8S_VERSION == 'kindIpv6' }}
98
        run: |
99
          cat <<'EOF' | sudo tee /etc/docker/daemon.json
100
          {
101
            "ipv6": true,
102
            "fixed-cidr-v6": "2001:db8:1::/64",
103
            "dns": ["8.8.8.8"],
104
            "dns-search": ["."]
105
          }
106
          EOF
107
          sudo service docker restart
108
      - name: "GitHub Actions: run E2E tests"
109
        if: steps.eval-params.outputs.run-type == 'github'
110
        run: |
111
          if [[ "${{ env.E2E_PARAM_K8S_VERSION }}" == "kindIpv6" ]]; then
112
            export IPV6=true
113
            export K8S_CLUSTER_TOOL=kind
114
            export KUMA_DEFAULT_RETRIES=60
115
            export KUMA_DEFAULT_TIMEOUT="6s"
116
          fi
117
          if [[ "${{ env.E2E_PARAM_K8S_VERSION }}" != "kind"* ]]; then
118
            export CI_K3S_VERSION=$E2E_PARAM_K8S_VERSION
119
            export K3D_NETWORK_CNI=${{ env.E2E_PARAM_CNI_NETWORK_PLUGIN }}
120
          fi
121
          if [[ "${{ env.E2E_PARAM_ARCH }}" == "arm64" ]]; then
122
            export MAKE_PARAMETERS="-j1"
123
          else
124
            export MAKE_PARAMETERS="-j2"
125
          fi
126

127
          if [[ "${{ env.E2E_PARAM_SIDECAR_CONTAINERS }}" != "" ]]; then
128
            export KUMA_EXPERIMENTAL_SIDECAR_CONTAINERS=true
129
          fi
130

131
          if [[ "${{ env.E2E_PARAM_TARGET }}" == "" ]]; then
132
            export GINKGO_E2E_LABEL_FILTERS="job-${{ matrix.parallelRunnerId }}"
133
          fi
134
          env
135
          if [[ "${{ env.E2E_PARAM_TARGET }}" != "" ]]; then
136
            target="test/e2e-${{ env.E2E_PARAM_TARGET }}"
137
          else
138
            target="test/e2e"
139
          fi
140
          make ${MAKE_PARAMETERS} CI=true "${target}"
141
      - name: "CircleCI: make circleci parameters"
142
        if: steps.eval-params.outputs.run-type == 'circleci'
143
        id: circleci-gen-params
144
        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
145
        with:
146
          script: |
147
            let circleCIParams = {
148
              'gh_action_build_artifact_name': 'build-output',
149
              'gh_action_run_id': '${{ github.run_id }}'
150
            };
151
            let inputs = JSON.parse(${{ toJSON(inputs.matrix) }});
152
            Object.keys(inputs).forEach(function(key) {
153
              circleCIParams[`e2e_param_${key}`] = inputs[key];
154
            });
155
            let circleCIBody = {
156
              "parameters": circleCIParams,
157
            };
158

159
            if ( "${{ github.event_name }}" == "pull_request" ) {
160
              circleCIBody["branch"] = 'pull/${{ github.event.pull_request.number }}/merge';
161
            } else {
162
              circleCIBody["tag"] = '${{ github.sha }}'
163
            }
164

165
            core.info(`created request object for circleCI ${JSON.stringify(circleCIBody)}`);
166
            return circleCIBody
167
      - name: "CircleCI: trigger a new pipeline workflow on CircleCI"
168
        if: steps.eval-params.outputs.run-type == 'circleci'
169
        id: circle-ci-trigger
170
        run: |
171
          # Trigger CircleCI manually, reference: https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/blob/main/src/lib/CircleCIPipelineTrigger.ts#L82
172
          set -e
173
          if [ "${{ runner.debug }}" == "1" ]; then
174
            set -x
175
          fi
176

177
          CIRCLE_CI_API_PATH=https://circleci.com/api/v2/project/gh/${{ github.repository }}/pipeline
178
          echo "Calling CircleCI api with parameters:
179
            URL: $CIRCLE_CI_API_PATH
180
            BODY: ${{ steps.circleci-gen-params.outputs.result }}"
181

182
          if [ "${{ secrets.circleCIToken }}" == "" ]; then
183
            echo "Skipping request CircleCI because secret 'CIRCLECI_TOKEN' not set."
184
            exit 0
185
          fi
186

187
          function request(){
188
            METHOD=$1
189
            URL=$2
190
            DATA=$3
191

192
            if [ "$DATA" != "" ]; then
193
              DATA="--data $DATA"
194
            fi
195

196
            OUTPUT_FILE=/tmp/circleci-response-$RANDOM.json
197
            touch $OUTPUT_FILE
198
            STATUS_CODE=
199
            while [[ "$STATUS_CODE" == "" ]]; do
200
              STATUS_CODE=$(curl -o $OUTPUT_FILE -sL -w "%{http_code}" -X $METHOD $URL \
201
                --header "content-type: application/json" --header "accept: application/json" \
202
                --header "x-attribution-login: ${{ github.actor }}" --header "x-attribution-actor-id: ${{ github.actor }}" \
203
                --header "Circle-Token: ${{ secrets.circleCIToken }}" $DATA )
204

205
              if [[ "$STATUS_CODE" == "429" ]]; then
206
                STATUS_CODE=
207
                echo '' > $OUTPUT_FILE
208
                sleep $((RANDOM % 3))
209
              fi
210
            done
211

212
            if [ $STATUS_CODE -lt 200 ] || [ $STATUS_CODE -gt 399 ] ; then
213
              echo "Error requesting $METHOD $URL (status $STATUS_CODE)"
214
              cat $OUTPUT_FILE
215
            fi
216
            cat $OUTPUT_FILE
217
            rm $OUTPUT_FILE
218
          }
219

220
          PIPELINE_ID=$(request POST $CIRCLE_CI_API_PATH '${{ steps.circleci-gen-params.outputs.result }}' | tr '\n' ' ' | jq -Rrc 'fromjson | .id')
221
          sleep 3
222
          WORKFLOW_DETAILS=$(request GET https://circleci.com/api/v2/pipeline/$PIPELINE_ID/workflow | tr '\n' ' ' | jq -Rrc 'fromjson | .items[] | select(.name == "manual-e2e")')
223
          PIPELINE_NUMBER=$(echo $WORKFLOW_DETAILS | tr '\n' ' ' | jq -Rrc 'fromjson | .pipeline_number')
224
          WORKFLOW_ID=$(echo $WORKFLOW_DETAILS | tr '\n' ' ' | jq -Rrc 'fromjson | .id')
225

226
          echo "pipeline_number=$PIPELINE_NUMBER" >> $GITHUB_OUTPUT
227
          echo "workflow_id=$WORKFLOW_ID" >> $GITHUB_OUTPUT
228

229
          if [[ "$WORKFLOW_ID" == "" ]]; then
230
            echo "Could not trigger a workflow on CircleCI, check your .circleci/config.yaml"
231
            exit 1
232
          fi
233

234
          echo ''
235
          echo "CircleCI pipeline triggered successfully, pipeline id: $PIPELINE_ID"
236
          echo "Check CircleCI workflow details at: https://app.circleci.com/pipelines/gh/${{ github.repository }}/$PIPELINE_NUMBER/workflows/$WORKFLOW_ID"
237
      - name: "CircleCI: check run status of pipeline workflow on CircleCI"
238
        if: ${{ steps.eval-params.outputs.run-type == 'circleci' && steps.circle-ci-trigger.outputs.workflow_id != '' }}
239
        run: |
240
          set -e
241
          if [ "${{ runner.debug }}" == "1" ]; then
242
            set -x
243
          fi
244

245
          function request(){
246
            METHOD=$1
247
            URL=$2
248
            DATA=$3
249

250
            if [ "$DATA" != "" ]; then
251
              DATA="--data $DATA"
252
            fi
253

254
            OUTPUT_FILE=/tmp/circleci-response-$RANDOM.json
255
            touch $OUTPUT_FILE
256
            STATUS_CODE=$(curl -o $OUTPUT_FILE -sL -w "%{http_code}" -X $METHOD $URL \
257
              --header "content-type: application/json" --header "accept: application/json" \
258
              --header "x-attribution-login: ${{ github.actor }}" --header "x-attribution-actor-id: ${{ github.actor }}" \
259
              --header "Circle-Token: ${{ secrets.circleCIToken }}" $DATA )
260

261
            if [ "$STATUS_CODE" == "429" ]; then
262
              # we are exceeding rate limit, try again later
263
              echo '{"status": ""}'
264
              return
265
            fi
266
            if [ $STATUS_CODE -lt 200 ] || [ $STATUS_CODE -gt 399 ] ; then
267
              echo "Error requesting $METHOD $URL (status $STATUS_CODE)"
268
              cat $OUTPUT_FILE
269
            fi
270
            cat $OUTPUT_FILE
271
            rm $OUTPUT_FILE
272
          }
273

274
          function check_workflow(){
275
            WORKFLOW_ID=$1
276
            STATUS=''
277
            # status could be "success" "running" "not_run" "failed" "error" "failing" "on_hold" "canceled" "unauthorized"
278
            # statuses to continue: "running" "on_hold"
279
            # status completed: "success" "not_run" "failed" "error" "failing" "canceled" "unauthorized"
280
            while [[ "$STATUS" == "" ]] || [[ "$STATUS" == "running" ]] || [[ "$STATUS" == "on_hold" ]]; do
281
              sleep $((RANDOM % 5 + 25))
282
              STATUS=$(request GET https://circleci.com/api/v2/workflow/$WORKFLOW_ID | tr '\n' ' ' | jq -Rrc 'fromjson | .status')
283
              echo -n .
284
            done
285

286
            echo ''
287
            if [[ "$STATUS" == "success" ]]; then
288
              echo "CircleCI workflow has completed successfully."
289
              exit 0
290
            else
291
              echo "CircleCI workflow has completed with status: '$STATUS'."
292
              exit 1
293
            fi
294
          }
295

296
          PIPELINE_NUMBER='${{ steps.circle-ci-trigger.outputs.pipeline_number }}'
297
          WORKFLOW_ID='${{ steps.circle-ci-trigger.outputs.workflow_id }}'
298
          echo "Check CircleCI workflow details at: https://app.circleci.com/pipelines/gh/${{ github.repository }}/$PIPELINE_NUMBER/workflows/$WORKFLOW_ID"
299
          echo "Tracking workflow status:"
300
          check_workflow '${{ steps.circle-ci-trigger.outputs.workflow_id }}'
301
      - name: "CircleCI: cancel CircleCI running if requested"
302
        if: ${{  steps.eval-params.outputs.run-type == 'circleci' && cancelled() && steps.circle-ci-trigger.outputs.workflow_id != '' }}
303
        run: |
304
          set -e
305
          if [ "${{ runner.debug }}" == "1" ]; then
306
            set -x
307
          fi
308

309
          function request(){
310
            METHOD=$1
311
            URL=$2
312
            DATA=$3
313

314
            if [ "$DATA" != "" ]; then
315
              DATA="--data $DATA"
316
            fi
317

318
            OUTPUT_FILE=/tmp/circleci-response-$RANDOM.json
319
            STATUS_CODE=$(curl -o $OUTPUT_FILE -sL -w "%{http_code}" -X $METHOD $URL \
320
              --header "content-type: application/json" --header "accept: application/json" \
321
              --header "x-attribution-login: ${{ github.actor }}" --header "x-attribution-actor-id: ${{ github.actor }}" \
322
              --header "Circle-Token: ${{ secrets.circleCIToken }}" $DATA )
323

324
            cat $OUTPUT_FILE
325
            rm $OUTPUT_FILE
326
          }
327

328
          request POST https://circleci.com/api/v2/workflow/${{ steps.circle-ci-trigger.outputs.workflow_id }}/cancel
329

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.