Skip to content

Commit 6af22be

Browse files
[issue 46] adds ci and release pipelines for JS (#55)
ci and release pipelines for JS
1 parent 5953ff6 commit 6af22be

31 files changed

+440
-187
lines changed

.github/workflows/release.yml

Lines changed: 199 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313

1414
env:
1515
PKG_NAME: didcomm
16+
PKG_NAME_NODEJS: didcomm-node
1617

1718

1819
jobs:
@@ -25,8 +26,12 @@ jobs:
2526
current_version: ${{ steps.current_version.outputs.current_version }}
2627
release_info: ${{ steps.release_info.outputs.release_info }}
2728
asset_crate_url: ${{ steps.release_info.outputs.asset_crate_url }}
29+
asset_npm_pkg_bundler_url: ${{ steps.release_info.outputs.asset_npm_pkg_bundler_url }}
30+
asset_npm_pkg_nodejs_url: ${{ steps.release_info.outputs.asset_npm_pkg_nodejs_url }}
2831
upload_url: ${{ steps.release_info.outputs.upload_url }}
2932
already_in_crates_io: ${{ steps.check_in_crates_io.outputs.already_in_crates_io != '' }}
33+
already_in_npm_bundler: ${{ steps.check_in_npm.outputs.already_in_npm_bundler != '' }}
34+
already_in_npm_nodejs: ${{ steps.check_in_npm.outputs.already_in_npm_nodejs != '' }}
3035

3136
steps:
3237
- uses: actions/checkout@v2
@@ -53,6 +58,16 @@ jobs:
5358
echo "::set-output name=asset_crate_url::$asset_crate_url"
5459
echo "$asset_crate_url"
5560
61+
asset_npm_pkg_bundler_url="$(echo "$release_info" \
62+
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}-${{ steps.current_version.outputs.current_version }}\\.tgz$")) | .browser_download_url')"
63+
echo "::set-output name=asset_npm_pkg_bundler_url::$asset_npm_pkg_bundler_url"
64+
echo "$asset_npm_pkg_bundler_url"
65+
66+
asset_npm_pkg_nodejs_url="$(echo "$release_info" \
67+
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME_NODEJS }}-${{ steps.current_version.outputs.current_version }}\\.tgz$")) | .browser_download_url')"
68+
echo "::set-output name=asset_npm_pkg_nodejs_url::$asset_npm_pkg_nodejs_url"
69+
echo "$asset_npm_pkg_nodejs_url"
70+
5671
upload_url="$(echo "$release_info" | jq -r '.upload_url')"
5772
echo "::set-output name=upload_url::$upload_url"
5873
echo "$upload_url"
@@ -67,6 +82,21 @@ jobs:
6782
echo "::set-output name=already_in_crates_io::$out"
6883
shell: bash {0} # to opt-out of default fail-fast behavior
6984

85+
- name: check if already deployed to npm
86+
id: check_in_npm
87+
run: |
88+
out="$(npm view ${{ env.PKG_NAME }}@${{ steps.current_version.outputs.current_version }} --json 2>/dev/null \
89+
| jq -r '.versions | select (.!=null)')"
90+
echo "in npm check for ${{ env.PKG_NAME }} : $out"
91+
echo "::set-output name=already_in_npm_bundler::$out"
92+
93+
out="$(npm view ${{ env.PKG_NAME_NODEJS }}@${{ steps.current_version.outputs.current_version }} --json 2>/dev/null \
94+
| jq -r '.versions | select (.!=null)')"
95+
echo "in npm check for ${{ env.PKG_NAME_NODEJS }}: $out"
96+
echo "::set-output name=already_in_npm_nodejs::$out"
97+
shell: bash {0} # to opt-out of default fail-fast behavior
98+
99+
70100
release:
71101
name: Release
72102
if: github.ref == 'refs/heads/stable'
@@ -81,20 +111,8 @@ jobs:
81111
rustup toolchain install stable
82112
shell: bash
83113

84-
- name: package and verify the crate
85-
id: build_assets
86-
if: ${{ !needs.checks.outputs.asset_crate_url }}
87-
run: |
88-
cargo package
89-
90-
# TODO
91-
# - verify that it's not more than crates.io limit (10 MB)
92-
# - explore wthere we need to upload another artifact (without extension)
93-
ls -la target/package
94-
cargo package --list
95-
96-
asset_crate_name="$(find target/package -name '*.crate' -printf '%f')"
97-
echo "::set-output name=asset_crate_name::$asset_crate_name"
114+
- name: Install wasm-pack
115+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
98116
shell: bash
99117

