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

Add CI #14

Merged
merged 10 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 263 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
name: CI

on: [push, pull_request]

env:
CI: true

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Add target wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown

- name: Install Node.js dependencies
run: npm install

- name: Add components clippy and rustfmt
run: rustup component add clippy rustfmt

- name: Run lint
run: |
make lint

test-browser:
name: Test in browser (electron)
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Add target wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown

- name: Install Node.js dependencies
run: npm install

- uses: actions/cache@v2
id: binaryen-cache
with:
path: binaryen-version_100
key: binaryen-version_100

- name: Install wasm-opt (binaryen)
if: steps.binaryen-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_100/binaryen-version_100-x86_64-linux.tar.gz
tar zxvf binaryen-version_100-x86_64-linux.tar.gz binaryen-version_100/bin/wasm-opt

- name: Build wasm
run: export PATH=$PATH:./binaryen-version_100/bin/ && make build-wasm

- name: Build JS
run: make build-js-browser

- name: Run tests
env:
DISPLAY: :99.0
run: |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
make test-browser-build-raw
make test-browser-raw-ci

- name: Upload wasm
uses: actions/upload-artifact@v2
with:
name: wasm
path: lib.node/secp256k1.wasm

test-node:
name: Test in Node.js
needs: [test-browser]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Node.js@12.0.0
uses: actions/setup-node@v2
with:
node-version: 12.0.0

- name: Install Node.js dependencies
run: npm install

- name: Add component rust-src
run: rustup component add rust-src

- name: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib.node

- name: Build JS
run: make build-js-node

- name: Add target x86_64-unknown-linux-musl and musl-tools
if: runner.os == 'Linux'
run: |
rustup target add x86_64-unknown-linux-musl
sudo apt-get install musl-tools

- name: Build addon (Linux)
if: runner.os == 'Linux'
run: make build-addon-x86_64-unknown-linux-musl+x64-linux.so

- name: Build addon (macOS)
if: runner.os == 'macOS'
run: make build-addon-x86_64-apple-darwin+x64-darwin.dylib

- name: Build addon (Windows)
if: runner.os == 'Windows'
run: make build-addon-x86_64-pc-windows-msvc+x64-win32.dll

- name: Run tests and coverage
run: |
make test-node-raw-ci
make test-node-coverage-raw

- name: Upload addon (Linux)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib.node/secp256k1-x64-linux.so

- name: Upload addon (macOS)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-darwin.dylib
path: lib.node/secp256k1-x64-darwin.dylib

