Skip to content

Commit c55989f

Browse files
committed
perf: improve automated release PR creation
1 parent 13e66c6 commit c55989f

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

.github/workflows/k8s_edit.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ jobs:
5151
-f ${{ env.KUBERNETES_MANIFEST_FILE_PATH }} \
5252
-r ${{ env.AZURE_CONTAINER_REGISTRY }} \
5353
-t ${{ env.IMAGE_TAG }}
54-
55-
rm -rf cicd-deployment-scripts
5654
5755
git config --global user.email "[email protected]"
5856
git config --global user.name "GitHub Actions"
@@ -65,12 +63,12 @@ jobs:
6563
if [ ${{ github.event_name }} == 'release' ]; then
6664
PR_TITLE="ci(${{ github.ref_name }}): $AUTOMATED_RELEASE_BRANCH"
6765
fi
68-
69-
gh pr create \
70-
--base dev \
71-
--head $AUTOMATED_RELEASE_BRANCH \
72-
--title "$PR_TITLE" \
73-
--body "Automated release for ${{ github.event.repository.name }}:\n- $KUBERNETES_POD_NEW_IMAGE:${{ env.IMAGE_TAG }}" \
74-
--draft \
75-
--repo ${{ github.repository_owner }}/${{ env.KUBERNETES_CLUSTER_REPO_NAME }} || true
76-
# --reviewer ${{ github.repository_owner }}/devops-admin \
66+
67+
bash cicd-deployment-scripts/gh/pr_create.sh \
68+
-b ${{ github.event_name == 'release' && 'prod' || 'dev' }} \
69+
-h "$AUTOMATED_RELEASE_BRANCH" \
70+
-t "$PR_TITLE" \
71+
-o "${{ github.repository_owner }}" \
72+
-r "${{ github.event.repository.name }}" \
73+
-p "$KUBERNETES_POD_NEW_IMAGE" \
74+
-k "${{ env.KUBERNETES_CLUSTER_REPO_NAME }}" \

gh/pr_create.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# !/bin/bash
2+
set -e
3+
4+
BASE_REF="dev"
5+
HEAD_REF="automated-release-dev"
6+
PR_TITLE="ci: automated-release-dev"
7+
REPOSITORY_OWNER="code-kern-ai"
8+
REPOSITORY_NAME=""
9+
POD_IMAGE_NAME=""
10+
KUBERNETES_CLUSTER_REPO_NAME=""
11+
12+
while getopts b:h:t:o:r:p:k: flag
13+
do
14+
case "${flag}" in
15+
b) BASE_REF=${OPTARG};;
16+
h) HEAD_REF=${OPTARG};;
17+
t) PR_TITLE=${OPTARG};;
18+
o) REPOSITORY_OWNER=${OPTARG};;
19+
r) REPOSITORY_NAME=${OPTARG};;
20+
p) POD_IMAGE_NAME=${OPTARG};;
21+
k) KUBERNETES_CLUSTER_REPO_NAME=${OPTARG};;
22+
esac
23+
done
24+
25+
EXISTING_PR_NUMBER=""
26+
EXISTING_PR_BODY=$(gh pr list --base $BASE_REF --head $HEAD_REF --json body --jq '.[].body')
27+
28+
if [ -z "$EXISTING_PR_BODY" ]; then
29+
PR_BODY=$(cat <<EOF
30+
Automated $BASE_REF release:
31+
- $POD_IMAGE_NAME
32+
EOF
33+
)
34+
gh pr create \
35+
--base $BASE_REF \
36+
--head $HEAD_REF \
37+
--title "$PR_TITLE" \
38+
--body "$PR_BODY" \
39+
--draft \
40+
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME
41+
# --reviewer $REPOSITORY_OWNER/devops-admin \
42+
43+
else
44+
EXISTING_PR_NUMBER=$(gh pr list \
45+
--base $BASE_REF \
46+
--head $HEAD_REF \
47+
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME \
48+
--json number --jq '.[].number')
49+
PR_BODY=$(cat <<EOF
50+
$EXISTING_PR_BODY
51+
- $POD_IMAGE_NAME
52+
EOF
53+
)
54+
gh pr edit $EXISTING_PR_NUMBER \
55+
--body "$PR_BODY" \
56+
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME || true
57+
fi
58+

0 commit comments

Comments
 (0)