-
Notifications
You must be signed in to change notification settings - Fork 14k
66 lines (63 loc) · 2.41 KB
/
pr-labeled.yml
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
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: PR Labeled
on:
pull_request_target:
types:
- labeled
jobs:
approve-workflow-run:
# Even though job conditionals are difficult to debug, this will reduce the number of unnecessary runs
if:
github.event_name == 'pull_request_target' &&
github.event.action == 'labeled' &&
github.event.label.name == 'ci-approved'
runs-on: ubuntu-latest
steps:
- name: Env
run: printenv
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials:
false
- name: Find Workflow Run ID
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
SHA: ${{ github.event.pull_request.head.sha }}
run: |
set +e
echo "Found 'ci-approved' label on PR #$PR_NUMBER."
RUN_ID=$(gh run list -L 1 -c $SHA -s action_required --json databaseId --jq '.[].databaseId')
if [ -z "$RUN_ID" ]; then
echo "No workflow run found for SHA $SHA";
exit 0;
else
echo "Auto-approving workflow run $RUN_ID.";
fi;
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
echo "RUN_ID=$RUN_ID" >> "$GITHUB_ENV"
- name: Approve Workflow Run
if: env.RUN_ID != ''
uses: ./.github/actions/gh-api-approve-run
with:
gh-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run_id: ${{ env.RUN_ID }}
pr_number: ${{ env.PR_NUMBER }}
commit_sha: ${{ github.event.workflow_run.head_sha }}