-
Notifications
You must be signed in to change notification settings - Fork 6
174 lines (155 loc) · 5.78 KB
/
cp.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Cherry Pick Commits on Issue Creation
on:
workflow_call:
inputs:
org:
required: true
type: string
repo:
required: true
type: string
team:
required: true
type: string
user:
required: true
type: string
issue:
required: true
type: string
issue-title:
required: true
type: string
issue-body:
required: true
type: string
secrets:
git_token:
required: true
jobs:
cherry_pick:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main # Checkout the main branch
fetch-depth: 0 # Fetch all history for cherry-picking
- name: Add comment to issue
env:
GH_TOKEN: ${{ secrets.git_token }}
org: ${{ inputs.org }}
repo: ${{ inputs.repo }}
issue: ${{ inputs.issue }}
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/add-issue-commit.sh | bash
- name: Check Issue
run: |
echo "org: ${{ inputs.org }}"
echo "team: ${{ inputs.team }}"
echo "user: ${{ inputs.user }}"
echo "title: ${{ inputs.issue-title }}"
echo "body: ${{ inputs.issue-body }}"
ORG_NAME=${{ inputs.org }}
TEAM_NAME=${{ inputs.team }}
USER_NAME=${{ inputs.user }}
echo "org1: $ORG_NAME"
echo "team1: $TEAM_NAME"
echo "user1: $USER_NAME"
# Check organization membership
ORG_MEMBERSHIP=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.git_token }}" "https://api.github.com/orgs/$ORG_NAME/members/$USER_NAME")
if [[ $ORG_MEMBERSHIP -ne 404 ]]; then
echo "The user $USER_NAME is a member of the organization $ORG_NAME."
else
echo "The user $USER_NAME is not a member of the organization $ORG_NAME."
exit 1
fi
# Check team membership
TEAM_MEMBERSHIP=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.git_token }}" "https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_NAME/memberships/$USER_NAME")
echo "$TEAM_MEMBERSHIP"
if [[ $TEAM_MEMBERSHIP -eq 200 ]]; then
echo "The user $USER_NAME is a member of the team $TEAM_NAME within the organization $ORG_NAME."
else
echo "The user $USER_NAME is not a member of the team $TEAM_NAME within the organization $ORG_NAME."
exit 1
fi
- name: Determine target branch
id: set_branch
run: |
title="${{ inputs.issue-title }}"
if [[ $title = cprc* ]]; then
branch="rc"
elif [[ $title =~ cprelease* ]]; then
branch="release"
else
echo "Unknown issue title. Aborting."
exit 1
fi
echo "::set-output name=branch::${branch}"
shell: bash
- name: Verify if '$branch' branch exists
id: verify_branch
run: |
branch=${{ steps.set_branch.outputs.branch }}
if git branch -r | grep -qE "origin/$branch"; then
echo "Branch '$branch' exists."
else
echo "Branch '$branch' does not exist."
exit 1
fi
shell: bash
- name: Install jq for JSON processing
run: sudo apt-get install jq -y
- name: Parse issue description for commit SHAs
id: parse_commits
run: |
# Extract all SHA hashes from the issue description
body='${{ inputs.issue-body }}'
if [ -z "$body" ]; then
echo "Issue body is empty"
fi
commit_list=""
while IFS= read -r line; do
cleaned_line=$(echo "$line" | tr '.,' ' ' | tr -s ' ')
cleaned_line=$(echo "$cleaned_line" | sed 's/[[:space:]]*$//')
commit_list+=" $cleaned_line"
done <<< "$body"
commit_list=$(echo "$commit_list" | sed 's/[[:space:]]*$//')
echo "::set-output name=commits::${commit_list}"
shell: bash
- name: Cherry pick commits to branch
env:
github_token: ${{ secrets.git_token }}
commit_list: ${{ steps.parse_commits.outputs.commits }}
branch: ${{ steps.set_branch.outputs.branch }}
org: ${{ inputs.org }}
repo: ${{ inputs.repo }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "upload-robot"
git config --global url.https://${{ secrets.git_token }}@github.com/.insteadOf https://github.com/
curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/cp.sh | bash
- name: Close issue
env:
GH_TOKEN: ${{ secrets.git_token }}
org: ${{ inputs.org }}
repo: ${{ inputs.repo }}
issue: ${{ inputs.issue }}
run: curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/close-issue.sh | bash
handle-failure:
needs: cherry_pick
runs-on: ubuntu-22.04
if: failure()
steps:
- name: Add comment to issue
env:
GH_TOKEN: ${{ secrets.git_token }}
org: ${{ inputs.org }}
repo: ${{ inputs.repo }}
team: ${{ inputs.team }}
user: ${{ inputs.user }}
issue: ${{ inputs.issue }}
body: "Error occured"
run: |
curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/add-issue-commit.sh | bash