-
Notifications
You must be signed in to change notification settings - Fork 36
138 lines (118 loc) · 5.61 KB
/
on-pr-helm-stc-sync.yaml
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
name: Validate operator and helm storageCluster Sync
on:
pull_request:
types: [opened, edited, synchronize]
paths:
- 'deploy/crds/**'
jobs:
check-crd-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Check if StorageCluster CRD has changes
id: crd_check
run: |
echo "Checking CRD changes..."
if git diff --exit-code HEAD^ HEAD -- deploy/crds/core_v1_storagecluster_crd.yaml; then
echo "crd_changed=false" >> $GITHUB_ENV
else
echo "crd_changed=true" >> $GITHUB_ENV
fi
- name: Validate PR Description for Helm Link
id: validate_pr_description
if: env.crd_changed == 'true'
run: |
echo "Extracting PR body..."
PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH")
echo "PR_BODY: '$PR_BODY'"
# Extract the HELM_PR_LINK value
HELM_PR_LINK=$(echo "$PR_BODY" | grep -oP 'HELM_PR_LINK[[:space:]]*=[[:space:]]*.*' | awk -F '=' '{print $2}' | xargs)
IS_CONFIGURABLE=$(echo "$PR_BODY" | grep -oP 'IS_USER_CONFIGURABLE_FIELD_ADDED[[:space:]]*=[[:space:]]*.*' | awk -F '=' '{print $2}' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | xargs)
# Debugging output
echo "HELM_PR_LINK: '$HELM_PR_LINK'"
echo "IS_USER_CONFIGURABLE_FIELD_ADDED: '$IS_CONFIGURABLE'"
# Check if HELM_PR_LINK is missing
if [[ -z "$HELM_PR_LINK" ]]; then
echo "Changes detected in storageCluster CRD file"
echo "Error: HELM_PR_LINK is missing in the description."
echo "Please make similar changes in the Helm StorageCluster CRD and add the PR link in the description using the format: HELM_PR_LINK=<helm-stc-changes-pr>"
exit 1
else
echo "helm_pr_link=true" >> $GITHUB_ENV
echo "helm_pr_link_url=$HELM_PR_LINK" >> $GITHUB_ENV
fi
# Debugging output for IS_CONFIGURABLE
echo "Trimmed IS_USER_CONFIGURABLE_FIELD_ADDED: '$IS_CONFIGURABLE'"
# Validate IS_CONFIGURABLE value
if [[ "$IS_CONFIGURABLE" == 'YES' ]]; then
echo "is_configurable=true" >> $GITHUB_ENV
elif [[ "$IS_CONFIGURABLE" == 'NO' ]]; then
echo "is_configurable=false" >> $GITHUB_ENV
else
echo "Changes detected in storageCluster CRD file"
echo "Error: Please specify IS_USER_CONFIGURABLE_FIELD_ADDED as either YES or NO in PR description."
echo "If you are adding a new field in the storageCluster CRD that is configurable or editable by the user, it should be added in the Helm StorageCluster template and values.yaml."
exit 1
fi
echo "is_configurable : '$is_configurable'"
- name: Extract Branch Name from Helm PR Link
id: extract_branch
if: env.helm_pr_link == 'true'
run: |
# Extract the PR number from the HELM_PR_LINK URL
PR_NUMBER=$(echo "${{ env.helm_pr_link_url }}" | grep -o '[0-9]\+')
echo "PR_NUMBER: $PR_NUMBER"
# Check if PR_NUMBER extraction was successful
if [ -z "$PR_NUMBER" ]; then
echo "Error: PR_NUMBER could not be extracted."
exit 1
fi
# Fetch the branch name using the GitHub API
HELM_BRANCH=$(curl -s "https://api.github.com/repos/portworx/helm/pulls/$PR_NUMBER" | jq -r '.head.ref')
echo "HELM_BRANCH: $HELM_BRANCH"
# Check if HELM_BRANCH was successfully extracted
if [ -z "$HELM_BRANCH" ]; then
echo "Error: Failed to extract the branch name from the Helm PR."
exit 1
else
echo "helm_branch=$HELM_BRANCH" >> $GITHUB_ENV
fi
- name: Checkout Helm Repo
if: env.crd_changed == 'true' && env.helm_pr_link == 'true'
uses: actions/checkout@v3
with:
fetch-depth: 2
repository: portworx/helm
ref: ${{ env.helm_branch }}
- name: Verify Helm StorageCluster CRD Changes
if: env.crd_changed == 'true' && env.helm_pr_link == 'true'
run: |
echo "Checking Helm template changes..."
if git diff --exit-code HEAD^ HEAD -- charts/portworx/crds/core_v1_storagecluster_crd.yaml; then
echo "Error: No changes detected in Helm storagecluster CRD file."
exit 1
else
echo "Helm storagecluster CRD changes detected."
fi
- name: Verify Helm StorageCluster template and values.yaml file changes
if: env.crd_changed == 'true' && env.helm_pr_link == 'true' && env.is_configurable== 'true'
run: |
echo "Checking Helm storagecluster template changes..."
if git diff --exit-code HEAD^ HEAD -- charts/portworx/crds/core_v1_storagecluster_crd.yaml; then
echo "Error: No changes detected in Helm storagecluster template file."
exit 1
else
echo "Helm storagecluster template changes detected."
fi
echo "Checking Helm storagecluster template changes..."
if git diff --exit-code HEAD^ HEAD -- charts/portworx/values.yaml; then
echo "Error: No changes detected in Helm values.yaml file."
exit 1
else
echo "Helm values.yaml file changes detected."
fi
- name: Final Status
run: echo "Validation completed successfully."