Skip to content

Commit 925ef8f

Browse files
committed
ci: add npm publish steps for contracts, utils, and chainservice on feat/publish-packages branch
1 parent a2d9a54 commit 925ef8f

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

.github/workflows/build-test-deploy.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- testnet-prod
88
- mainnet-staging
99
- mainnet-prod
10+
- feat/publish-packages
1011
pull_request:
1112

1213
concurrency:
@@ -146,6 +147,141 @@ jobs:
146147
- name: Install jq
147148
run: sudo apt-get install -y jq
148149

150+
- name: Extract version, determine tag, and publish contracts package
151+
if: ${{ github.ref == 'refs/heads/feat/publish-packages' }}
152+
env:
153+
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
154+
run: |
155+
workspaces=(
156+
"packages/contracts:@chimera-monorepo/contracts"
157+
)
158+
159+
for entry in "${workspaces[@]}"; do
160+
IFS=":"; read -ra split_entry <<< "$entry"
161+
directory="${split_entry[0]}"
162+
workspace="${split_entry[1]}"
163+
subpackage_version=$(cat $directory/package.json | jq -r '.version')
164+
165+
tag=""
166+
if [[ "$subpackage_version" == *"-alpha"* ]]; then
167+
tag="alpha"
168+
elif [[ "$subpackage_version" == *"-beta"* ]]; then
169+
tag="beta"
170+
fi
171+
172+
echo "Checking $workspace for existing version..."
173+
npm_package_info=$(npm view $workspace versions --json)
174+
175+
if [[ -z "$tag" ]]; then
176+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"-\") | not)" | tail -1)
177+
else
178+
base_version=$(echo "$subpackage_version" | sed 's/-.*//')
179+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"^${base_version}-${tag}\"))" | tail -1)
180+
fi
181+
182+
echo "Compare version in NPM ($last_version) against local version ($subpackage_version)"
183+
if [[ "$last_version" != "$subpackage_version" ]]; then
184+
echo "Publishing $workspace with version $subpackage_version"
185+
if [[ ! -z "$tag" ]]; then
186+
yarn workspace $workspace npm publish --access public --tag $tag
187+
else
188+
yarn workspace $workspace npm publish --access public
189+
fi
190+
else
191+
echo "Skipping $workspace as version $subpackage_version already exists"
192+
fi
193+
done
194+
195+
- name: Extract version, determine tag, and publish utils package
196+
if: ${{ github.ref == 'refs/heads/feat/publish-packages' }}
197+
env:
198+
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
199+
run: |
200+
workspaces=(
201+
"packages/utils:@chimera-monorepo/utils"
202+
)
203+
204+
for entry in "${workspaces[@]}"; do
205+
IFS=":"; read -ra split_entry <<< "$entry"
206+
directory="${split_entry[0]}"
207+
workspace="${split_entry[1]}"
208+
subpackage_version=$(cat $directory/package.json | jq -r '.version')
209+
210+
tag=""
211+
if [[ "$subpackage_version" == *"-alpha"* ]]; then
212+
tag="alpha"
213+
elif [[ "$subpackage_version" == *"-beta"* ]]; then
214+
tag="beta"
215+
fi
216+
217+
echo "Checking $workspace for existing version..."
218+
npm_package_info=$(npm view $workspace versions --json)
219+
220+
if [[ -z "$tag" ]]; then
221+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"-\") | not)" | tail -1)
222+
else
223+
base_version=$(echo "$subpackage_version" | sed 's/-.*//')
224+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"^${base_version}-${tag}\"))" | tail -1)
225+
fi
226+
227+
echo "Compare version in NPM ($last_version) against local version ($subpackage_version)"
228+
if [[ "$last_version" != "$subpackage_version" ]]; then
229+
echo "Publishing $workspace with version $subpackage_version"
230+
if [[ ! -z "$tag" ]]; then
231+
yarn workspace $workspace npm publish --access public --tag $tag
232+
else
233+
yarn workspace $workspace npm publish --access public
234+
fi
235+
else
236+
echo "Skipping $workspace as version $subpackage_version already exists"
237+
fi
238+
done
239+
240+
- name: Extract version, determine tag, and publish chainservice package
241+
if: ${{ github.ref == 'refs/heads/feat/publish-packages' }}
242+
env:
243+
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
244+
run: |
245+
workspaces=(
246+
"packages/adapters/chainservice:@chimera-monorepo/chainservice"
247+
)
248+
249+
for entry in "${workspaces[@]}"; do
250+
IFS=":"; read -ra split_entry <<< "$entry"
251+
directory="${split_entry[0]}"
252+
workspace="${split_entry[1]}"
253+
subpackage_version=$(cat $directory/package.json | jq -r '.version')
254+
255+
tag=""
256+
if [[ "$subpackage_version" == *"-alpha"* ]]; then
257+
tag="alpha"
258+
elif [[ "$subpackage_version" == *"-beta"* ]]; then
259+
tag="beta"
260+
fi
261+
262+
echo "Checking $workspace for existing version..."
263+
npm_package_info=$(npm view $workspace versions --json)
264+
265+
if [[ -z "$tag" ]]; then
266+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"-\") | not)" | tail -1)
267+
else
268+
base_version=$(echo "$subpackage_version" | sed 's/-.*//')
269+
last_version=$(echo "$npm_package_info" | jq -r ".[] | select(test(\"^${base_version}-${tag}\"))" | tail -1)
270+
fi
271+
272+
echo "Compare version in NPM ($last_version) against local version ($subpackage_version)"
273+
if [[ "$last_version" != "$subpackage_version" ]]; then
274+
echo "Publishing $workspace with version $subpackage_version"
275+
if [[ ! -z "$tag" ]]; then
276+
yarn workspace $workspace npm publish --access public --tag $tag
277+
else
278+
yarn workspace $workspace npm publish --access public
279+
fi
280+
else
281+
echo "Skipping $workspace as version $subpackage_version already exists"
282+
fi
283+
done
284+
149285
build-and-push-relayer-image:
150286
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/testnet-staging' || github.ref == 'refs/heads/mainnet-staging' || github.ref == 'refs/heads/testnet-prod' || github.ref == 'refs/heads/mainnet-prod'
151287
env:

0 commit comments

Comments
 (0)