forked from opendatahub-io/data-science-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (101 loc) · 4.55 KB
/
Copy pathstable-merge-check.yml
File metadata and controls
118 lines (101 loc) · 4.55 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
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
name: PR Merge Integration Test Check
on:
pull_request:
branches:
- stable
types: [opened, synchronize, reopened, edited]
issue_comment:
types: [created, edited]
permissions:
issues: write
pull-requests: write
contents: read
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
# Job to handle /integration-tests-ok command
process-integration-command:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/integration-tests-ok') }}
steps:
- name: Check if the author is a member or Owner
id: check-condition
run: |
if [[ "${{ github.event.comment.author_association }}" == "MEMBER" || "${{ github.event.comment.author_association }}" == "OWNER" ]]; then
echo "condition_met=true" >> $GITHUB_ENV
else
echo "User does not have permission to trigger this command."
echo "condition_met=false" >> $GITHUB_ENV
fi
- name: Leave a Comment on Permission Fail
if: env.condition_met == 'false'
env:
message: 🚫 This command cannot be processed. Only organization members or owners can use the `/integration-tests-ok` command.
run: |
gh issue comment ${{ github.event.issue.number }} --repo "${{ github.repository }}" --body "${{ env.message }}"
echo ${message}
exit 1
- name: Check if PR target
if: env.condition_met == 'true'
run: |
PR_URL="${{ github.event.issue.pull_request.url }}"
PR_DATA=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" "$PR_URL")
BASE_BRANCH=$(echo "$PR_DATA" | jq -r '.base.ref')
HEAD_BRANCH=$(echo "$PR_DATA" | jq -r '.head.ref')
echo "Base branch: $BASE_BRANCH"
echo "Head branch: $HEAD_BRANCH"
if [[ "$BASE_BRANCH" == "stable" || "$BASE_BRANCH" == "master" ]]; then
echo "valid_target=true" >> $GITHUB_ENV
else
echo "valid_target=false" >> $GITHUB_ENV
echo "This command only works for PRs against master/stable branch"
fi
- name: Leave a Comment on Invalid Target
if: env.condition_met == 'true' && env.valid_target == 'false'
env:
message: ⚠️ This command only works for pull requests to `master/stable` branches.
run: |
gh issue comment ${{ github.event.issue.number }} --repo "${{ github.repository }}" --body "${{ env.message }}"
echo ${message}
exit 1
- name: Add integration-tests-verified label
if: env.condition_met == 'true' && env.valid_target == 'true'
run: |
gh issue edit ${{ github.event.issue.number }} --add-label "integration-tests-verified" --repo "${{ github.repository }}"
echo "✅ Added integration-tests-verified label"
- name: Leave success comment
if: env.condition_met == 'true' && env.valid_target == 'true'
env:
message: |
✅ **Integration Tests Verified**
The `integration-tests-verified` label has been added to this PR. The merge check will now pass.
**Note**: This label will be automatically removed if new commits are pushed to ensure tests are re-run with the latest changes.
run: |
gh issue comment ${{ github.event.issue.number }} --repo "${{ github.repository }}" --body "${{ env.message }}"
# Job to remove label on new commits and check for label presence
integration-test-check:
name: Integration Test Verification
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || contains(github.event.comment.body, '/integration-tests-ok')
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install PyGithub
- name: Check integration test label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_EVENT_ACTION: ${{ github.event.action }}
run: |
echo "Waiting for 10 sec for label to get added in case it does get added"
sleep 10
python .github/scripts/check_integration_test_label.py