-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (66 loc) · 3.65 KB
/
create-milestones.yml
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
name: Create Milestone
on:
workflow_dispatch:
inputs:
due_date:
description: "Provide the due date for the milestone (format: YYYY-MM-DD)"
required: false
default: ""
schedule:
- cron: '0 12 * * 3' # Every Wednesday at noon UTC
permissions:
issues: write
contents: read
jobs:
create-milestone:
runs-on: ubuntu-latest
steps:
- name: Create Milestone
run: |
#!/bin/bash
# Explicitly set the timezone to UTC
export TZ=UTC
echo "Debug: Manually Entered Due Date: ${{ github.event.inputs.due_date }}"
# Get the input date from workflow_dispatch (if provided) or use default logic
if [ -n "${{ github.event.inputs.due_date }}" ]; then
# Use the provided date from workflow_dispatch input
DUE_DATE="${{ github.event.inputs.due_date }}"
echo "Manual input provided. Using input date: $DUE_DATE"
else
# No manual input, use the default: 2 weeks from now
DUE_DATE=$(date -u -d '2 weeks' '+%Y-%m-%d')
echo "No manual input. Using default date 2 weeks from now: $DUE_DATE"
fi
# Set the date format for the milestone title and due date
DATE=$(date -u -d "$DUE_DATE" '+%B %-d, %Y') # Human-readable date
DATE_ISO8601=$(date -u -d "$DUE_DATE" '+%Y-%m-%dT23:59:59Z') # ISO8601 format
# Prepare the description for the milestone
DESCRIPTION="The release is scheduled for $DATE, and PRs should be submitted and made mergeable by EOD $DATE. This means they should have tests passing and merge conflicts resolved. The description for the PR must include details of what is included in the PR and how to test it, and preferably new tests supporting the update.\n\nAny PRs submitted after the deadline will not be included in the release but go in the next release. This includes PRs with tests failing, no description, no screenshots/video demonstrating the update, sufficient Cypress tests, no link to associated JIRA ticket, etc. If no mergeable PRs are submitted for a release, there will be no release that week (unless there is a need for an out-of-cycle release)."
# Debugging outputs
echo "Debug: Human-readable Date: $DATE"
echo "Debug: ISO8601 Date: $DATE_ISO8601"
echo "Debug: Description content: $DESCRIPTION"
# Prepare the JSON payload for the API request
PAYLOAD="{\"title\":\"$DATE Release\", \"description\":\"$DESCRIPTION\", \"due_on\":\"$DATE_ISO8601\", \"state\":\"open\"}"
# Debugging the JSON payload
echo "Debug: Payload: $PAYLOAD"
# Perform the curl request and capture the response
RESPONSE=$(curl -s -w "%{http_code}" -o response_body.txt -X POST \
-H "User-Agent: GitHub-API-Request" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/milestones \
-d "$PAYLOAD")
# Capture HTTP status code and response body
HTTP_STATUS=$(tail -n1 <<< "$RESPONSE")
RESPONSE_BODY=$(cat response_body.txt)
# Debugging the HTTP status and response body
echo "Debug: HTTP Status: $HTTP_STATUS"
echo "Debug: Response Body: $RESPONSE_BODY"
# If the request fails, exit with an error
if [[ "$HTTP_STATUS" -ge 400 ]]; then
echo "Error: Failed to create a milestone."
exit 1
fi
echo "Milestone created successfully."
echo "Response body: $RESPONSE_BODY"