Skip to content

Commit 6143af1

Browse files
Create check_mysql_repo.groovy (#3556)
* Create check_mysql_repo.groovy * Add fixes and improvements check_mysql_repo.groovy
1 parent 6480870 commit 6143af1

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
def awsCredentials = [[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: '4422eb0c-26be-4454-8823-fc76b9b3b120']]
2+
3+
void sendMessage(String REPO_NAME, String REPO_URL) {
4+
TAGS = sh (
5+
script: "cat ${REPO_NAME}.newtags 2>/dev/null || echo ''",
6+
returnStdout: true
7+
).trim()
8+
9+
if (TAGS) {
10+
slackSend channel: "${ReposSlackMap["$REPO_NAME"]}", color: '#00FF00', message: "[${JOB_NAME}]: New tag(s) have been created for ${REPO_NAME}, please check the following link(s):\n${TAGS}"
11+
} else {
12+
sh (script: "rm -rf ${REPO_NAME}.newtags", returnStdout: false)
13+
}
14+
}
15+
16+
void checkRepo(String REPO_NAME, String REPO_URL) {
17+
popArtifactFile("${REPO_NAME}.last")
18+
sh """
19+
if [ -f ${REPO_NAME}.last ]; then
20+
git ls-remote --tags --refs ${REPO_URL} | awk -F'/' '{print \$3}' | sort | uniq > ${REPO_NAME}.current
21+
cat ${REPO_NAME}.last ${REPO_NAME}.current | sort | uniq -u | awk '{print "$REPO_URL/tree/"\$1}' > ${REPO_NAME}.newtags
22+
mv -fv ${REPO_NAME}.current ${REPO_NAME}.last
23+
else
24+
git ls-remote --tags --refs ${REPO_URL} | awk -F'/' '{print \$3}' | sort | uniq > ${REPO_NAME}.last
25+
fi
26+
27+
"""
28+
pushArtifactFile("${REPO_NAME}.last")
29+
}
30+
31+
void pushArtifactFile(String FILE_NAME) {
32+
sh """
33+
S3_PATH=s3://rel-repo-cache/mysql-monitor
34+
aws s3 ls \$S3_PATH/${FILE_NAME} || :
35+
aws s3 cp --quiet ${FILE_NAME} \$S3_PATH/${FILE_NAME} || :
36+
"""
37+
}
38+
39+
void popArtifactFile(String FILE_NAME) {
40+
sh """
41+
S3_PATH=s3://rel-repo-cache/mysql-monitor
42+
aws s3 cp --quiet \$S3_PATH/${FILE_NAME} ${FILE_NAME} || :
43+
"""
44+
}
45+
46+
def GitHubURL='https://github.com'
47+
48+
// Filtered to only MySQL-related repositories
49+
ReposPathMap = [
50+
'MySQL': "${GitHubURL}/mysql/mysql-server"
51+
]
52+
53+
// Corresponding Slack channels for MySQL repositories
54+
ReposSlackMap = [
55+
'MySQL': "#mysql"
56+
]
57+
58+
pipeline {
59+
agent {
60+
label 'micro-amazon'
61+
}
62+
triggers {
63+
// Hourly on months 1,4,7,10 from 2nd week to 4th week (days 8-28)
64+
cron('H * 8-28 1,4,7,10 *')
65+
}
66+
options {
67+
skipStagesAfterUnstable()
68+
disableConcurrentBuilds()
69+
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
70+
withCredentials(awsCredentials)
71+
}
72+
stages {
73+
stage('Check MySQL Repos') {
74+
steps {
75+
script {
76+
ReposPathMap.each { repo_info ->
77+
checkRepo("${repo_info.key}", "${repo_info.value}")
78+
}
79+
}
80+
stash allowEmpty: true, includes: "*.newtags", name: "NewTagsFiles"
81+
}
82+
}
83+
stage('Process New Tags') {
84+
when {
85+
expression {
86+
// Check if any repo has new tags using same logic as sendMessage function
87+
def hasNewTags = false
88+
ReposPathMap.each { repo_info ->
89+
try {
90+
def tags = sh(
91+
script: "cat ${repo_info.key}.newtags 2>/dev/null || echo ''",
92+
returnStdout: true
93+
).trim()
94+
if (tags) {
95+
hasNewTags = true
96+
}
97+
} catch (Exception e) {
98+
// File doesn't exist, continue
99+
}
100+
}
101+
return hasNewTags
102+
}
103+
}
104+
steps {
105+
script {
106+
echo "New tags detected, downloading and executing processing script..."
107+
108+
// Download the script
109+
sh """
110+
curl -fsSL -o gen_csv_diff.sh https://raw.githubusercontent.com/VarunNagaraju/sh/refs/heads/master/gen_csv_diff.sh
111+
chmod +x gen_csv_diff.sh
112+
"""
113+
114+
// Create directory for CSV output
115+
sh "mkdir -p csv_output"
116+
117+
// Clone mysql-server repository once
118+
sh """
119+
git clone ${ReposPathMap['MySQL']} mysql-server-repo
120+
"""
121+
122+
// Define version patterns to track
123+
def versionPatterns = ['mysql-5.7', 'mysql-8.0', 'mysql-8.4']
124+
125+
versionPatterns.each { versionPattern ->
126+
echo "Processing version series: ${versionPattern}"
127+
128+
// Get latest two tags for this version series
129+
def tags = sh(
130+
script: """
131+
git -C mysql-server-repo tag -l '${versionPattern}.*' | sort -V | tail -2
132+
""",
133+
returnStdout: true
134+
).trim().split('\n')
135+
136+
if (tags.size() >= 2) {
137+
def oldTag = tags[-2].trim()
138+
def newTag = tags[-1].trim()
139+
140+
if (oldTag && newTag) {
141+
echo "Comparing ${versionPattern}: ${oldTag} -> ${newTag}"
142+
143+
// Execute script with version-specific parameters
144+
sh """
145+
cd mysql-server-repo
146+
../gen_csv_diff.sh ${oldTag} ${newTag} ../csv_output
147+
"""
148+
} else {
149+
echo "Could not determine tags for ${versionPattern}"
150+
}
151+
} else {
152+
echo "Not enough tags found for ${versionPattern} (found: ${tags.size()})"
153+
}
154+
}
155+
}
156+
}
157+
}
158+
stage('Sending notifications') {
159+
steps {
160+
unstash "NewTagsFiles"
161+
script {
162+
ReposPathMap.each { repo_info ->
163+
sendMessage("${repo_info.key}", "${repo_info.value}")
164+
}
165+
}
166+
}
167+
}
168+
}
169+
post {
170+
always {
171+
archiveArtifacts artifacts: '*.newtags, csv_output/**/*.csv', allowEmptyArchive: true
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)