From fd51402e473693d9d3f693a70d399f5977eff2aa Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 16 Nov 2021 23:08:15 +0100 Subject: [PATCH] refactor: custom-runtime.sh Making this into a feature useful for testing specific go+js setups. --- .github/workflows/test.yml | 24 ++++++++++++------ .gitignore | 1 - README.md | 21 ++++++++++++++++ package.json | 1 - scripts/custom-runtime.sh | 50 ++++++++++++++++++++++++++++++++++++++ setup-http-rpc-runtime.sh | 38 ----------------------------- 6 files changed, 87 insertions(+), 48 deletions(-) create mode 100755 scripts/custom-runtime.sh delete mode 100755 setup-http-rpc-runtime.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09e18c96..ef1ecc2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,12 +4,13 @@ on: branches: - master -# TODO: remove below + use of setup-go env: - IPFS_GO_EXEC: '/tmp/go-ipfs/cmd/ipfs/ipfs' - IPFS_JS_EXEC: '/tmp/js-ipfs/packages/ipfs/src/cli.js' - IPFS_JS_MODULE: '/tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js' - IPFS_JS_HTTP_MODULE: '/tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js' + # To run CI against unrelased go-ipfs or js-ipfs-* code (eg. wip PR), + # uncomment below and define git revisions in ./scripts/custom-runtime.sh + IPFS_GO_EXEC: /tmp/go-ipfs/cmd/ipfs/ipfs + IPFS_JS_EXEC: /tmp/js-ipfs/packages/ipfs/src/cli.js + IPFS_JS_MODULE: /tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js + IPFS_JS_HTTP_MODULE: /tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js jobs: build: @@ -34,6 +35,7 @@ jobs: key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} - name: Install Dependencies run: | + ./scripts/custom-runtime.sh npm install npm run build @@ -95,7 +97,9 @@ jobs: run: | npm install npm run build - - run: npm run test -- -t node + - run: | + ./scripts/custom-runtime.sh + npm run test -- -t node test-browser: needs: build @@ -132,7 +136,9 @@ jobs: run: | npm install npm run build - - run: npm run test -- -t ${{ matrix.type }} -- --browser ${{ matrix.browser }} + - run: | + ./scripts/custom-runtime.sh + npm run test -- -t ${{ matrix.type }} -- --browser ${{ matrix.browser }} test-electron: needs: check @@ -168,4 +174,6 @@ jobs: npm run build - uses: GabrielBB/xvfb-action@v1 with: - run: npm run test -- -t ${{ matrix.type }} --bail -f dist/cjs/node-test/*js + run: | + ./scripts/custom-runtime.sh + npm run test -- -t ${{ matrix.type }} --bail -f dist/cjs/node-test/*js diff --git a/.gitignore b/.gitignore index 36922669..3f0082bd 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,3 @@ test/test-data/go-ipfs-repo/LOCK test/test-data/go-ipfs-repo/LOG test/test-data/go-ipfs-repo/LOG.old types -tmp diff --git a/README.md b/README.md index 557ec060..88fb333b 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,27 @@ $ npm install -g ipfs-interop $ IPFS_GO_EXEC=/path IPFS_JS_EXEC=/path IPFS_JS_MODULE=/path IPFS_JS_HTTP_MODULE=/path ipfs-interop ``` +### As a custom runtime + +If you want to run interop on CI against specific repo and git revision of +go-ipfs or js-ipfs* then set everything up in `./scripts/custom-runtime.sh` +and enable it by uncommenting `env:` `IPFS_(..)` definitions in `.github/workflows/test.yml` + +If you want to test against unrelased things locally, make sure the same env +variables are set on your machine. + +For example, to run pubsub tests against go-ipfs and js-ipfs revision defined +in `./scripts/custom-runtime.sh`, one can: + +``` +export IPFS_GO_EXEC=/tmp/go-ipfs/cmd/ipfs/ipfs +export IPFS_JS_EXEC=/tmp/js-ipfs/packages/ipfs/src/cli.js +export IPFS_JS_MODULE=/tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js +export IPFS_JS_HTTP_MODULE=/tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js +./scripts/custom-runtime.sh +node bin/ipfs-interop.js -- -t node --grep "pubsub" +``` + ## Releasing a new version This repo does not use aegir for releases. diff --git a/package.json b/package.json index 0c9fd6bd..05c102bf 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "npm": ">6.0.0" }, "scripts": { - "postinstall": "bash ./setup-http-rpc-runtime.sh", "lint": "aegir lint", "build": "aegir build", "pretest": "aegir build --esm-tests", diff --git a/scripts/custom-runtime.sh b/scripts/custom-runtime.sh new file mode 100755 index 00000000..e6cf2744 --- /dev/null +++ b/scripts/custom-runtime.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# This script sets up the Rube Goldberg machine for testing against custom +# revision of go-ipfs and js-ipfs (the latter being tricky due to lerna monorepo) +# +# It assumes IPFS_GO_EXEC or IPFS_JS_EXEC to be in env. +# One can trigger this locally by exporting the same path as we do on CI. +# For example, to run pubsub tests against go-ipfs and js-ipfs revision defined +# in ./scripts/custom-runtime.sh one can: +# +# export IPFS_GO_EXEC=/tmp/go-ipfs/cmd/ipfs/ipfs +# export IPFS_JS_EXEC=/tmp/js-ipfs/packages/ipfs/src/cli.js +# export IPFS_JS_MODULE=/tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js +# export IPFS_JS_HTTP_MODULE=/tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js +# ./scripts/custom-runtime.sh +# node bin/ipfs-interop.js -- -t node --grep "pubsub" + +set -eo pipefail + +WORKDIR=$(pwd) + +if [ "$IPFS_GO_EXEC" == /tmp/go-ipfs/cmd/ipfs/ipfs ]; then +if [ ! -d /tmp/go-ipfs ]; then + cd /tmp + git clone https://github.com/coryschwartz/go-ipfs.git + cd go-ipfs + # implementation from https://github.com/ipfs/go-ipfs/pull/8183 + git checkout 153697d524f449ee9bec97245b0fcd7ebc2e8170 + make build +fi +fi + +if [ "$IPFS_JS_EXEC" == /tmp/js-ipfs/packages/ipfs/src/cli.js ]; then +if [ ! -d /tmp/js-ipfs ]; then + cd /tmp + git clone https://github.com/ipfs/js-ipfs.git + cd js-ipfs + # implementation from https://github.com/ipfs/js-ipfs/pull/3922 + git checkout 1dcac76f56972fc3519526e93567e39d685033dd + npm install + npm run build + npm run link +fi +fi + +cd $WORKDIR + + +# print overrides +env | grep IPFS_ diff --git a/setup-http-rpc-runtime.sh b/setup-http-rpc-runtime.sh deleted file mode 100755 index 73d9a90b..00000000 --- a/setup-http-rpc-runtime.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -xeo pipefail - -# this script sets up the Rube Goldberg machine for testing HTTP RPC wire format change end-to-end -# context: -# - https://github.com/ipfs/go-ipfs/pull/8183 -# - https://github.com/ipfs/js-ipfs/pull/3922 - -WORKDIR=$(pwd) -rm -rf /tmp/js-ipfs /tmp/go-ipfs - - -# use updated GO implementation from https://github.com/ipfs/go-ipfs/pull/8183 -cd /tmp - git clone -b feat/pubsub-require-multibase https://github.com/coryschwartz/go-ipfs.git - cd go-ipfs - make build - make install - -# TODO: go-ipfs binary path to be used as IPFS_GO_EXEC -realpath /tmp/go-ipfs/cmd/ipfs/ipfs - - -# use updated JS implementation from https://github.com/ipfs/js-ipfs/pull/3922 -cd /tmp - git clone -b feat/pubsub-require-multibase https://github.com/ipfs/js-ipfs.git - cd js-ipfs - npm install - npm run build - npm run link - -cd $WORKDIR - -export IPFS_GO_EXEC=/tmp/go-ipfs/cmd/ipfs/ipfs -export IPFS_JS_EXEC=/tmp/js-ipfs/packages/ipfs/src/cli.js -export IPFS_JS_MODULE=/tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js -export IPFS_JS_HTTP_MODULE=/tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js