Skip to content

Commit 4d087b4

Browse files
cbrznholgerd77
andauthored
Monorepo (& Tx, VM): Examples scripts in CI (#1658)
* 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>
1 parent c4cc930 commit 4d087b4

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

.github/workflows/examples.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Packages examples
2+
on:
3+
push:
4+
branches: [master, develop]
5+
pull_request:
6+
types: [opened, reopened, synchronize]
7+
8+
jobs:
9+
test-examples:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
submodules: recursive
15+
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: 16
19+
cache: 'npm'
20+
21+
- run: npm i
22+
- run: npm run examples

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"preinstall": "npm run checkNpmVersion",
3030
"postinstall": "npm run build --workspaces",
3131
"checkNpmVersion": "./scripts/check-npm-version.sh",
32+
"examples": "npm run examples --workspaces --if-present",
3233
"clean": "./config/cli/clean-root.sh",
3334
"e2e:publish": "./scripts/e2e-publish.sh",
3435
"e2e:resolutions": "node ./scripts/e2e-resolutions.js",

packages/tx/examples/transactions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ console.log('--------------------')
4343
// You can decode it with the rlp module.
4444
// After that you should have something like:
4545
const rawTx = [
46-
'0x00',
46+
'0x',
4747
'0x09184e72a000',
4848
'0x2710',
4949
'0x0000000000000000000000000000000000000000',
50-
'0x00',
50+
'0x',
5151
'0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
5252
'0x1c',
5353
'0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
5454
'0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13',
5555
]
5656

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

5959
// Note rlp.decode will produce an array of buffers.
6060
// So assuming that you were able to parse the transaction, we will now get the sender's address.

packages/tx/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"tape": "tape -r ts-node/register",
3131
"test": "npm run test:node && npm run test:browser",
3232
"test:node": "tape -r ts-node/register ./test/index.ts",
33-
"test:browser": "karma start karma.conf.js"
33+
"test:browser": "karma start karma.conf.js",
34+
"examples": "ts-node ../../scripts/examples-runner.ts -- tx"
3435
},
3536
"dependencies": {
3637
"@ethereumjs/common": "^2.6.0",

scripts/examples-runner.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { extname, join } from 'path'
2+
import { readdir } from 'fs'
3+
4+
const pkg = process.argv[3]
5+
if (!pkg) {
6+
throw new Error('Package argument must be passed')
7+
}
8+
9+
const examplesPath = `../packages/${pkg}/examples/`
10+
const path = join(__dirname, examplesPath)
11+
12+
readdir(path, async (err, files) => {
13+
if (err) {
14+
throw new Error('Error loading examples directory: ' + err.message)
15+
}
16+
17+
const getTsFiles = (fileName: string): Promise<NodeModule> | undefined => {
18+
if (extname(fileName) === '.ts') {
19+
return import(examplesPath + fileName)
20+
}
21+
}
22+
23+
const importedFiles = files.map(getTsFiles).filter((file) => file)
24+
25+
await Promise.all(importedFiles)
26+
})

0 commit comments

Comments
 (0)