-
Notifications
You must be signed in to change notification settings - Fork 162
129 lines (114 loc) · 5.58 KB
/
CI-request-trigger.yml
File metadata and controls
129 lines (114 loc) · 5.58 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
119
120
121
122
123
124
125
126
127
128
129
# This is a basic workflow to help you get started with Actions
name: CI Request Trigger
# Controls when the workflow will run
on:
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: [self-hosted, Linux]
# work on CI script dir
defaults:
run:
working-directory: .github/scripts
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout repository (attempt 1)
id: checkout1
continue-on-error: true
uses: actions/checkout@v4
- name: Checkout repository (attempt 2)
if: steps.checkout1.outcome == 'failure'
id: checkout2
continue-on-error: true
uses: actions/checkout@v4
- name: Checkout repository (attempt 3)
if: steps.checkout2.outcome == 'failure'
id: checkout3
uses: actions/checkout@v4
# Runs trigger CI
- name: Make the script files executable
run: chmod +x pre-check-CI-result.sh trigger-CI.sh get-CI-result.sh get-branch-info.sh add-comment.sh
# Pre-check if CI already completed
- name: Pre-check CI status
id: pre-check
run: |
echo "=== Task started at: $(date '+%Y-%m-%d %H:%M:%S') ==="
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "Pre-checking CI status for Commit ID: $COMMIT_ID"
if ./pre-check-CI-result.sh "$COMMIT_ID" "${{ secrets.CI_SECRET }}" "${{ github.repository }}"; then
echo "skip_ci=true" >> $GITHUB_OUTPUT
echo "CI already completed, will skip trigger"
else
echo "skip_ci=false" >> $GITHUB_OUTPUT
echo "CI not completed, will trigger new CI"
fi
- name: trigger a CI
if: steps.pre-check.outputs.skip_ci != 'true'
run: |
echo "=== Task started at: $(date '+%Y-%m-%d %H:%M:%S') ==="
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "Using Commit ID: $COMMIT_ID"
echo "$GITHUB_REF"
PR_ID=$(echo "$GITHUB_REF" | sed 's@refs/pull/\([0-9]\+\)/.*@\1@')
echo "PR ID is $PR_ID"
./trigger-CI.sh "$COMMIT_ID" "${{ secrets.CI_SECRET }}" "${{ github.event.pull_request.head.repo.clone_url }}" "$PR_ID" "${{ github.run_id }}"
sleep 150
- name: Add comment via REST API
continue-on-error: true
run: |
echo "=== Task started at: $(date '+%Y-%m-%d %H:%M:%S') ==="
PR_ID=${{ github.event.pull_request.number }}
BRANCH_NAME="open_merge/${PR_ID}"
REPOSITORY="${{ github.repository }}"
COMMENT="internal source has been updated, please review the changes!"
SOURCE="RTP"
MAIN_BRANCH="main-internal"
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "BRANCH_NAME is $BRANCH_NAME"
BRANCH_INFO=$(./get-branch-info.sh "${BRANCH_NAME}" "${REPOSITORY}" "${COMMIT_ID}")
if [ $? -ne 0 ]; then
echo "Error: Failed to query branch info for ${BRANCH_NAME}"
exit 0
fi
echo "get branch info : $BRANCH_INFO"
CURRENT_INTERNAL_COMMITID=$(echo "$BRANCH_INFO" | jq -r '.commit.id')
if [ -z "$CURRENT_INTERNAL_COMMITID" ] || [ "$CURRENT_INTERNAL_COMMITID" = "null" ]; then
echo "Error: Failed to extract commit ID from branch info"
exit 0
fi
echo "Current internal commit ID: $CURRENT_INTERNAL_COMMITID"
MAIN_BRANCH_INFO=$(./get-branch-info.sh "$MAIN_BRANCH" "${REPOSITORY}" "${COMMIT_ID}")
if [ $? -ne 0 ]; then
echo "Error: Failed to query branch info for ${MAIN_BRANCH}"
exit 0
fi
MAIN_INTERNAL_COMMITID=$(echo "$MAIN_BRANCH_INFO" | jq -r '.commit.id')
if [ -z "$MAIN_INTERNAL_COMMITID" ] || [ "$MAIN_INTERNAL_COMMITID" = "null" ]; then
echo "Error: Failed to extract commit ID from main branch info"
exit 0
fi
echo "Main internal commit ID: $MAIN_INTERNAL_COMMITID"
if [ "${CURRENT_INTERNAL_COMMITID}" != "${MAIN_INTERNAL_COMMITID}" ]; then
echo "Commit IDs differ, adding comment..."
./add-comment.sh "$BRANCH_NAME" "$PR_ID" "$REPOSITORY" "$COMMENT" "$SOURCE" "$MAIN_BRANCH" "$COMMIT_ID"
else
echo "Commit IDs are the same, no comment needed"
fi
# Runs get CI result
- name: Get CI result
if: steps.pre-check.outputs.skip_ci != 'true'
run: |
echo "=== Task started at: $(date '+%Y-%m-%d %H:%M:%S') ==="
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "Using Commit ID: $COMMIT_ID"
./get-CI-result.sh "$COMMIT_ID" "${{ secrets.CI_SECRET }}" "${{ github.repository }}"