-
Notifications
You must be signed in to change notification settings - Fork 48
163 lines (143 loc) · 5.94 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
name: Publish to npm, Tag and create GH Release
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
Timestamp:
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main
print_version_to_publish:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
version_to_be_published: ${{ steps.get_version_to_publish.outputs.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 "VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
# Fetch the latest version from NPM
fetch_latest_version:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
LATEST_VERSION: ${{ steps.get_latest_version.outputs.LATEST_VERSION }}
steps:
- name: Get latest package version
id: get_latest_version
run: |
LATEST_VERSION=$(npm view @story-protocol/core-sdk version)
echo "Latest version of @story-protocol/core-sdk on NPMJS is $LATEST_VERSION"
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_OUTPUT
# Fail the PR if the version to be published is the same as the latest version on NPM
fail_if_version_is_same:
needs: [print_version_to_publish, fetch_latest_version]
runs-on: ubuntu-latest
steps:
- name: Fail if version is the same
run: |
if [ "${{ needs.fetch_latest_version.outputs.LATEST_VERSION }}" == "${{ needs.print_version_to_publish.outputs.version_to_be_published }}" ]; then
echo "The version to be published is the same as the latest version on NPM. Exiting..."
exit 1
fi
build-test-publish:
needs: [print_version_to_publish, fetch_latest_version, fail_if_version_is_same]
# Skip this job if the version to be published is the same as the latest version on NPM
# and the event triggering the workflow is a push
if: needs.fetch_latest_version.outputs.LATEST_VERSION != needs.print_version_to_publish.outputs.version_to_be_published && 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@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.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} --block-time 1 --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 to npm
run: |
cd packages/core-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create_release:
needs: [print_version_to_publish, fetch_latest_version, fail_if_version_is_same]
# Skip this job if the version to be published is the same as the latest version on NPM
# and the event triggering the workflow is a push
if: needs.fetch_latest_version.outputs.LATEST_VERSION != needs.print_version_to_publish.outputs.version_to_be_published && github.event_name == 'push'
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@main
with:
version_to_publish: ${{ needs.print_version_to_publish.outputs.version_to_be_published }}
send_slack_notif:
needs: [build-test-publish, create_release]
runs-on: ubuntu-latest
steps:
- name: Push Slack Notification
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
payload: |
{
"text": "${{ github.repository }}: Package has been published to NPM Registry.",
"blocks": [
{ "type": "divider" },
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Published to Registry"
},
"image_url": "https://imgur.com/gallery/npm-install-OsbqxXW",
"alt_text": "Published to Registry"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text":"${{ github.repository }}: Package has been published to NPM Registry"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}