-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsdk-release-pr-notification.yml
More file actions
146 lines (129 loc) · 4.64 KB
/
Copy pathsdk-release-pr-notification.yml
File metadata and controls
146 lines (129 loc) · 4.64 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
name: SDK Release PR Notification
on:
pull_request:
types: [opened, reopened, ready_for_review]
permissions:
contents: read
pull-requests: read
jobs:
notify:
name: Notify Slack
if: >
(github.event.action == 'ready_for_review' || github.event.pull_request.draft == false) &&
(
github.event.pull_request.user.login == 'fern-api[bot]' ||
github.event.pull_request.user.login == 'fern-api' ||
contains(github.event.pull_request.head.ref, 'fern')
)
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.PRODUCTION_RELEASE_OBSERVABILITY_SLACK_WEBHOOK }}
RUNBOOK_URL: https://github.com/VapiAI/docs/blob/main/.github/runbooks/sdk-release-approval.md
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Detect package metadata
id: package
shell: bash
run: |
set -euo pipefail
repo="${GITHUB_REPOSITORY#*/}"
package="unknown"
registry="unknown"
case "$repo" in
server-sdk-typescript)
package="@vapi-ai/server-sdk"
registry="npm"
;;
server-sdk-python)
package="vapi_server_sdk"
registry="PyPI"
;;
server-sdk-go)
package="github.com/VapiAI/server-sdk-go"
registry="Go modules"
;;
server-sdk-ruby)
package="vapi_server_sdk"
registry="RubyGems"
;;
server-sdk-csharp)
package="Vapi.Net"
registry="NuGet"
;;
server-sdk-php)
package="vapi/vapi"
registry="Packagist"
;;
server-sdk-swift)
package="Vapi"
registry="Swift Package Manager"
;;
esac
version="$(node <<'NODE'
const fs = require('fs');
const readJson = (path) => {
try {
return JSON.parse(fs.readFileSync(path, 'utf8'));
} catch {
return undefined;
}
};
const firstMatch = (path, regex) => {
if (!fs.existsSync(path)) return undefined;
return fs.readFileSync(path, 'utf8').match(regex)?.[1];
};
const metadata = readJson('.fern/metadata.json');
const packageJson = readJson('package.json');
const composerJson = readJson('composer.json');
const version =
metadata?.sdkVersion ||
packageJson?.version ||
composerJson?.version ||
firstMatch('pyproject.toml', /^version = "([^"]+)"/m) ||
firstMatch('src/Vapi.Net/Vapi.Net.csproj', /<Version>([^<]+)<\/Version>/) ||
firstMatch('lib/vapi/version.rb', /VERSION = "([^"]+)"/) ||
'unknown';
process.stdout.write(version);
NODE
)"
{
echo "package=$package"
echo "registry=$registry"
echo "version=$version"
} >> "$GITHUB_OUTPUT"
- name: Send Slack notification
shell: bash
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PACKAGE_NAME: ${{ steps.package.outputs.package }}
PACKAGE_REGISTRY: ${{ steps.package.outputs.registry }}
PACKAGE_VERSION: ${{ steps.package.outputs.version }}
run: |
set -euo pipefail
if [ -z "${SLACK_WEBHOOK_URL}" ]; then
echo "::warning::PRODUCTION_RELEASE_OBSERVABILITY_SLACK_WEBHOOK is not set; skipping Slack notification."
exit 0
fi
text="$(cat <<EOF
*SDK release PR ready for review*
*Repo:* \`${GITHUB_REPOSITORY}\`
*PR:* <${PR_URL}|#${PR_NUMBER} ${PR_TITLE}>
*Author:* \`${PR_AUTHOR}\`
*Package:* \`${PACKAGE_NAME}\` (${PACKAGE_REGISTRY})
*Version:* \`${PACKAGE_VERSION}\`
*Next:* Review and merge the PR, then publish the release tag from the SDK repo.
*Runbook:* <${RUNBOOK_URL}|SDK release approval runbook>
EOF
)"
payload="$(jq -n --arg text "$text" '{text: $text}')"
curl --fail --show-error --silent \
--request POST \
--header 'Content-Type: application/json' \
--data "$payload" \
"$SLACK_WEBHOOK_URL"