-
Notifications
You must be signed in to change notification settings - Fork 11.2k
117 lines (98 loc) · 5.41 KB
/
release-notes-monitor.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
name: Release Notes Monitor
on:
workflow_dispatch:
schedule:
- cron: '0 */3 * * *' # every 3 hours
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 }}
existing_commit_tag: ${{ steps.get-pr-list.outputs.existing_commit_tag }}
new_tag: ${{ steps.get-pr-list.outputs.new_tag }}
sui_version: ${{ steps.get-pr-list.outputs.sui_version }}
runs-on: ubuntu-latest
steps:
- name: Checkout sui repo main branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
with:
fetch-depth: 0
ref: main
- name: Get list of PRs
id: get-pr-list
working-directory: ./
run: |
export new_commit_hash=$(git rev-parse HEAD)
export existing_commit_tag=$(git tag --points-at ${new_commit_hash} | grep -E 'sui_v(.*)_rel_notes' | head -n 1)
export previous_tag=$(git tag | grep -E 'sui_v1(.*)_rel_notes' | sort -rV | head -1)
export previous_commit_hash=$(git rev-list -n 1 ${previous_tag})
export list_of_prs=$(git log --grep "\[x\]" --pretty=oneline --abbrev-commit ${previous_commit_hash}...${new_commit_hash} -- consensus crates dashboards doc docker external-crates kiosk nre sui-execution | grep -o '#[0-9]\+' | grep -o '[0-9]\+' | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${list_of_prs}" >> $GITHUB_OUTPUT
echo "new_commit_hash=${new_commit_hash}" >> $GITHUB_OUTPUT
echo "existing_commit_tag=${existing_commit_tag}" >> $GITHUB_OUTPUT
export sui_crate_version=$(cat Cargo.toml | grep "^version =" | tr -d '"' | awk '{ print $3 }')
export new_tag=$(echo "sui_v${sui_crate_version}_$(date +%s)_rel_notes")
echo "new_tag=${new_tag}" >> $GITHUB_OUTPUT
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: Reading Release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Processing PR#${{ matrix.pr }}"
# old format
export rel_notes=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/MystenLabs/sui/pulls/${{ matrix.pr }} --jq ".body" | awk '/### Release notes/{p=1; next} p' | sed '/^[[:space:]]*$/d')
# new format
[[ -z $rel_notes ]] && export rel_notes=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/MystenLabs/sui/pulls/${{ matrix.pr }} --jq ".body" | awk '/^\- \[x\]/')
# make text json payload friendly
rel_notes="${rel_notes//\\/\\\\}"
rel_notes="${rel_notes//\"/\\\"}"
rel_notes="${rel_notes//$'\r'/}"
echo "release_notes=${rel_notes}" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # pin v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Get PR author
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export author=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/MystenLabs/sui/pulls/${{ matrix.pr }} --jq ".user.login")
export slack_id=$(aws s3 cp s3://mysten-employees-dir/employees.json - | jq --arg AUTHOR "${author}" '.[] | if .github_handle == $AUTHOR then .slack_id else empty end')
# if we don't have the slack id or the author is not part of Mysten org, get the reviewer instead
if [ -z "$slack_id" ]; then
export reviewer=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/MystenLabs/sui/pulls/${{ matrix.pr }}/reviews --jq ".[0].user.login")
export slack_id=$(aws s3 cp s3://mysten-employees-dir/employees.json - | jq --arg AUTHOR "${reviewer}" '.[] | if .github_handle == $AUTHOR then .slack_id else empty end')
fi
echo "slack_id=$(echo ${slack_id} | tr -d '"')" >> $GITHUB_ENV
- name: Post to a Slack channel
uses: slackapi/slack-github-action@34c3fd73326693ef04728f8611669d918a2d781d # [email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: '#ext-mysten-release-notes'
slack-message: |
<@U03LRLPR1QX> and <@U04A8V9E203>, please review release notes for upcoming `v${{ needs.get-list-of-prs.outputs.sui_version }}` release.
*PR* <https://github.com/MystenLabs/sui/pull/${{ matrix.pr }}|${{ matrix.pr }}> by <@${{ env.slack_id }}>
*Release Notes:*
${{ env.release_notes }}
tag:
name: Adding git tag to processed commit
needs: [ get-list-of-prs ]
if: ${{ success() && needs.get-list-of-prs.outputs.existing_commit_tag == '' }}
uses: mystenlabs/sui/.github/workflows/tag.yml@main
with:
sui_commit: ${{ needs.get-list-of-prs.outputs.new_commit_hash }}
tag_name: ${{ needs.get-list-of-prs.outputs.new_tag }}
secrets: inherit