-
Notifications
You must be signed in to change notification settings - Fork 45
290 lines (266 loc) · 14 KB
/
publish-package.yaml
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
name: Publish to npm, Tag and create GH Release
on:
push:
branches:
- main
- v1.1
pull_request:
branches:
- main
- v1.1
env:
VERSION_1_1: "1.1"
VERSION_1_2: "1.2"
MAIN: "main"
DEV: "dev"
jobs:
Timestamp:
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main
print_version_to_publish:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
core_sdk_version_to_be_published: ${{ steps.get_version_to_publish.outputs.CORE_SDK_VERSION_TO_BE_PUBLISHED }}
react_sdk_version_to_be_published: ${{ steps.get_version_to_publish.outputs.REACT_SDK_VERSION_TO_BE_PUBLISHED }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Get version to publish
id: get_version_to_publish
run: |
content=$(cat packages/core-sdk/package.json)
echo "CORE_SDK_VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
content=$(cat packages/react-sdk/package.json)
echo "REACT_SDK_VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
extract_branch_name:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.extract_branch_name.outputs.BRANCH_NAME }}
steps:
- name: Extract branch name
id: extract_branch_name
run: |
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
else
echo "BRANCH_NAME=${GITHUB_BASE_REF}" >> $GITHUB_OUTPUT
fi
# Fetch the latest version from NPM
fetch_latest_version:
needs: [Timestamp, extract_branch_name]
runs-on: ubuntu-latest
outputs:
core_sdk_latest_version: ${{ steps.get_latest_version.outputs.CORE_SDK_LATEST_VERSION }}
react_sdk_latest_version: ${{ steps.get_latest_version.outputs.REACT_SDK_LATEST_VERSION }}
steps:
- name: Get latest package version
id: get_latest_version
run: |
get_latest_version() {
prefix=$1
package_name=$2
variable_key=$3
all_versions=$(npm view "$package_name" versions --json)
if [[ "$all_versions" == "["* ]]; then
filtered_versions=$(echo "$all_versions" | jq -r "[.[] | select(startswith(\"$prefix\"))]")
echo "filtered_versions1: $filtered_versions"
else
filtered_versions=$(echo "[$all_versions]" | jq -r "[.[] | select(startswith(\"$prefix\"))]")
echo "filtered_versions2: $filtered_versions"
fi
latest_version=$(echo "$filtered_versions" | jq -r '.[-1]')
if [ "$latest_version" == "null" ]; then
latest_version="Not_Published"
fi
echo "Latest version of $package_name on NPMJS with prefix $prefix is $latest_version"
echo "$variable_key=$latest_version" >> $GITHUB_OUTPUT
}
BRANCH_NAME="${{ needs.extract_branch_name.outputs.branch_name }}"
if [[ "$BRANCH_NAME" == "v${{ env.VERSION_1_1 }}" || "$BRANCH_NAME" == "dev_v${{ env.VERSION_1_1 }}" ]]; then
get_latest_version "${{ env.VERSION_1_1 }}" "@story-protocol/core-sdk" "CORE_SDK_LATEST_VERSION"
get_latest_version "${{ env.VERSION_1_1 }}" "@story-protocol/react-sdk" "REACT_SDK_LATEST_VERSION"
elif [[ "$BRANCH_NAME" == "${{ env.MAIN }}" || "$BRANCH_NAME" == ${{ env.DEV }} ]]; then
get_latest_version "${{ env.VERSION_1_2 }}" "@story-protocol/core-sdk" "CORE_SDK_LATEST_VERSION"
get_latest_version "${{ env.VERSION_1_2 }}" "@story-protocol/react-sdk" "REACT_SDK_LATEST_VERSION"
fi
# Fail if the version including react-sdk and core-sdk does not match the branch strategy
check_if_version_is_valid_for_branch:
needs: [extract_branch_name, print_version_to_publish, fetch_latest_version]
runs-on: ubuntu-latest
outputs:
is_publish_core_sdk: ${{ steps.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_CORE_SDK }}
is_publish_react_sdk: ${{ steps.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_REACT_SDK }}
steps:
- name: Check if version is valid for branch
id: check_if_version_is_valid_for_branch
run: |
BRANCH_NAME="${{ needs.extract_branch_name.outputs.branch_name }}"
CORE_SDK_PUBLISH_VERSION="${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}"
REACT_SDK_PUBLISH_VERSION="${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}"
CORE_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.core_sdk_latest_version }}"
REACT_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.react_sdk_latest_version }}"
if [[ "$BRANCH_NAME" == "v${{ env.VERSION_1_1 }}" || "$BRANCH_NAME" == "dev_v${{ env.VERSION_1_1 }}" ]]; then
if ! [[ "$CORE_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_1 }} ]] && ! [[ "$REACT_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_1 }} ]]; then
echo "Error: Invalid version @story-protocol/core-sdk@$CORE_SDK_PUBLISH_VERSION and @story-protocol/react-sdk@$REACT_SDK_PUBLISH_VERSION for branch 'v${{ env.VERSION_1_1 }}', only versions starting with '${{ env.VERSION_1_1 }}' are allowed in v${{ env.VERSION_1_1 }} branch"
exit 1
fi
if [[ "$CORE_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_1 }} && "$CORE_SDK_PUBLISH_VERSION" != "$CORE_SDK_LATEST_VERSION" ]]; then
echo "IS_PUBLISH_CORE_SDK=true" >> $GITHUB_OUTPUT
fi
if [[ "$REACT_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_1 }} && "$REACT_SDK_PUBLISH_VERSION" != "$REACT_SDK_LATEST_VERSION" ]]; then
echo "IS_PUBLISH_REACT_SDK=true" >> $GITHUB_OUTPUT
fi
elif [[ "$BRANCH_NAME" == "${{ env.MAIN }}" || "$BRANCH_NAME" == "${{ env.DEV }}" ]]; then
if ! [[ "$CORE_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_2 }} ]] && ! [[ "$REACT_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_2 }} ]]; then
echo "Error: Invalid version @story-protocol/core-sdk@$CORE_SDK_PUBLISH_VERSION and @story-protocol/react-sdk@$REACT_SDK_PUBLISH_VERSION for branch '${{ env.MAIN }}', only versions starting with '${{ env.VERSION_1_2 }}' are allowed in ${{ env.MAIN }} branch"
exit 1
fi
if [[ "$CORE_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_2 }} && "$CORE_SDK_PUBLISH_VERSION" != "$CORE_SDK_LATEST_VERSION" ]]; then
echo "IS_PUBLISH_CORE_SDK=true" >> $GITHUB_OUTPUT
fi
if [[ "$REACT_SDK_PUBLISH_VERSION" =~ ^${{ env.VERSION_1_2 }} && "$REACT_SDK_PUBLISH_VERSION" != "$REACT_SDK_LATEST_VERSION" ]]; then
echo "IS_PUBLISH_REACT_SDK=true" >> $GITHUB_OUTPUT
fi
fi
# Fail react-sdk and core-sdk don't need to be published
check_is_publish:
needs:
[
print_version_to_publish,
fetch_latest_version,
check_if_version_is_valid_for_branch,
extract_branch_name,
]
runs-on: ubuntu-latest
steps:
- name: Fail if version is the same
run: |
IS_PUBLISH_CORE_SDK="${{ needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_CORE_SDK }}"
IS_PUBLISH_REACT_SDK="${{ needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_REACT_SDK }}"
BRANCH_NAME="${{ needs.extract_branch_name.outputs.branch_name }}"
CORE_SDK_PUBLISH_VERSION="${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}"
REACT_SDK_PUBLISH_VERSION="${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}"
CORE_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.core_sdk_latest_version }}"
REACT_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.react_sdk_latest_version }}"
BRANCH_DESCRIPTION=$([[ "$BRANCH_NAME" == "${{ env.MAIN }}" || "$BRANCH_NAME" == "${{ env.DEV }}" ]] && echo "v${{ env.VERSION_1_2 }}" || echo "v${{ env.VERSION_1_1 }}")
if [ "$IS_PUBLISH_CORE_SDK" != "true" ] && [ "$IS_PUBLISH_REACT_SDK" != "true" ]; then
echo "This is $BRANCH_DESCRIPTION branch, The @story-protocol/core-sdk cannot be published, because the latest version on NPM is $CORE_SDK_LATEST_VERSION and the version to be published is $CORE_SDK_PUBLISH_VERSION. The @story-protocol/react-sdk cannot be published, because the latest version on NPM is $REACT_SDK_LATEST_VERSION and the version to be published is $REACT_SDK_PUBLISH_VERSION."
exit 1
fi
build-test-publish:
needs:
[
print_version_to_publish,
fetch_latest_version,
check_is_publish,
check_if_version_is_valid_for_branch,
]
# Skip this job if the core-sdk and react-sdk don't need to be published
# and the event triggering the workflow is a push
if: ${{ (needs.check_if_version_is_valid_for_branch.outputs.is_publish_core_sdk == 'true' || needs.check_if_version_is_valid_for_branch.outputs.is_publish_react_sdk == 'true') && github.event_name == 'push' }}
runs-on: ubuntu-latest
environment: "beta-sepolia"
env:
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }}
SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }}
TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_SEPOLIA_RPC_PROVIDER_URL }}
SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }}
SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }}
STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }}
STORY_TEST_NET_WALLET_PRIVATE_KEY: ${{ secrets.STORY_TEST_NET_WALLET_PRIVATE_KEY }}
STORY_TEST_NET_TEST_WALLET_ADDRESS: ${{ secrets.STORY_TEST_NET_TEST_WALLET_ADDRESS }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 8.8.0
- name: Setup Node.js environment
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: 20.0.0
cache: pnpm
registry-url: https://registry.npmjs.org/
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install dependencies
run: pnpm install
- name: Fix
run: pnpm fix
- name: Run Anvil
id: run_anvil
run: anvil --fork-url ${SEPOLIA_RPC_PROVIDER_URL} --silent &
- name: Check on Run Anvil
if: steps.run_anvil.outcome != 'success'
run: exit 1
- name: Test
run: pnpm test
- name: Build
run: pnpm build
- name: Publish core-sdk package to npm
if: ${{ github.event_name == 'push' && needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_CORE_SDK == 'true'}}
run: |
cd packages/core-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish react-sdk package to npm
if: ${{ github.event_name == 'push' && needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_REACT_SDK == 'true'}}
run: |
cd packages/react-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create-release-core-sdk:
needs:
[
build-test-publish,
print_version_to_publish,
check_if_version_is_valid_for_branch,
]
# Skip this job if core-sdk doesn't need to be published
# and the event triggering the workflow is a push
if: ${{ github.event_name == 'push' && needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_CORE_SDK == 'true'}}
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@main
with:
tag_name: core-sdk@${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}
send_slack_notif-core-sdk:
needs: [print_version_to_publish, create-release-core-sdk]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-slack-notifs.yml@main
with:
short-desc: "${{ github.repository }}: core-sdk package has been published to NPM Registry, version: ${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published}}"
title: "Published to Registry"
img-url: "https://i.imgur.com/JHmKB0s.png"
img-alt-text: "Published to Registry"
secrets:
channel-name: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
create-release-react-sdk:
needs:
[
build-test-publish,
print_version_to_publish,
check_if_version_is_valid_for_branch,
]
# Skip this job if react-sdk doesn't need to be published
# and the event triggering the workflow is a push
if: ${{ github.event_name == 'push' && needs.check_if_version_is_valid_for_branch.outputs.IS_PUBLISH_REACT_SDK == 'true'}}
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@main
with:
tag_name: react-sdk@${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}
send_slack_notif-react-sdk:
needs: [print_version_to_publish, create-release-react-sdk]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-slack-notifs.yml@main
with:
short-desc: "${{ github.repository }}: react-sdk package has been published to NPM Registry, version: ${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}"
title: "Published to Registry"
img-url: "https://i.imgur.com/JHmKB0s.png"
img-alt-text: "Published to Registry"
secrets:
channel-name: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}