Skip to content

Commit 5050036

Browse files
committed
chore: release label automation
1 parent a4f0004 commit 5050036

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Test Auto-label PR with next release date
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
branches:
7+
- develop # Test on develop branch first
8+
9+
jobs:
10+
add-release-label:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Calculate next release date
14+
id: calculate_date
15+
run: |
16+
# Function to adjust date to next Tuesday if needed
17+
adjust_to_tuesday() {
18+
local input_date="$1"
19+
local day_of_week=$(date -d "$input_date" +%u)
20+
if [ $day_of_week -ne 2 ]; then
21+
local days_to_add=$(( (2 - $day_of_week + 7) % 7 ))
22+
date -d "$input_date + $days_to_add days" +%Y-%m-%d
23+
else
24+
echo "$input_date"
25+
fi
26+
}
27+
28+
RELEASE_START="2025-08-12"
29+
30+
FREEZE_START_1="2025-12-02"
31+
FREEZE_END_1="2025-12-15"
32+
FREEZE_START_2="2025-12-30"
33+
FREEZE_END_2="2026-01-06"
34+
35+
TODAY=$(date +%Y-%m-%d)
36+
37+
# DEBUG: Output initial values
38+
echo "DEBUG: Today: $TODAY"
39+
echo "DEBUG: Release start: $RELEASE_START"
40+
echo "DEBUG: Freeze periods: $FREEZE_START_1 to $FREEZE_END_1, $FREEZE_START_2 to $FREEZE_END_2"
41+
42+
# Calculate which release cycle we're in (releases every 14 days)
43+
DAYS_SINCE_START=$(( ($(date -d "$TODAY" +%s) - $(date -d "$RELEASE_START" +%s)) / 86400 ))
44+
echo "DEBUG: Days since start: $DAYS_SINCE_START"
45+
46+
if [ $DAYS_SINCE_START -lt 0 ]; then
47+
NEXT_RELEASE_DATE="$RELEASE_START"
48+
echo "DEBUG: Using release start date (before first release)"
49+
else
50+
CYCLES_PASSED=$(( $DAYS_SINCE_START / 14 ))
51+
NEXT_CYCLE=$(( $CYCLES_PASSED + 1 ))
52+
NEXT_RELEASE_DATE=$(date -d "$RELEASE_START + $(( $NEXT_CYCLE * 14 )) days" +%Y-%m-%d)
53+
echo "DEBUG: Cycles passed: $CYCLES_PASSED, Next cycle: $NEXT_CYCLE"
54+
fi
55+
56+
echo "DEBUG: Initial calculated date: $NEXT_RELEASE_DATE"
57+
58+
# Skip freeze periods - if calculated date falls during freeze,
59+
# jump to first Tuesday after freeze ends
60+
MAX_ITERATIONS=3 # Safety guard - worst case is 2 freeze periods
61+
ITERATION=0
62+
while [ $ITERATION -lt $MAX_ITERATIONS ]; do
63+
if [[ "$NEXT_RELEASE_DATE" >= "$FREEZE_START_1" && "$NEXT_RELEASE_DATE" <= "$FREEZE_END_1" ]]; then
64+
echo "DEBUG: Date falls in freeze period 1, adjusting..."
65+
NEXT_RELEASE_DATE=$(date -d "$FREEZE_END_1 + 1 day" +%Y-%m-%d)
66+
NEXT_RELEASE_DATE=$(adjust_to_tuesday "$NEXT_RELEASE_DATE")
67+
echo "DEBUG: Adjusted to: $NEXT_RELEASE_DATE"
68+
ITERATION=$((ITERATION + 1))
69+
continue
70+
fi
71+
72+
if [[ "$NEXT_RELEASE_DATE" >= "$FREEZE_START_2" && "$NEXT_RELEASE_DATE" <= "$FREEZE_END_2" ]]; then
73+
echo "DEBUG: Date falls in freeze period 2, adjusting..."
74+
NEXT_RELEASE_DATE=$(date -d "$FREEZE_END_2 + 1 day" +%Y-%m-%d)
75+
NEXT_RELEASE_DATE=$(adjust_to_tuesday "$NEXT_RELEASE_DATE")
76+
echo "DEBUG: Adjusted to: $NEXT_RELEASE_DATE"
77+
ITERATION=$((ITERATION + 1))
78+
continue
79+
fi
80+
81+
break
82+
done
83+
84+
echo "DEBUG: Final iterations used: $ITERATION"
85+
86+
if [ $ITERATION -eq $MAX_ITERATIONS ]; then
87+
echo "Error: Too many freeze period adjustments" >&2
88+
exit 1
89+
fi
90+
91+
if ! date -d "$NEXT_RELEASE_DATE" >/dev/null 2>&1; then
92+
echo "Error: Invalid date calculated" >&2
93+
exit 1
94+
fi
95+
96+
echo "DEBUG: Final release date: $NEXT_RELEASE_DATE"
97+
echo "date=$NEXT_RELEASE_DATE" >> $GITHUB_OUTPUT
98+
99+
- name: Add test release label to PR
100+
uses: actions/github-script@v6
101+
with:
102+
script: |
103+
const nextReleaseDate = "${{ steps.calculate_date.outputs.date }}";
104+
105+
// Validate date format
106+
if (!/^\d{4}-\d{2}-\d{2}$/.test(nextReleaseDate)) {
107+
throw new Error('Invalid date format received');
108+
}
109+
110+
console.log(`Adding test label: test-release:${nextReleaseDate}`);
111+
112+
await github.rest.issues.addLabels({
113+
owner: context.repo.owner,
114+
repo: context.repo.repo,
115+
issue_number: context.payload.pull_request.number,
116+
labels: [`test-release:${nextReleaseDate}`]
117+
});
118+
119+
// Also add a comment for easier verification
120+
await github.rest.issues.createComment({
121+
owner: context.repo.owner,
122+
repo: context.repo.repo,
123+
issue_number: context.payload.pull_request.number,
124+
body: `🧪 **Test Release Labeling**: This PR would be included in release \`${nextReleaseDate}\``
125+
});

0 commit comments

Comments
 (0)