-
Notifications
You must be signed in to change notification settings - Fork 11.7k
156 lines (133 loc) · 5.92 KB
/
Copy pathrelease-notes-monitor.yml
File metadata and controls
156 lines (133 loc) · 5.92 KB
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
name: Release Notes Monitor
on:
workflow_dispatch:
schedule:
- cron: '0 */3 * * *' # every 3 hours
# Required for updating repository variables
permissions:
contents: read
actions: write
jobs:
get-list-of-prs:
name: Get Release Notes for new PRs
outputs:
matrix: ${{ steps.get-pr-list.outputs.matrix }}
new_commit_hash: ${{ steps.get-pr-list.outputs.new_commit_hash }}
sui_version: ${{ steps.get-pr-list.outputs.sui_version }}
runs-on: ubuntu-latest
steps:
- name: Checkout sui repo main branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # pin@v6.0.2
with:
fetch-depth: 0
ref: main
- name: Setup Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # pin@v6.2.0
with:
python-version: 3.10.10
- name: Get list of PRs
id: get-pr-list
working-directory: ./
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export new_commit_hash=$(git rev-parse HEAD)
# Use repo variable to track last processed commit instead of tags
export last_processed_commit="${{ vars.RELEASE_NOTES_LAST_COMMIT }}"
# If no last processed commit, default to only checking last 50 commits for safety
# This prevents processing entire history if variable is missing/deleted
if [ -z "$last_processed_commit" ]; then
last_processed_commit=$(git rev-parse HEAD~50 2>/dev/null || git rev-list --max-parents=0 HEAD)
echo "Warning: RELEASE_NOTES_LAST_COMMIT variable not set, defaulting to last 50 commits"
echo "Starting from: $last_processed_commit"
fi
# Use the release_notes.py script to get the list of PRs with release notes
export list_of_prs=$(python3 ./scripts/release_notes.py list-prs "${last_processed_commit}" "${new_commit_hash}")
echo "matrix=${list_of_prs}" >> $GITHUB_OUTPUT
echo "new_commit_hash=${new_commit_hash}" >> $GITHUB_OUTPUT
export sui_crate_version=$(cat Cargo.toml | grep "^version =" | tr -d '"' | awk '{ print $3 }')
echo "sui_version=${sui_crate_version}" >> $GITHUB_OUTPUT
process-prs:
name: Processing PR
needs: [ get-list-of-prs ]
if: ${{ needs.get-list-of-prs.outputs.matrix != '[]' && needs.get-list-of-prs.outputs.matrix != '' }}
runs-on: ubuntu-latest
strategy:
matrix:
pr: ${{ fromJson(needs.get-list-of-prs.outputs.matrix) }}
steps:
- name: Checkout sui repo main branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # pin@v6.0.2
with:
ref: main
- name: Setup Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # pin@v6.2.0
with:
python-version: 3.10.10
- name: Reading Release notes
id: read-notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Processing PR#${{ matrix.pr }}"
# Use the release_notes.py script to get formatted release notes
rel_notes=$(python ./scripts/release_notes.py get-notes "${{ matrix.pr }}")
# make text json payload friendly
rel_notes=$(sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\r//g' <<<"$rel_notes")
# Use random delimiter to prevent injection attacks
delimiter="EOF_$(dd if=/dev/urandom bs=15 count=1 2>/dev/null | base64 | tr -d '\n=+/')"
{
echo "release_notes<<${delimiter}"
printf '%s\n' "$rel_notes"
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
- name: Get PR author and title
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch PR info (author and title) in one API call
pr_info=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/MystenLabs/sui/pulls/${{ matrix.pr }})
author=$(echo "$pr_info" | jq -r ".user.login")
pr_title=$(echo "$pr_info" | jq -r ".title")
# Escape special characters for Slack mrkdwn format (& < > must be escaped)
pr_title=$(echo "$pr_title" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
echo "author=${author}" >> $GITHUB_ENV
echo "pr_title=${pr_title}" >> $GITHUB_ENV
- name: Dispatch to sui-operations for notification
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # pin@v4.0.1
with:
token: ${{ secrets.DOCKER_BINARY_BUILDS_DISPATCH }}
repository: MystenLabs/sui-operations
event-type: release-notes-review
client-payload: |-
{
"pr_number": "${{ matrix.pr }}",
"pr_title": "${{ env.pr_title }}",
"author": "${{ env.author }}",
"release_notes": ${{ toJSON(steps.read-notes.outputs.release_notes) }},
"sui_version": "${{ needs.get-list-of-prs.outputs.sui_version }}"
}
update-last-processed-commit:
name: Update last processed commit
needs: [ get-list-of-prs, process-prs ]
if: ${{ always() && needs.get-list-of-prs.result == 'success' && (needs.process-prs.result == 'success' || needs.process-prs.result == 'skipped') }}
runs-on: ubuntu-latest
steps:
- name: Update RELEASE_NOTES_LAST_COMMIT variable
env:
# Requires a PAT with repo scope to update repository variables
GH_TOKEN: ${{ secrets.SUI_CREATE_RELEASE }}
run: |
# Retry up to 3 times to ensure variable is updated
for attempt in 1 2 3; do
if gh variable set RELEASE_NOTES_LAST_COMMIT \
--repo MystenLabs/sui \
--body "${{ needs.get-list-of-prs.outputs.new_commit_hash }}"; then
echo "Updated RELEASE_NOTES_LAST_COMMIT to ${{ needs.get-list-of-prs.outputs.new_commit_hash }}"
exit 0
fi
echo "Attempt $attempt failed, retrying in 5 seconds..."
sleep 5
done
echo "ERROR: Failed to update RELEASE_NOTES_LAST_COMMIT after 3 attempts"
exit 1