Skip to content

Commit 44c50d6

Browse files
committed
Now the manager also handles issues after release (on-sync)
a) keeping the current queue fed (like before release). b) holding new features and improvements (with special on-syn message) I've ended refactoring / reorganizing everything, splitting into bash functions for easier reuse and future expansion. Also, add support for $dryrun env variable to allow the script to be executed without performing any change in the tracker.
1 parent a0993ac commit 44c50d6

File tree

2 files changed

+344
-161
lines changed

2 files changed

+344
-161
lines changed

tracker_automations/continuous_manage_queues/continuous_manage_queues.sh

Lines changed: 70 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
# - current queue: issues under current integration.
55
#
66
# The automatisms are as follow:
7-
# 0) Add the "integration_held" (+ std. comment) to new features & improvements issue missing it @ candidates.
8-
# 1) Move "important" issues from candidates to current.
9-
# 2) Move issues away from the candidates queue:
10-
# 2a) Before a date (last week), keep the current queue fed with issues when it's under a threshold.
11-
# 2b) After a date (last week), add the "integration_held" (+ std.comment) to bug issues.
7+
# A) Before release only! (normally 6 weeks of continuous before release)
8+
# 1) Add the "integration_held" (+ standard comment) to new features & improvements issue missing it @ candidates.
9+
# 2) Move "important" issues from candidates to current.
10+
# 3) Move issues away from the candidates queue.
11+
# a) Before a date (last week), keep the current queue fed with bug issues when it's under a threshold.
12+
# b) After a date (last week), add the "integration_held" (+ standard comment) to bug issues.
13+
# B) After release only! (normally 2 weeks of on-sync continuous after release)
14+
# 1) Move issues away from the candidates queue.
15+
# a) Keep the current queue fed with bug issues when it's under a threshold.
16+
# b) Add the "integration_held" (+ on-sync standard comment) to new features and improvements missing it @ candidates.
1217
#
1318
# The criteria to consider an issue "important" are:
14-
# 1) It must be in the candidates queue, awating for integration. |
19+
# 1) It must be in the candidates queue, awaiting for integration. |
1520
# 2) It must not have the integration_held or security_held labels. | => filter=14000
1621
# 3) It must not have the "agreed_to_be_after_release" text in a comment.| => NOT filter = 21366
1722
# 4) At least one of this is true:
@@ -31,15 +36,17 @@
3136
# jiraserver: jira server url we are going to connect to
3237
# jirauser: user that will perform the execution
3338
# jirapass: password of the user
34-
# datetoholdbugs: first date to change behavior from 2a - feed current to 2b - held bug issues. (YYY-MM-DD)
39+
# releasedate: Release date, used to decide between A (before release) and B (after release) behaviors. YYYY-MM-DD.
40+
# lastweekdate: Last week date to decide between 2a - feed current and 2b - held bug issues. (YYY-MM-DD, defaults to release -1w)
3541
# currentmin: optional, number of issue under which the current queue will be fed from the candidates one.
3642
# movemax: optional, max number of issue that will be moved from candidates to current when under currentmin.
43+
# dryrun: don't perfomr any write operation, only reads. Defaults to empty (false).
3744

3845
# Let's go strict (exit on error)
3946
set -e
4047

4148
# Verify everything is set
42-
required="WORKSPACE jiraclicmd jiraserver jirauser jirapass datetoholdbugs"
49+
required="WORKSPACE jiraclicmd jiraserver jirauser jirapass releasedate"
4350
for var in $required; do
4451
if [ -z "${!var}" ]; then
4552
echo "Error: ${var} environment variable is not defined. See the script comments."
@@ -59,175 +66,77 @@ mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5966
basereq="${jiraclicmd} --server ${jiraserver} --user ${jirauser} --password ${jirapass}"
6067
BUILD_TIMESTAMP="$(date +'%Y-%m-%d_%H-%M-%S')"
6168

