Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove .unwrap() from JS API; Driver.new => new Driver #142

Merged
merged 18 commits into from Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/actions/setup-rust-wasm/action.yml
@@ -0,0 +1,55 @@
# For an example of a local composite actions:
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file
#
# The only reference I can find in the docs to actually using one in the same repo:
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsuses
name: 'Set up Rust stable, wasm-bindgen and binaryen/wasm-opt'
runs:
using: "composite"
steps:

- name: Install Rust 1.52.1
uses: actions-rs/toolchain@v1
with:
toolchain: 1.52.1
override: true
target: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v1
with:
sharedKey: cargo-wasm-release

# simple version
# - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f

# complicated version
- working-directory: /tmp
shell: bash
run: |
mkdir -p $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH

# we want a pre-built copy of wasm-bindgen to match the version we've pinned in Cargo.toml
#
# to cross compile wasm-bindgen for linux on a mac:
# rustup target add x86_64-unknown-linux-gnu
# open https://github.com/chinedufn/cross-compile-rust-from-mac-to-linux
# ./download-libssl-dev.sh with updated .deb URL from debian stable
# mv target/usr/include/x86_64-linux-gnu/openssl/* target/usr/include/openssl
# ./build.sh
# set VERSION no-unwrap
# tar -zcv -f "$DIR/wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz" -C target/x86_64-unknown-linux-gnu/release wasm-bindgen
# gh release -R cormacrelf/wasm-bindgen upload $VERSION wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz

VERSION=no-unwrap
curl -sL -o wasm-bindgen.tar.gz \
"https://github.com/cormacrelf/wasm-bindgen/releases/download/$VERSION/wasm-bindgen-$VERSION-x86_64-unknown-linux-gnu.tar.gz"
tar -xzvf wasm-bindgen.tar.gz
cp wasm-bindgen $HOME/.local/bin/

