forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (61 loc) · 2.68 KB
/
cicd.yml
File metadata and controls
68 lines (61 loc) · 2.68 KB
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
# Copyright 2024 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
name: Remove outdated CICD Label
on:
pull_request_target:
types: [synchronize]
permissions:
pull-requests: write
issues: write
jobs:
remove_cicd_label:
name: remove_cicd_label
if: contains(github.event.pull_request.labels.*.name, 'CICD')
runs-on: ubuntu-latest
steps:
- name: Check if label was added before push
id: check_timing
env:
PUSH_TIME: ${{ github.event.pull_request.updated_at }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ github.token }}
run: |
echo "Push time: $PUSH_TIME"
# Get latest CICD labeling event time from the last 100 events
LABEL_TIME=$(gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
timelineItems(last: 100, itemTypes: [LABELED_EVENT]) {
nodes {
... on LabeledEvent {
label { name }
createdAt
}
}
}
}
}
}' -f owner="$REPO_OWNER" -f repo="$REPO_NAME" -F pr="$PR_NUMBER" \
--jq '.data.repository.pullRequest.timelineItems.nodes | map(select(.label.name == "CICD")) | last | .createdAt')
echo "Label time: $LABEL_TIME"
if [[ -z "$LABEL_TIME" ]]; then
# Label exists on PR (checked by job 'if') but not in last 100 events -> must be very old
echo "should_remove=true" >> "$GITHUB_OUTPUT"
echo "Result: Label found on PR but not in recent timeline events. Assuming it is old."
elif [[ "$LABEL_TIME" < "$PUSH_TIME" ]]; then
echo "should_remove=true" >> "$GITHUB_OUTPUT"
echo "Result: Label added at $LABEL_TIME is older than push at $PUSH_TIME. Removing."
else
echo "should_remove=false" >> "$GITHUB_OUTPUT"
echo "Result: Label added at $LABEL_TIME is newer than or same as push at $PUSH_TIME. Skipping removal."
fi
- name: Remove outdated CICD label
if: steps.check_timing.outputs.should_remove == 'true'
run: |
gh pr edit ${{ github.event.pull_request.number }} -R ${{ github.repository }} --remove-label "CICD"
env:
GITHUB_TOKEN: ${{ github.token }}