100118
- name: Create GitHub Release
@@ -109,37 +127,142 @@ jobs:
109127

110128
- name: Set upload url
111129
id: upload_url
112-
if: ${{ !needs.checks.outputs.asset_crate_url }}
130+
if: ${{ !(needs.checks.outputs.asset_crate_url && needs.checks.outputs.asset_npm_pkg_bundler_url && needs.checks.outputs.asset_npm_pkg_nodejs_url) }}
113131
run: |
114132
if [[ -n "${{ needs.checks.outputs.upload_url }}" ]]; then
115133
echo "::set-output name=value::${{ needs.checks.outputs.upload_url }}"
116134
else
117135
echo "::set-output name=value::${{ steps.create_release.outputs.upload_url }}"
118136
fi
119137
120-
- name: Upload to GitHub
138+
- name: package and verify (crate)
139+
id: build_assets_crate
140+
if: ${{ !needs.checks.outputs.asset_crate_url }}
141+
run: |
142+
cargo package
143+
144+
# TODO
145+
# - verify that it's not more than crates.io limit (10 MB)
146+
# - explore whether we need to upload another artifact (without extension)
147+
ls -la target/package
148+
cargo package --list
149+
150+
asset_name="$(find target/package -name '*.crate' -printf '%f')"
151+
echo "::set-output name=asset_name::$asset_name"
152+
shell: bash
153+
154+
- name: upload to GitHub (crate)
121155
if: ${{ !needs.checks.outputs.asset_crate_url }}
122156
uses: actions/upload-release-asset@v1
123157
env:
124158
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125159
with:
126160
upload_url: ${{ steps.upload_url.outputs.value }}
127-
asset_path: target/package/${{ steps.build_assets.outputs.asset_crate_name }}
128-
asset_name: ${{ steps.build_assets.outputs.asset_crate_name }}
161+
asset_path: target/package/${{ steps.build_assets_crate.outputs.asset_name }}
162+
asset_name: ${{ steps.build_assets_crate.outputs.asset_name }}
129163
asset_content_type: application/octet-stream # TODO check for less generic type
130164

165+
- name: package and verify (npm bundler)
166+
id: build_assets_npm_bundler
167+
if: ${{ !needs.checks.outputs.asset_npm_pkg_bundler_url }}
168+
run: |
169+
cd wasm
170+
rm -rf pkg
171+
172+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME }}\1~}" ./Cargo.toml
173+
wasm-pack build --target bundler
174+
175+
# verify
176+
pushd pkg
177+
npm install .
178+
popd
179+
180+
wasm-pack pack
181+
asset_name="$(find pkg -name '*.tgz' -printf '%f')"
182+
echo "::set-output name=asset_name::$asset_name"
183+
shell: bash
184+
185+
- name: upload to GitHub (npm bundler)
186+
if: ${{ !needs.checks.outputs.asset_npm_pkg_bundler_url }}
187+
uses: actions/upload-release-asset@v1
188+
env:
189+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190+
with:
191+
upload_url: ${{ steps.upload_url.outputs.value }}
192+
asset_path: wasm/pkg/${{ steps.build_assets_npm_bundler.outputs.asset_name }}
193+
asset_name: ${{ steps.build_assets_npm_bundler.outputs.asset_name }}
194+
asset_content_type: application/x-gtar
195+
196+
- name: package and verify (npm nodejs)
197+
id: build_assets_npm_nodejs
198+
if: ${{ !needs.checks.outputs.asset_npm_pkg_nodejs_url }}
199+
run: |
200+
cd wasm
201+
rm -rf pkg
202+
203+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME_NODEJS }}\1~}" ./Cargo.toml
204+
wasm-pack build --target bundler
205+
206+
# verify
207+
pushd pkg
208+
npm install .
209+
popd
210+
211+
wasm-pack pack
212+
asset_name="$(find pkg -name '*.tgz' -printf '%f')"
213+
echo "::set-output name=asset_name::$asset_name"
214+
shell: bash
215+
216+
- name: upload to GitHub (npm nodejs)
217+
if: ${{ !needs.checks.outputs.asset_npm_pkg_nodejs_url }}
218+
uses: actions/upload-release-asset@v1
219+
env:
220+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
221+
with:
222+
upload_url: ${{ steps.upload_url.outputs.value }}
223+
asset_path: wasm/pkg/${{ steps.build_assets_npm_nodejs.outputs.asset_name }}
224+
asset_name: ${{ steps.build_assets_npm_nodejs.outputs.asset_name }}
225+
asset_content_type: application/x-gtar
226+
131227
# NOTE looks like there is no option to skip packaging here
132228
# and use already prepared artifacts
133-
- name: Publish to crates.io
229+
230+
- name: publish to crates.io
134231
if: needs.checks.outputs.already_in_crates_io == 'false'
135232
env:
136233
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
137234
run: cargo publish
138235
shell: bash
139236