VERSION=version_103
curl -sL -o binaryen.tar.gz \
"https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz"
tar -xzvf binaryen.tar.gz
# binaryen's releases no longer have $VERSION in folder name
# as they did for version_101 and earlier
cp binaryen-/bin/* $HOME/.local/bin/
85 changes: 21 additions & 64 deletions .github/workflows/build-wasm.yml
Expand Up @@ -19,53 +19,34 @@ jobs:
if: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/setup-rust-wasm
- name: Yarn install
working-directory: crates/wasm/js-demo
run: yarn install

- name: Install Rust 1.52.1
uses: actions-rs/toolchain@v1
with:
toolchain: 1.52.1
override: true
- uses: Swatinem/rust-cache@v1
with:
sharedKey: ${{ github.ref == 'refs/heads/master' && 'cargo-wasm-release' || 'cargo-wasm-debug' }}

- name: Install wasm-pack and binaryen
# run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
#
# wasm-opt seems to have a segfault, wasm-pack doesn't let you use a wasm-opt off your $PATH,
# it has to use its own pinned version and is not being updated much at the moment.
# So custom wasm-pack, and binaryen from github releases
- name: >
Build WASM pkg
(${{ github.ref == 'refs/heads/master' && '--release' || '--dev' }})
working-directory: crates/wasm
run: |
cd /tmp
mkdir -p $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH

VERSION=manual-1
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
tar -xzvf wasm-pack.tar.gz
cp wasm-pack $HOME/.local/bin/
./scripts/npm-pkg-config.sh \
${{ github.ref != 'refs/heads/master' && '--dev' || '' }} \
--targets browser \
--set-name @citeproc-rs/wasm \
--dest ./pkg \
--features console,dot

VERSION=version_101
curl -sL -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz
tar -xzvf binaryen.tar.gz
cp binaryen-$VERSION/bin/* $HOME/.local/bin/
- run: yarn build
working-directory: crates/wasm/js-demo

- name: Yarn install
run: cd crates/wasm/js-demo && yarn
- name: Yarn build (dev)
if: ${{ github.ref != 'refs/heads/master' }}
run: cd crates/wasm/js-demo && yarn build -d
- name: Yarn build (prod)
if: ${{ github.ref == 'refs/heads/master' }}
run: cd crates/wasm/js-demo && yarn build -p
- name: Deploy
if: ${{ github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v2
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_DIR: ./crates/wasm/js-demo/dist
PUBLISH_DIR: ./crates/wasm/js-demo/build
EXTERNAL_REPOSITORY: cormacrelf/citeproc-wasm-demo
PUBLISH_BRANCH: gh-pages

Expand All @@ -92,8 +73,8 @@ jobs:

if $IS_TAGGED_RELEASE; then
TAG=${GITHUB_REF#refs/tags/wasm-}
IFS='-' read -ra PLAIN_VERSION POST_HYPHEN <<< "$TAG"
if ! [ -z "$POST_HYPHEN" ]; then
IFS='-' read -ra _ POST_HYPHEN <<< "$TAG"
if [ -n "$POST_HYPHEN" ]; then
# i.e. there was a -alpha.1 appended, use the `next` dist tag
set-output npm_dist_tag next
else
Expand All @@ -111,31 +92,7 @@ jobs:
dist tag ${{ steps.version.outputs.npm_dist_tag }}
run: echo

- name: Install Rust 1.52.1
uses: actions-rs/toolchain@v1
with:
toolchain: 1.52.1
override: true
- uses: Swatinem/rust-cache@v1
with:
sharedKey: cargo-wasm-release

- name: Install wasm-pack and binaryen
# run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
run: |
cd /tmp
mkdir -p $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH

VERSION=manual-1
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
tar -xzvf wasm-pack.tar.gz
cp wasm-pack $HOME/.local/bin/

VERSION=version_101
curl -sL -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/$VERSION/binaryen-$VERSION-x86_64-linux.tar.gz
tar -xzvf binaryen.tar.gz
cp binaryen-$VERSION/bin/* $HOME/.local/bin/
- uses: ./.github/actions/setup-rust-wasm

- name: Build for all targets
working-directory: crates/wasm
Expand All @@ -151,7 +108,7 @@ jobs:
- name: Publish @citeproc-rs/wasm to NPM
working-directory: crates/wasm
run: >
npm publish dist --access public
npm publish ./dist --access public
--tag ${{ steps.version.outputs.npm_dist_tag }}
${{ steps.version.outputs.npm_dry_run == 'true' && '--dry-run' || '' }}

32 changes: 14 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -10,6 +10,12 @@ env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: '1'

# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
cargo_test:
name: Cargo Test
Expand Down Expand Up @@ -40,10 +46,11 @@ jobs:
- name: Extract branch name
id: branch
shell: bash
env:
GITHUB_HEAD: ${{ github.head_ref }}
GITHUB_BASE: ${{ github.base_ref }}
run: |
IS_CI_TEST=${{ github.event_name == 'push' && github.ref != 'refs/heads/master' && 'true' || 'false '}}
GITHUB_HEAD=${{ github.head_ref }}
GITHUB_BASE=${{ github.base_ref }}

if test -z "$GITHUB_HEAD"; then
GITHUB_HEAD="$GITHUB_REF"
Expand All @@ -54,15 +61,15 @@ jobs:

# transforms refs/pulls/123/merge into pulls-123-merge
GITHUB_HEAD=${GITHUB_HEAD#refs/heads/}
GITHUB_HEAD=$(echo ${GITHUB_HEAD#refs/} | tr '/' '-')
GITHUB_HEAD=$(echo "${GITHUB_HEAD#refs/}" | tr '/' '-')
echo "GITHUB_HEAD = ${GITHUB_HEAD}"
echo "::set-output name=head::${GITHUB_HEAD}"

if $IS_CI_TEST; then
echo "::set-output name=base::master"
else
GITHUB_BASE=${GITHUB_BASE#refs/heads/}
GITHUB_BASE=$(echo ${GITHUB_BASE#refs/} | tr '/' '-')
GITHUB_BASE=$(echo "${GITHUB_BASE#refs/}" | tr '/' '-')
echo "GITHUB_BASE = ${GITHUB_BASE}"
echo "::set-output name=base::${GITHUB_BASE}"
fi
Expand Down Expand Up @@ -103,8 +110,8 @@ jobs:
GITHUB_HEAD: ${{ steps.branch.outputs.head }}
shell: bash
run: |
cp .snapshots/current .snapshots/branches/$GITHUB_HEAD
cargo test-suite diff $GITHUB_BASE..$GITHUB_HEAD | tee test-results/diff
cp .snapshots/current ".snapshots/branches/$GITHUB_HEAD"
cargo test-suite diff "$GITHUB_BASE..$GITHUB_HEAD" | tee test-results/diff
# need the first command in the pipe, $? would give us tee's status
echo "${PIPESTATUS[0]}" > test-results/diff-status

Expand Down Expand Up @@ -147,18 +154,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Rust 1.52.1
uses: actions-rs/toolchain@v1
with:
toolchain: 1.52.1
override: true
- uses: Swatinem/rust-cache@v1
with:
sharedKey: cargo-wasm-debug

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f

- uses: ./.github/actions/setup-rust-wasm
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/post-ci.yml
Expand Up @@ -46,8 +46,6 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-southeast-2
GITHUB_HEAD: ${{ steps.branch.outputs.head }}
GITHUB_BASE: ${{ steps.branch.outputs.base }}
PR_NUM: ${{ steps.wf.outputs.pr_number }}
SNAPSHOT_NAME: ${{ steps.wf.outputs.snapshot_name }}
working-directory: ./test-results
Expand Down
47 changes: 21 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -33,3 +33,8 @@ debug = false

# [profile.dev]
# rpath = true

[patch.'crates-io'.wasm-bindgen]
version = "0.2.78"
git = "https://github.com/cormacrelf/wasm-bindgen"
tag = "no-unwrap"