Skip to content

Commit

Permalink
Monorepo (& Tx, VM): Examples scripts in CI (#1658)
Browse files Browse the repository at this point in the history
* chore(examples): examples added to ci

* chore(examples-ci): remove script from VM (for now) & rename examples workflow file

* chore(ci): new script formwatted with prettier & example workflow changes to run with non-test branches

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
  • Loading branch information
cbrzn and holgerd77 committed Jan 25, 2022
1 parent c4cc930 commit 4d087b4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Packages examples
on:
push:
branches: [master, develop]
pull_request:
types: [opened, reopened, synchronize]

jobs:
test-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions/setup-node@v2
with:
node-version: 16
cache: 'npm'

- run: npm i
- run: npm run examples
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"preinstall": "npm run checkNpmVersion",
"postinstall": "npm run build --workspaces",
"checkNpmVersion": "./scripts/check-npm-version.sh",
"examples": "npm run examples --workspaces --if-present",
"clean": "./config/cli/clean-root.sh",
"e2e:publish": "./scripts/e2e-publish.sh",
"e2e:resolutions": "node ./scripts/e2e-resolutions.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/tx/examples/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ console.log('--------------------')
// You can decode it with the rlp module.
// After that you should have something like:
const rawTx = [
'0x00',
'0x',
'0x09184e72a000',
'0x2710',
'0x0000000000000000000000000000000000000000',
'0x00',
'0x',
'0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
'0x1c',
'0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
'0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13',
]

const tx2 = Transaction.fromValuesArray(rawTx.map(toBuffer)) // This is also a maninnet transaction
const tx2 = Transaction.fromValuesArray(rawTx.map(toBuffer)) // This is also a mainnet transaction

// Note rlp.decode will produce an array of buffers.
// So assuming that you were able to parse the transaction, we will now get the sender's address.
Expand Down
3 changes: 2 additions & 1 deletion packages/tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"tape": "tape -r ts-node/register",
"test": "npm run test:node && npm run test:browser",
"test:node": "tape -r ts-node/register ./test/index.ts",
"test:browser": "karma start karma.conf.js"
"test:browser": "karma start karma.conf.js",
"examples": "ts-node ../../scripts/examples-runner.ts -- tx"
},
"dependencies": {
"@ethereumjs/common": "^2.6.0",
Expand Down
26 changes: 26 additions & 0 deletions scripts/examples-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { extname, join } from 'path'
import { readdir } from 'fs'

const pkg = process.argv[3]
if (!pkg) {
throw new Error('Package argument must be passed')
}

const examplesPath = `../packages/${pkg}/examples/`
const path = join(__dirname, examplesPath)

readdir(path, async (err, files) => {
if (err) {
throw new Error('Error loading examples directory: ' + err.message)
}

const getTsFiles = (fileName: string): Promise<NodeModule> | undefined => {
if (extname(fileName) === '.ts') {
return import(examplesPath + fileName)
}
}

const importedFiles = files.map(getTsFiles).filter((file) => file)

await Promise.all(importedFiles)
})

0 comments on commit 4d087b4

Please sign in to comment.