-
Notifications
You must be signed in to change notification settings - Fork 140
167 lines (142 loc) · 6.28 KB
/
schedule-last-call-date-end.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Schedule Status Update Based on Last Call Time
permissions:
pull-requests: write
contents: write
packages: write
defaults:
run:
shell: bash
on:
pull_request:
types: [closed]
branches:
- main
jobs:
check-merged-file:
if: github.event.pull_request.merged == true
runs-on: improvement-proposals-linux-medium
steps:
- name: Check out the code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Get modified files
id: get-modified-files
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
FILES=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/files" | jq -r '.[].filename')
echo "Modified files:"
echo "$FILES"
echo "modified_files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check if modified files are in the HIP directory and have a .md extension
if: steps.get-modified-files.outputs.modified_files != ''
id: check-hip-files
run: |
HIP_FILES=""
while IFS= read -r file; do
if [[ $file == HIP/*.md ]]; then
HIP_FILES="$HIP_FILES $file"
fi
done <<< "${{ steps.get-modified-files.outputs.modified_files }}"
if [ -z "$HIP_FILES" ]; then
echo "No modified HIP files found."
else
echo "Modified HIP files: $HIP_FILES"
echo "hip_files=$HIP_FILES" >> $GITHUB_OUTPUT
fi
- name: Check if modified files are in Last Call
if: steps.check-hip-files.outputs.hip_files != ''
id: check-last-call
run: |
last_call_files=""
for file in ${{ steps.check-hip-files.outputs.hip_files }}; do
if grep -qE '^status: Last Call' "$file"; then
last_call_files="$last_call_files $file"
fi
done
if [[ -n "$last_call_files" ]]; then
echo "Files in Last Call: $last_call_files"
echo "last_call_files=$last_call_files" >> $GITHUB_OUTPUT
else
echo "No files in Last Call"
fi
- name: Calculate Delay Until Last Call
if: steps.check-last-call.outputs.last_call_files != ''
id: calculate-delay
run: |
first_last_call_file=$(echo "${{ steps.check-last-call.outputs.last_call_files }}" | awk '{print $1}')
last_call_time=$(grep -oP '(?<=^last-call-date-time: ).*' "$first_last_call_file")
echo "Last Call Date Time: $last_call_time"
target_epoch=$(date -d "$last_call_time" +%s)
current_epoch=$(date +%s)
delay_seconds=$((target_epoch - current_epoch))
echo "Delay in seconds: $delay_seconds"
if [[ $delay_seconds -gt 0 ]]; then
echo "Delaying PR creation and automerge for $delay_seconds seconds."
echo "delay_seconds=$delay_seconds" >> $GITHUB_OUTPUT
else
echo "The last-call date-time is in the past. Skipping delay."
exit 1
fi
- name: Delay Until Last Call
if: steps.calculate-delay.outputs.delay_seconds != ''
run: |
delay_seconds=${{ steps.calculate-delay.outputs.delay_seconds }}
echo "Sleeping for $delay_seconds seconds"
sleep "$delay_seconds"
- name: Update HIP status and Add/Update `updated` Date
if: steps.check-last-call.outputs.last_call_files != ''
run: |
current_date=$(date +%Y-%m-%d)
for file in ${{ steps.check-last-call.outputs.last_call_files }}; do
hip_type=$(grep -oP '(?<=^type: ).*' "$file")
hip_category=$(grep -oP '(?<=^category: ).*' "$file")
echo "Processing file: $file"
echo "Extracted type: $hip_type"
echo "Extracted category: $hip_category"
new_status=""
if [[ "$hip_type" == "Standards Track" ]]; then
if [[ "$hip_category" == "Core" || "$hip_category" == "Service" || "$hip_category" == "Mirror" ]]; then
new_status="Council Review"
elif [[ "$hip_category" == "Application" ]]; then
new_status="Accepted"
fi
elif [[ "$hip_type" == "Informational" || "$hip_type" == "Process" ]]; then
new_status="Active"
fi
if [[ -n "$new_status" ]]; then
# Update status
sed -i "s/^status: Last Call/status: $new_status/" "$file"
# Update or add `updated` property before the final "---"
if grep -q '^updated: ' "$file"; then
sed -i "s/^updated:.*/updated: $current_date/" "$file"
else
sed -i "/^---$/i updated: $current_date" "$file"
fi
echo "Updated status of $file to $new_status and set updated date to $current_date"
else
echo "Unable to determine the new status for $file. Check the type and category fields."
fi
done
- name: Create PR for status update
if: steps.check-last-call.outputs.last_call_files != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: create-pr
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
git add .
git commit -m "Update HIP status and set updated date"
git push origin HEAD:status-update-${{ github.sha }}
PR_URL=$(gh pr create --title "Update HIP status" --body "Automatically updating the status of HIPs in Last Call and setting the updated date based on the type and category." --base main --head status-update-${{ github.sha }})
echo "Pull request created at $PR_URL"
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
- name: Auto-merge PR
if: steps.create-pr.outputs.pr_url != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(echo "${{ steps.create-pr.outputs.pr_url }}" | grep -oP '\d+$')
echo "Merging PR number: $PR_NUMBER"
gh pr merge $PR_NUMBER --merge --auto --body "Auto-merged via GitHub Actions"