69+
source ${mydir}/lib.sh # Add all the functions.
70+
6271
# Set defaults
6372
currentmin=${currentmin:-6}
6473
movemax=${movemax:-3}
74+
lastweekdate=${lastweekdate:-$(date -d "${releasedate} -7day" +%Y-%m-%d)}
75+
dryrun=${dryrun:-}
76+
77+
# Verify that $releasedata has a correct YYYY-MM-DD format
78+
if [[ ! ${releasedate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
79+
echo "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
80+
exit 1
81+
fi
6582

66-
# Verify that $datetoholdbugs has a correct YYYY-MM-DD format
67-
if [[ ! ${datetoholdbugs} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
68-
echo "ERROR: Incorrect YYYY-MM-DD format detected: ${datetoholdbugs}"
83+
# Verify that $lastweekdate has a correct YYYY-MM-DD format
84+
if [[ ! ${lastweekdate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
85+
echo "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
6986
exit 1
7087
fi
7188

72-
# Decide if we are going to perform the behavior 2a) move to current
73-
# or 2b) hold bugs, based on current date.
74-
behavior2=
75-
holddate=$(date -d "${datetoholdbugs}" +%Y%m%d)
89+
# Today
7690
nowdate=$(date +%Y%m%d)
77-
if [ $nowdate -lt $holddate ]; then
78-
behavior2="move"
91+
92+
# Decide if we are going to proceed with behaviour A (before release) or behaviour B (after release)
93+
behaviorAB=
94+
if [ $nowdate -lt $(date -d "${releasedate}" +%Y%m%d) ]; then
95+
behaviorAB="before"
7996
else
80-
behavior2="hold"
97+
behaviorAB="after"
8198
fi
8299

83-
# Note this could be done by one unique "runFromIssueList" action, but we are splitting
84-
# the search and the update in order to log all the closed issues within jenkins ($logfile)
85-
86-
# 0) Add the "integration_held" (+ std. comment) to new features & improvements issue missing it @ candidates.
87-
88-
# Basically get all the issues in the candidates queue (filter=14000), that are not bug
89-
# and that haven't received any comment with the standard unholding text (NOT filter = 22054)
90-
91-
# Get the list of issues.
92-
${basereq} --action getIssueList \
93-
--search "filter=14000 \
94-
AND type IN ('New Feature', Improvement) \
95-
AND NOT filter = 22054" \
96-
--file "${resultfile}"
97-
98-
# Iterate over found issues and perform the actions with them.
99-
for issue in $( sed -n 's/^"\(MDL-[0-9]*\)".*/\1/p' "${resultfile}" ); do
100-
echo "Processing ${issue}"
101-
# Add the integration_held label.
102-
${basereq} --action addLabels \
103-
--issue ${issue} \
104-
--labels "integration_held"
105-
# Add the standard comment for held issues.
106-
comment='This issue has been sent to integration after the freeze.
107-
108-
If you want Moodle HQ to consider including it into the incoming major release please add the "{{unhold_requested}}" label, and post a comment here outlining good reasons why you think it should be considered for late integration into the next major release.'
109-
${basereq} --action addComment \
110-
--issue ${issue} \
111-
--comment "${comment}"
112-
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} integration_held added" >> "${logfile}"
113-
done
100+
# Decide if we are going to proceed with behaviour A3a (before last week, keep current queue fed)
101+
# or behaviour A3b (last-week, add the integration_held + standard last week message to any issue).
102+
behaviorA3=
103+
if [ $behaviorAB == "before" ]; then # Only calculate this before release.
104+
if [ $nowdate -lt $(date -d "${lastweekdate}" +%Y%m%d) ]; then
105+
behaviorA3="move"
106+
else
107+
behaviorA3="hold"
108+
fi
109+
fi
114110

115-
# 1) Move "important" issues from candidates to current (cleaning integrator and tester).
116-
117-
# Get the list of issues.
118-
${basereq} --action getIssueList \
119-
--search "filter=14000
120-
AND NOT filter = 21366
121-
AND (
122-
filter = 21363 OR
123-
labels IN (mdlqa) OR
124-
priority IN (Critical, Blocker) OR
125-
level IS NOT EMPTY OR
126-
component IN ('Privacy', 'Automated functional tests (behat)', 'Unit tests')
127-
)" \
128-
--file "${resultfile}"
129-
130-
# Iterate over found issues and perform the actions with them.
131-
for issue in $( sed -n 's/^"\(MDL-[0-9]*\)".*/\1/p' "${resultfile}" ); do
132-
echo "Processing ${issue}"
133-
# For fields available in the default screen, it's ok to use updateIssue or SetField, but in this case
134-
# we are setting some custom fields not available (on purpose) on that screen. So we have created a
135-
# global transition, only available to the bots, not transitioning but bringing access to all the fields
136-
# via special screen. So we'll ne using that global transition via progressIssue instead.
137-
# Also, there is one bug in the 4.4.x series, setting the destination as 0, leading to error in the
138-
# execution, so the form was hacked in the browser to store correct -1: https://jira.atlassian.com/browse/JRA-25002
139-
# Commented below, it's the "ideal" code. If some day JIRA changes that restriction we could stop using
140-
# that non-transitional transition and use normal update.
141-
#${basereq} --action updateIssue \
142-
# --issue ${issue} \
143-
# --custom "customfield_10110:,customfield_10210:,customfield_10211:Yes"
144-
${basereq} --action progressIssue \
145-
--issue ${issue} \
146-
--step "CI Global Self-Transition" \
147-
--custom "customfield_10211:Yes,customfield_10110:,customfield_10011:" \
148-
--comment "Continuous queues manage: Moving to current because it's important" \
149-
--role "Integrators"
150-
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} moved to current: important" >> "${logfile}"
151-
done
111+
if [ -n "${dryrun}" ]; then
112+
echo "Dry-run enabled, no changes will be performed to the tracker"
113+
fi
152114

153-
# 2) Move issues away from the current queue:
154-
155-
# 2a) Before a date (last week), keep the current queue fed with issues when it's under a threshold.
156-
157-
if [[ "${behavior2}" == "move" ]]; then
158-
# Count the list of issues in the current queue. (We cannot use getIssueCount till bumping to Jira CLI 8.1, hence, old way)
159-
${basereq} --action getIssueList \
160-
--search "project = MDL \
161-
AND 'Currently in integration' IS NOT EMPTY \
162-
AND status IN ('Waiting for integration review')" \
163-
--file "${resultfile}"
164-
165-
# Iterate over found issues just to count them.
166-
counter=0
167-
for issue in $( sed -n 's/^"\(MDL-[0-9]*\)".*/\1/p' "${resultfile}" ); do
168-
counter=$((counter+1))
169-
done
170-
echo "$counter issues awaiting integration in current queue"
171-
172-
# If there are < $currentmin issues, let's add up to $movemax issues from the candidates queue.
173-
if [[ "$counter" -lt "$currentmin" ]]; then
174-
# Get an ordered list of up to $movemax issues in the candidate queue.
175-
${basereq} --action getIssueList \
176-
--limit $movemax \
177-
--search "filter=14000 \
178-
ORDER BY 'Integration priority' DESC, \
179-
priority DESC, \
180-
votes DESC, \
181-
'Last comment date' ASC" \
182-
--file "${resultfile}"
183-
184-
# Iterate over found issues, moving them to the current queue (cleaning integrator and tester).
185-
for issue in $( sed -n 's/^"\(MDL-[0-9]*\)".*/\1/p' "${resultfile}" ); do
186-
echo "Processing ${issue}"
187-
# For fields available in the default screen, it's ok to use updateIssue or SetField, but in this case
188-
# we are setting some custom fields not available (on purpose) on that screen. So we have created a
189-
# global transition, only available to the bots, not transitioning but bringing access to all the fields
190-
# via special screen. So we'll ne using that global transition via progressIssue instead.
191-
# Also, there is one bug in the 4.4.x series, setting the destination as 0, leading to error in the
192-
# execution, so the form was hacked in the browser to store correct -1: https://jira.atlassian.com/browse/JRA-25002
193-
# Commented below, it's the "ideal" code. If some day JIRA changes that restriction we could stop using
194-
# that non-transitional transition and use normal update.
195-
#${basereq} --action updateIssue \
196-
# --issue ${issue} \
197-
# --custom "customfield_10110:,customfield_10210:,customfield_10211:Yes"
198-
${basereq} --action progressIssue \
199-
--issue ${issue} \
200-
--step "CI Global Self-Transition" \
201-
--custom "customfield_10211:Yes,customfield_10110:,customfield_10011:" \
202-
--comment "Continuous queues manage: Moving to current given we are below the threshold ($currentmin)" \
203-
--role "Integrators"
204-
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} moved to current: threshold (before ${datetoholdbugs})" >> "${logfile}"
205-
done
115+
# Behaviour A, before the release (normally the 6 weeks of continuous).
116+
117+
if [ $behaviorAB == "before" ]; then
118+
# A1, add the "integration_held" + standard comment to any new feature or improvement arriving to candidates.
119+
run_A1
120+
# A2, move "important" issues from candidates to current
121+
run_A2
122+
# A3, move all issues aways from candidates queue:
123+
if [ $behaviorA3 == "move" ]; then
124+
# A3a, keep the current queue fed with bug issues when it's under a threshold.
125+
run_A3a
126+
fi
127+
if [ $behaviorA3 == "hold" ]; then
128+
# A3b, add the "integration_held" + standard comment to any issue arriving to candidates.
129+
run_A3b
206130
fi
207131
fi
208132

209-
# 2b) After a date (last week), add the "integration_held" (+ std.comment) to bug issues.
210-
211-
if [[ "${behavior2}" == "hold" ]]; then
212-
# Get the list of issues in the candidates queue. All them will be held with last week comment.
213-
${basereq} --action getIssueList \
214-
--search "filter=14000" \
215-
--file "${resultfile}"
216-
217-
# Iterate over found issues, moving them to the current queue.
218-
for issue in $( sed -n 's/^"\(MDL-[0-9]*\)".*/\1/p' "${resultfile}" ); do
219-
echo "Processing ${issue}"
220-
# Add the integration_held label.
221-
${basereq} --action addLabels \
222-
--issue ${issue} \
223-
--labels "integration_held"
224-
# Add the standard comment for held issues the last week.
225-
comment='We are currently in the final week before release ( https://docs.moodle.org/dev/Integration_Review#During_continuous_integration.2FFreeze.2FQA_period ) so this issue is being held until after release. Thanks for your patience!'
226-
${basereq} --action addComment \
227-
--issue ${issue} \
228-
--comment "${comment}"
229-
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} integration_held added (since ${datetoholdbugs})" >> "${logfile}"
230-
done
133+
# Behaviour B, after the release (normally the 2 weeks of on-sync).
134+
135+
if [ $behaviorAB == "after" ]; then
136+
# B1a, keep the current queue fed with bug issues when it's under a threshold.
137+
run_B1a
138+
# B1b, add the "integration_held" + standard on-sync comment to any new feature or improvement arriving to candidates.
139+
run_B1b
231140
fi
232141

233142
# Remove the resultfile. We don't want to disclose those details.

0 commit comments

Comments
 (0)