kafka

Форк
0
/
ci-requested.yml 
86 строк · 3.6 Кб
1
# Licensed to the Apache Software Foundation (ASF) under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#    http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
name: CI Requested
17

18
on:
19
  workflow_run:
20
    workflows: [CI]
21
    types:
22
      - requested
23

24
run-name: CI Requested for ${{ github.event.workflow_run.display_title}}
25

26
jobs:
27
  check-pr-labels:
28
    # Even though job conditionals are difficult to debug, this will reduce the number of unnecessary runs
29
    if: |
30
      github.event_name == 'workflow_run' && 
31
      github.event.workflow_run.event == 'pull_request' &&
32
      github.event.workflow_run.status == 'completed' && 
33
      github.event.workflow_run.conclusion == 'action_required'
34
    runs-on: ubuntu-latest
35
    steps:
36
      - name: Env
37
        run: printenv
38
        env:
39
          GITHUB_CONTEXT: ${{ toJson(github) }}
40
      - name: Checkout code
41
        uses: actions/checkout@v4
42
        with:
43
          persist-credentials:
44
            false
45
      - name: Check PR Labels
46
        env:
47
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48
          REPO: ${{ github.repository }}
49
          RUN_ID: ${{ github.event.workflow_run.id }}
50
          HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
51
          HEAD_REPO: ${{ github.event.workflow_run.head_repository.owner.login }}
52
        # Caution! This is a bit hacky. The GH documentation shows that the workflow_run event should include a list
53
        # of referencing pull_requests. I think this might only be the case for pull requests originating from the
54
        # base repository. To deal with fork PRs, we need to query the API for PRs for the owner's branch. This
55
        # code assumes that the fork repo owner is the same as the organization for the "org:branch" syntax used
56
        # in the query. Also, only the first matching PR from that org will be considered.
57
        run: |
58
          set +e
59
          PR_NUMBER=$(gh api \
60
            -H "Accept: application/vnd.github+json" \
61
            -H "X-GitHub-Api-Version: 2022-11-28" \
62
            /repos/$REPO/pulls?head=$HEAD_REPO:$HEAD_BRANCH \
63
            --jq '.[0].number')
64
          if [ -z "$PR_NUMBER" ]; then
65
            echo "Could not find the PR that triggered this workflow request";
66
            exit 1;
67
          fi
68
          gh pr view $PR_NUMBER --json labels -q '.labels[].name' | grep -q 'ci-approved'
69
          exitcode="$?"
70
          if [ $exitcode -ne 0 ]; then
71
            echo "No ci-approved label set on PR #$PR_NUMBER. Will not auto-approve.";
72
            exit 0;
73
          else
74
            echo "Found 'ci-approved' label on PR #$PR_NUMBER. Auto-approving workflow run $RUN_ID.";
75
          fi
76
          echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
77
          echo "RUN_ID=$RUN_ID" >> "$GITHUB_ENV"
78
      - name: Approve Workflow Run
79
        if: env.RUN_ID != ''
80
        uses: ./.github/actions/gh-api-approve-run
81
        with:
82
          gh-token: ${{ secrets.GITHUB_TOKEN }}
83
          repository: ${{ github.repository }}
84
          run_id: ${{ env.RUN_ID }}
85
          pr_number: ${{ env.PR_NUMBER }}
86
          commit_sha: ${{ github.event.workflow_run.head_sha }}
87

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

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

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

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