Repository navigation
140 lines (126 loc) · 4.82 KB
/
Copy pathpublish_github_release.yml
File metadata and controls
140 lines (126 loc) · 4.82 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
name: "Publish: Create GitHub release"
# This workflow creates a GitHub Release with release notes after a new
# version is published to PyPI and a tag is pushed.
#
# It is called by publish_to_pypi.yml after the tag push succeeds.
# publish_to_pypi.yml then calls publish_upload_binaries.yml to attach the
# platform binaries from the wheels it published.
on:
workflow_call:
inputs:
tag_name:
description: 'The version tag (e.g. 0.57.0)'
required: true
type: string
secrets:
DISCORD_RELEASES_WEBHOOK_URL:
description: 'Discord webhook URL for the releases channel'
required: false
permissions:
contents: write
jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout repo at tag
uses: actions/checkout@v6
with:
ref: ${{ inputs.tag_name }}
- name: Find release notes file
id: find-notes
run: |
VERSION="${{ inputs.tag_name }}"
NOTES_FILE="release_notes/release-notes-v${VERSION}.md"
if [ -f "$NOTES_FILE" ]; then
echo "notes_file=$NOTES_FILE" >> $GITHUB_OUTPUT
echo "found=true" >> $GITHUB_OUTPUT
echo "Found release notes: $NOTES_FILE"
else
echo "found=false" >> $GITHUB_OUTPUT
echo "No release notes file found at $NOTES_FILE"
echo "Will create release with auto-generated notes"
fi
- name: Determine prerelease flag
id: prerelease
run: |
# Validate the version first, then check prerelease. is-prerelease
# returns exit 1 for stable (which is fine in an if-condition) but
# exit 2 for malformed input (which should fail the step).
python3 scripts/version_helpers.py to-marketplace "${{ inputs.tag_name }}" >/dev/null
if python3 scripts/version_helpers.py is-prerelease "${{ inputs.tag_name }}" >/dev/null; then
echo "prerelease_flag=--prerelease" >> $GITHUB_OUTPUT
else
echo "prerelease_flag=" >> $GITHUB_OUTPUT
fi
- name: Create release with notes file
if: steps.find-notes.outputs.found == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ inputs.tag_name }}" \
${{ steps.prerelease.outputs.prerelease_flag }} \
--title "Pyrefly v${{ inputs.tag_name }}" \
--notes-file "${{ steps.find-notes.outputs.notes_file }}"
- name: Create release with auto-generated notes
if: steps.find-notes.outputs.found != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ inputs.tag_name }}" \
${{ steps.prerelease.outputs.prerelease_flag }} \
--title "Pyrefly v${{ inputs.tag_name }}" \
--generate-notes
notify-discord:
name: Notify Discord
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Check webhook configured
id: check-webhook
env:
WEBHOOK_URL: ${{ secrets.DISCORD_RELEASES_WEBHOOK_URL }}
run: |
if [ -n "$WEBHOOK_URL" ]; then
echo "configured=true" >> $GITHUB_OUTPUT
else
echo "configured=false" >> $GITHUB_OUTPUT
echo "DISCORD_RELEASES_WEBHOOK_URL secret not set, skipping notification"
fi
- name: Send Discord notification
if: steps.check-webhook.outputs.configured == 'true'
env:
WEBHOOK_URL: ${{ secrets.DISCORD_RELEASES_WEBHOOK_URL }}
run: |
VERSION="${{ inputs.tag_name }}"
RELEASE_URL="https://github.com/facebook/pyrefly/releases/tag/${VERSION}"
PAYLOAD=$(cat <<EOF
{
"embeds": [{
"title": "\ud83d\ude80 Pyrefly v${VERSION} Released!",
"url": "${RELEASE_URL}",
"description": "Pyrefly v${VERSION} is now available! Check out the release notes for details on what's new, bug fixes, and more.",
"color": 16744448,
"fields": [
{
"name": "Install / Upgrade",
"value": "\`\`\`bash\npip install --upgrade pyrefly==${VERSION}\n\`\`\`",
"inline": false
},
{
"name": "Links",
"value": "[Release Notes](${RELEASE_URL}) | [PyPI](https://pypi.org/project/pyrefly/${VERSION}/)",
"inline": false
}
],
"footer": {
"text": "Pyrefly - Python Type Checker"
}
}]
}
EOF
)
curl -sf -H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$WEBHOOK_URL"
echo "Discord notification sent for v${VERSION}"