- name: Upload addon (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-win32.dll
path: lib.node/secp256k1-x64-win32.dll

package:
name: Create package
needs: [test-node]
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Node.js dependencies
run: npm install

- name: Build JS
run: make build-js

- name: Download compiled Linux addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib.node

- name: Download compiled macOS addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-darwin.dylib
path: lib.node

- name: Download compiled Windows addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-win32.dll
path: lib.node

- name: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib.node

- name: Create package
run: |
cp lib.node/secp256k1.wasm lib.browser/secp256k1.wasm
mkdir package
# Copy LICENSE, README.md
cp LICENSE package/LICENSE
cp README.md package/README.md
# Copy js, addon, wasm
cp -r lib.browser package/lib.browser
cp -r lib.node package/lib.node
# Copy package.json, on-install.js
cp package.json package/package.json
node util/update-package-json.js package/package.json
cp util/on-install.js package/on-install.js
# Copy addon source
cp -r secp256k1 package/secp256k1
cp -r secp256k1-node package/secp256k1-node
cp -r secp256k1-wasm package/secp256k1-wasm
cp Cargo.lock package/Cargo.lock
cp Cargo.toml package/Cargo.toml
# Run `npm pack`
cd package
npm pack

- name: Upload package
uses: actions/upload-artifact@v2
with:
name: package
path: package/tiny-secp256k1-*

benchmark:
name: Benchmark
needs: [test-node]
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Node.js dependencies
run: npm install

- name: Build JS
run: make build-js

- name: Download compiled addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib.node

- name: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib.node

- name: Install benchmark dependencies
run: cd benches && npm install

- name: Run benchmark
run: |
cp lib.node/secp256k1.wasm lib.browser/secp256k1.wasm
cd benches && npm start
81 changes: 56 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@ build-js-browser:
build-js-node:
npx tsc --project tsconfig.node.json && rm lib.node/*.browser.js

.PHONY: build-node-%
build-node-%: export PAIR = $(subst +, ,$(subst build-node-,,$@))
build-node-%:
cargo build --package secp256k1-node --target $(firstword $(PAIR)) -Z build-std=panic_abort,std --release
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/release/libsecp256k1_node.so lib.node/secp256k1-$(lastword $(PAIR)).so
strip lib.node/secp256k1-$(lastword $(PAIR)).so

.PHONY: build-node-debug
build-node-debug:
.PHONY: build-addon-%
build-addon-%: export PAIR = $(subst +, ,$(subst build-addon-,,$@))
build-addon-%:
$(if $(findstring musl,$(firstword $(PAIR))),RUSTFLAGS="-C target-feature=-crt-static",) cargo build \
--package secp256k1-node \
--target $(firstword $(PAIR)) \
$(if $(findstring musl,$(firstword $(PAIR))),,-Z build-std=panic_abort,std) \
--release
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/release/`node util/addon-target-name.js` lib.node/secp256k1-$(lastword $(PAIR))
strip $(if $(findstring Darwin,$(shell uname -s)),-Sx,--strip-all) lib.node/secp256k1-$(lastword $(PAIR))

.PHONY: build-addon-debug
build-addon-debug:
cargo build --package secp256k1-node

.PHONY: build-node-debug-%
build-node-debug-%: export PAIR = $(subst +, ,$(subst build-node-debug-,,$@))
build-node-debug-%:
.PHONY: build-addon-debug-%
build-addon-debug-%: export PAIR = $(subst +, ,$(subst build-addon-debug-,,$@))
build-addon-debug-%:
cargo build --package secp256k1-node --target $(firstword $(PAIR))
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/debug/libsecp256k1_node.so lib.node/secp256k1-$(lastword $(PAIR)).so
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/debug/`node util/addon-target-name.js` lib.node/secp256k1-$(lastword $(PAIR))

.PHONY: build-wasm
build-wasm:
RUSTFLAGS="-C link-args=-zstack-size=655360" cargo build --package secp256k1-wasm --target wasm32-unknown-unknown --release
mkdir -p lib.browser && cp -f target/wasm32-unknown-unknown/release/secp256k1_wasm.wasm lib.browser/secp256k1.wasm
wasm-opt --strip-debug --strip-producers --output lib.browser/secp256k1.wasm lib.browser/secp256k1.wasm
node util/wasm-strip.js lib.browser/secp256k1.wasm
npx babel-node -b @babel/preset-env util/wasm-strip.js lib.browser/secp256k1.wasm
wasm-opt -O4 --output lib.browser/secp256k1.wasm lib.browser/secp256k1.wasm
mkdir -p lib.node && cp -f lib.browser/secp256k1.wasm lib.node/secp256k1.wasm

Expand All @@ -48,7 +52,9 @@ build-wasm-debug:
.PHONY: clean
clean:
rm -rf \
.nyc_output \
benches/node_modules \
coverage \
examples/random-in-node/node_modules \
examples/react-app/dist/*.js \
examples/react-app/dist/*.wasm \
Expand All @@ -60,35 +66,60 @@ clean:
tests/browser \
types

eslint_files = benches/*.{js,json} examples/**/*.{js,json} src_ts/*.ts tests/*.js util/*.js *.json *.cjs

.PHONY: format
format:
cargo-fmt
npx eslint benches/*.{js,json} examples/**/*.{js,json} src_ts/*.ts tests/*.js util/*.js *.json *.cjs --fix
npx eslint $(eslint_files) --fix
npx sort-package-json package.json benches/package.json

.PHONY: lint
lint:
cargo fmt -- --check
cargo clippy --package secp256k1-node
cargo clippy --package secp256k1-wasm --target wasm32-unknown-unknown
npx eslint benches/*.{js,json} examples/**/*.{js,json} src_ts/*.ts tests/*.js util/*.js *.json *.cjs
npx eslint $(eslint_files)

.PHONY: test
test: test-browser test-node

.PHONY: test-browser-build
test-browser-build: build-js-browser build-wasm-debug
.PHONY: test-browser-build-raw
test-browser-build-raw:
npx webpack build -c tests/browser.webpack.js

.PHONY: test-browser-build
test-browser-build: build-js-browser build-wasm-debug test-browser-build-raw

test_browser_raw = cat tests/browser/index.js | npx browser-run --static tests/browser | npx tap-summary

.PHONY: test-browser-raw
test-browser-raw:
$(test_browser_raw)

.PHONY: test-browser-raw-ci
test-browser-raw-ci:
$(test_browser_raw) --no-ansi --no-progress

.PHONY: test-browser
test-browser: test-browser-build
cat tests/browser/index.js | npx browser-run --static tests/browser | npx tap-difflet -p
test-browser: test-browser-build test-browser-raw

test_node_raw = npx nyc --silent npx babel-node -b @babel/preset-env tests/index.js | npx tap-summary

.PHONY: test-node-raw
test-node-raw:
$(test_node_raw)

.PHONY: test-node-raw-ci
test-node-raw-ci:
$(test_node_raw) --no-ansi --no-progress

.PHONY: test-node
test-node: build-js-node build-node-debug build-wasm-debug
npx babel-node -b @babel/preset-env tests/index.js | npx tap-difflet -p
test-node: build-js-node build-addon-debug build-wasm-debug test-node-raw

.PHONY: test-node-coverage
test-node-coverage: build-js-node build-node-debug build-wasm-debug
npx nyc npx babel-node -b @babel/preset-env tests/index.js >/dev/null
.PHONY: test-node-coverage-raw
test-node-coverage-raw:
npx nyc report --reporter=html --reporter=text

.PHONY: test-node-coverage
test-node-coverage: test-node test-node-coverage-raw
2 changes: 1 addition & 1 deletion benches/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as tiny_secp256k1 from "../lib/index.js";
import * as tiny_secp256k1 from "../";
import _fecdsa from "../tests/fixtures/ecdsa.json";
import _fpoints from "../tests/fixtures/points.json";
import _fprivates from "../tests/fixtures/privates.json";
Expand Down
Loading