Skip to content

Commit 55a644c

Browse files
authored
Merge pull request #142 from zotero/no-unwrap
Remove .unwrap() from JS API; `Driver.new` => `new Driver`
2 parents f181977 + f6cb11c commit 55a644c

36 files changed

+1767
-7473
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# For an example of a local composite actions:
2+
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file
3+
#
4+
# The only reference I can find in the docs to actually using one in the same repo:
5+
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsuses
6+
name: 'Set up Rust stable, wasm-bindgen and binaryen/wasm-opt'
7+
runs:
8+
using: "composite"
9+
steps:
10+
11+
- name: Install Rust 1.52.1
12+
uses: actions-rs/toolchain@v1
13+
with:
14+
toolchain: 1.52.1
15+
override: true
16+
target: wasm32-unknown-unknown
17+
- uses: Swatinem/rust-cache@v1
18+
with:
19+
sharedKey: cargo-wasm-release
20+
21+
# simple version
22+
# - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
23+
24+
# complicated version
25+
- working-directory: /tmp
26+
shell: bash
27+
run: |
28+
mkdir -p $HOME/.local/bin
29+
echo "$HOME/.local/bin" >> $GITHUB_PATH
30+
31+
# we want a pre-built copy of wasm-bindgen to match the version we've pinned in Cargo.toml
32+
#
33+
# to cross compile wasm-bindgen for linux on a mac:
34+
# rustup target add x86_64-unknown-linux-gnu
35+
# open https://github.com/chinedufn/cross-compile-rust-from-mac-to-linux
36+
# ./download-libssl-dev.sh with updated .deb URL from debian stable
37+
# mv target/usr/include/x86_64-linux-gnu/openssl/* target/usr/include/openssl
38+
# ./build.sh
39+
# set VERSION no-unwrap
40+
# tar -zcv -f "$DIR/wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz" -C target/x86_64-unknown-linux-gnu/release wasm-bindgen
41+
# gh release -R cormacrelf/wasm-bindgen upload $VERSION wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz
42+
43+
VERSION=no-unwrap
44+
curl -sL -o wasm-bindgen.tar.gz \
45+
"https://github.com/cormacrelf/wasm-bindgen/releases/download/$VERSION/wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz"
46+
tar -xzvf wasm-bindgen.tar.gz
47+
cp wasm-bindgen $HOME/.local/bin/
48+
49+
VERSION=version_103
50+
curl -sL -o binaryen.tar.gz \
51+
"https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz"
52+
tar -xzvf binaryen.tar.gz
53+
# binaryen's releases no longer have $VERSION in folder name
54+
# as they did for version_101 and earlier
55+
cp binaryen-/bin/* $HOME/.local/bin/

.github/workflows/build-wasm.yml

+21-64
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,34 @@ jobs:
1919
if: ${{ github.event_name == 'push' }}
2020
steps:
2121
- uses: actions/checkout@v2
22+
- uses: ./.github/actions/setup-rust-wasm
23+
- name: Yarn install
24+
working-directory: crates/wasm/js-demo
25+
run: yarn install
2226

23-
- name: Install Rust 1.52.1
24-
uses: actions-rs/toolchain@v1
25-
with:
26-
toolchain: 1.52.1
27-
override: true
28-
- uses: Swatinem/rust-cache@v1
29-
with:
30-
sharedKey: ${{ github.ref == 'refs/heads/master' && 'cargo-wasm-release' || 'cargo-wasm-debug' }}
31-
32-
- name: Install wasm-pack and binaryen
33-
# run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
34-
#
35-
# wasm-opt seems to have a segfault, wasm-pack doesn't let you use a wasm-opt off your $PATH,
36-
# it has to use its own pinned version and is not being updated much at the moment.
37-
# So custom wasm-pack, and binaryen from github releases
27+
- name: >
28+
Build WASM pkg
29+
(${{ github.ref == 'refs/heads/master' && '--release' || '--dev' }})
30+
working-directory: crates/wasm
3831
run: |
39-
cd /tmp
40-
mkdir -p $HOME/.local/bin
41-
echo "$HOME/.local/bin" >> $GITHUB_PATH
42-
43-
VERSION=manual-1
44-
curl -sL -o wasm-pack.tar.gz https://github.com/cormacrelf/wasm-pack/releases/download/$VERSION/wasm-pack-$VERSION-x86_64-unknown-linux-gnu.tar.gz
45-
tar -xzvf wasm-pack.tar.gz
46-
cp wasm-pack $HOME/.local/bin/
32+
./scripts/npm-pkg-config.sh \
33+
${{ github.ref != 'refs/heads/master' && '--dev' || '' }} \
34+
--targets browser \
35+
--set-name @citeproc-rs/wasm \
36+
--dest ./pkg \
37+
--features console,dot
4738
48-
VERSION=version_101
49-
curl -sL -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz
50-
tar -xzvf binaryen.tar.gz
51-
cp binaryen-$VERSION/bin/* $HOME/.local/bin/
39+
- run: yarn build
40+
working-directory: crates/wasm/js-demo
5241

53-
- name: Yarn install
54-
run: cd crates/wasm/js-demo && yarn
55-
- name: Yarn build (dev)
56-
if: ${{ github.ref != 'refs/heads/master' }}
57-
run: cd crates/wasm/js-demo && yarn build -d
58-
- name: Yarn build (prod)
59-
if: ${{ github.ref == 'refs/heads/master' }}
60-
run: cd crates/wasm/js-demo && yarn build -p
6142
- name: Deploy
6243
if: ${{ github.ref == 'refs/heads/master' }}
6344
uses: peaceiris/actions-gh-pages@v2
6445
env:
6546
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
6647
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
6748
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68-
PUBLISH_DIR: ./crates/wasm/js-demo/dist
49+
PUBLISH_DIR: ./crates/wasm/js-demo/build
6950
EXTERNAL_REPOSITORY: cormacrelf/citeproc-wasm-demo
7051
PUBLISH_BRANCH: gh-pages
7152

@@ -92,8 +73,8 @@ jobs:
9273
9374
if $IS_TAGGED_RELEASE; then
9475
TAG=${GITHUB_REF#refs/tags/wasm-}
95-
IFS='-' read -ra PLAIN_VERSION POST_HYPHEN <<< "$TAG"
96-
if ! [ -z "$POST_HYPHEN" ]; then
76+
IFS='-' read -ra _ POST_HYPHEN <<< "$TAG"
77+
if [ -n "$POST_HYPHEN" ]; then
9778
# i.e. there was a -alpha.1 appended, use the `next` dist tag
9879
set-output npm_dist_tag next
9980
else
@@ -111,31 +92,7 @@ jobs:
11192
dist tag ${{ steps.version.outputs.npm_dist_tag }}
11293
run: echo
11394
114-
- name: Install Rust 1.52.1
115-
uses: actions-rs/toolchain@v1
116-
with:
117-
toolchain: 1.52.1
118-
override: true
119-
- uses: Swatinem/rust-cache@v1
120-
with:
121-
sharedKey: cargo-wasm-release
122-
123-
- name: Install wasm-pack and binaryen
124-
# run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
125-
run: |
126-
cd /tmp
127-
mkdir -p $HOME/.local/bin
128-
echo "$HOME/.local/bin" >> $GITHUB_PATH
129-
130-
VERSION=manual-1
131-
curl -sL -o wasm-pack.tar.gz https://github.com/cormacrelf/wasm-pack/releases/download/$VERSION/wasm-pack-$VERSION-x86_64-unknown-linux-gnu.tar.gz
132-
tar -xzvf wasm-pack.tar.gz
133-
cp wasm-pack $HOME/.local/bin/
134-
135-
VERSION=version_101
136-
curl -sL -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz
137-
tar -xzvf binaryen.tar.gz
138-
cp binaryen-$VERSION/bin/* $HOME/.local/bin/
95+
- uses: ./.github/actions/setup-rust-wasm
13996

14097
- name: Build for all targets
14198
working-directory: crates/wasm
@@ -151,7 +108,7 @@ jobs:
151108
- name: Publish @citeproc-rs/wasm to NPM
152109
working-directory: crates/wasm
153110
run: >
154-
npm publish dist --access public
111+
npm publish ./dist --access public
155112
--tag ${{ steps.version.outputs.npm_dist_tag }}
156113
${{ steps.version.outputs.npm_dry_run == 'true' && '--dry-run' || '' }}
157114

.github/workflows/ci.yml

+14-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ env:
1010
CARGO_TERM_COLOR: always
1111
RUST_BACKTRACE: '1'
1212

13+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
14+
# at a time
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1319
jobs:
1420
cargo_test:
1521
name: Cargo Test
@@ -40,10 +46,11 @@ jobs:
4046
- name: Extract branch name
4147
id: branch
4248
shell: bash
49+
env:
50+
GITHUB_HEAD: ${{ github.head_ref }}
51+
GITHUB_BASE: ${{ github.base_ref }}
4352
run: |
4453
IS_CI_TEST=${{ github.event_name == 'push' && github.ref != 'refs/heads/master' && 'true' || 'false '}}
45-
GITHUB_HEAD=${{ github.head_ref }}
46-
GITHUB_BASE=${{ github.base_ref }}
4754
4855
if test -z "$GITHUB_HEAD"; then
4956
GITHUB_HEAD="$GITHUB_REF"
@@ -54,15 +61,15 @@ jobs:
5461
5562
# transforms refs/pulls/123/merge into pulls-123-merge
5663
GITHUB_HEAD=${GITHUB_HEAD#refs/heads/}
57-
GITHUB_HEAD=$(echo ${GITHUB_HEAD#refs/} | tr '/' '-')
64+
GITHUB_HEAD=$(echo "${GITHUB_HEAD#refs/}" | tr '/' '-')
5865
echo "GITHUB_HEAD = ${GITHUB_HEAD}"
5966
echo "::set-output name=head::${GITHUB_HEAD}"
6067
6168
if $IS_CI_TEST; then
6269
echo "::set-output name=base::master"
6370
else
6471
GITHUB_BASE=${GITHUB_BASE#refs/heads/}
65-
GITHUB_BASE=$(echo ${GITHUB_BASE#refs/} | tr '/' '-')
72+
GITHUB_BASE=$(echo "${GITHUB_BASE#refs/}" | tr '/' '-')
6673
echo "GITHUB_BASE = ${GITHUB_BASE}"
6774
echo "::set-output name=base::${GITHUB_BASE}"
6875
fi
@@ -103,8 +110,8 @@ jobs:
103110
GITHUB_HEAD: ${{ steps.branch.outputs.head }}
104111
shell: bash
105112
run: |
106-
cp .snapshots/current .snapshots/branches/$GITHUB_HEAD
107-
cargo test-suite diff $GITHUB_BASE..$GITHUB_HEAD | tee test-results/diff
113+
cp .snapshots/current ".snapshots/branches/$GITHUB_HEAD"
114+
cargo test-suite diff "$GITHUB_BASE..$GITHUB_HEAD" | tee test-results/diff
108115
# need the first command in the pipe, $? would give us tee's status
109116
echo "${PIPESTATUS[0]}" > test-results/diff-status
110117
@@ -147,18 +154,7 @@ jobs:
147154
runs-on: ubuntu-20.04
148155
steps:
149156
- uses: actions/checkout@v2
150-
- name: Install Rust 1.52.1
151-
uses: actions-rs/toolchain@v1
152-
with:
153-
toolchain: 1.52.1
154-
override: true
155-
- uses: Swatinem/rust-cache@v1
156-
with:
157-
sharedKey: cargo-wasm-debug
158-
159-
- name: Install wasm-pack
160-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
161-
157+
- uses: ./.github/actions/setup-rust-wasm
162158
- name: Get yarn cache directory path
163159
id: yarn-cache-dir-path
164160
run: echo "::set-output name=dir::$(yarn cache dir)"

.github/workflows/post-ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ jobs:
4646
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
4747
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
4848
AWS_DEFAULT_REGION: ap-southeast-2
49-
GITHUB_HEAD: ${{ steps.branch.outputs.head }}
50-
GITHUB_BASE: ${{ steps.branch.outputs.base }}
5149
PR_NUM: ${{ steps.wf.outputs.pr_number }}
5250
SNAPSHOT_NAME: ${{ steps.wf.outputs.snapshot_name }}
5351
working-directory: ./test-results

Cargo.lock

+21-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ debug = false
3333

3434
# [profile.dev]
3535
# rpath = true
36+
37+
[patch.'crates-io'.wasm-bindgen]
38+
version = "0.2.78"
39+
git = "https://github.com/cormacrelf/wasm-bindgen"
40+
tag = "no-unwrap"

0 commit comments

Comments
 (0)