237+
- name: publish to npm (bundler)
238+
if: needs.checks.outputs.already_in_npm_bundler == 'false'
239+
env:
240+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
241+
run: |
242+
cd wasm
243+
rm -rf pkg
244+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME }}\1~}" ./Cargo.toml
245+
wasm-pack build --target nodejs
246+
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >pkg/.npmrc
247+
wasm-pack publish
248+
shell: bash
249+
250+
- name: publish to npm (nodejs)
251+
if: needs.checks.outputs.already_in_npm_nodejs == 'false'
252+
env:
253+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
254+
run: |
255+
cd wasm
256+
rm -rf pkg
257+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME_NODEJS }}\1~}" ./Cargo.toml
258+
wasm-pack build --target nodejs
259+
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >pkg/.npmrc
260+
wasm-pack publish
261+
shell: bash
262+
140263

141-
deploy-dev-crates-io:
142-
name: Publish dev to crates.io
264+
deploy-dev:
265+
name: publish dev to crates.io
143266
if: github.ref != 'refs/heads/stable' && github.event_name == 'workflow_dispatch'
144267
runs-on: ubuntu-latest
145268
steps:
@@ -151,21 +274,74 @@ jobs:
151274
rustup toolchain install stable
152275
shell: bash
153276

277+
- name: Install wasm-pack
278+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
279+
shell: bash
280+
154281
- name: set dev version
155282
run: |
156283
sed -i -r "0,/version/{s~^version = (['\"])(.+)['\"]~version = \1\2-0.dev.${{ github.event.inputs.devN }}\1~}" ./Cargo.toml
157284
grep version ./Cargo.toml
285+
sed -i -r "0,/version/{s~^version = (['\"])(.+)['\"]~version = \1\2-0.dev.${{ github.event.inputs.devN }}\1~}" ./wasm/Cargo.toml
286+
grep version ./wasm/Cargo.toml
158287
shell: bash
159288

160-
- name: verify the package
289+
- name: verify the package (crate)
161290
run: |
162291
cargo package --allow-dirty
163292
ls -la target/package
164293
cargo package --allow-dirty --list
165294
shell: bash
166295

167-
- name: publish
296+
- name: publish to crates.io
168297
env:
169298
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
170299
run: cargo publish --allow-dirty
171300
shell: bash
301+
302+
- name: verify the package (npm bundler)
303+
run: |
304+
cd wasm
305+
rm -rf pkg
306+
307+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME }}\1~}" ./Cargo.toml
308+
wasm-pack build --target bundler
309+
310+
# verify
311+
pushd pkg
312+
npm install .
313+
popd
314+
shell: bash
315+
316+
- name: publish to npm (bundler)
317+
if: false
318+
env:
319+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
320+
run: |
321+
cd wasm
322+
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >pkg/.npmrc
323+
wasm-pack publish --tag dev
324+
shell: bash
325+
326+
- name: verify the package (npm nodejs)
327+
run: |
328+
cd wasm
329+
rm -rf pkg
330+
331+
sed -i -r "0,/name/{s~^name = (['\"]).+['\"]~name = \1${{ env.PKG_NAME_NODEJS }}\1~}" ./Cargo.toml
332+
wasm-pack build --target nodejs
333+
334+
# verify
335+
pushd pkg
336+
npm install .
337+
popd
338+
shell: bash
339+
340+
- name: publish to npm (nodejs)
341+
env:
342+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
343+
run: |
344+
cd wasm
345+
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >pkg/.npmrc
346+
wasm-pack publish --tag dev
347+
shell: bash

0 commit comments

Comments
 (0)