diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml new file mode 100644 index 00000000..4eaea94b --- /dev/null +++ b/.github/workflows/canary.yml @@ -0,0 +1,19 @@ +name: Run Canary +on: + push: + tags: + - '*' + +jobs: + trigger_canary: + if: startsWith(github.ref, 'refs/tags/') # Only run when a new package is published (detects when a new tag is pushed) + runs-on: ubuntu-latest + steps: + - name: trigger canary + run: | + curl -L -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.CANARY_DISPATCH_PAT }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/holepunchto/canary-tests/dispatches \ + -d '{"event_type":"triggered-by-${{ github.event.repository.name }}-${{ github.ref_name }}"}' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..d55b770c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: Lint + +on: + push: + branches: [main, rocksdb] + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + name: Lint + steps: + - uses: holepunchto/actions/node-base@v1 + with: + allow-git: true + - run: npm run lint diff --git a/.github/workflows/test-bare.yml b/.github/workflows/test-bare.yml new file mode 100644 index 00000000..ec2a9064 --- /dev/null +++ b/.github/workflows/test-bare.yml @@ -0,0 +1,34 @@ +name: Test with Bare + +on: + push: + branches: [main, rocksdb] + pull_request: + +jobs: + test: + strategy: + matrix: + include: + - os: ubuntu-latest + platform: linux + arch: x64 + + - os: macos-latest + platform: darwin + arch: x64 + + - os: windows-latest + platform: win32 + arch: x64 + + runs-on: ${{ matrix.os }} + name: ${{ matrix.platform }}-${{ matrix.arch }} + steps: + - uses: holepunchto/actions/node-base@v1 + with: + allow-git: true + - uses: holepunchto/actions/setup-bare@v1 + + - name: Run tests + run: npm run test:bare diff --git a/.github/workflows/test-node.yml b/.github/workflows/test-node.yml index 1a0b3a7f..f7eaaf25 100644 --- a/.github/workflows/test-node.yml +++ b/.github/workflows/test-node.yml @@ -1,49 +1,33 @@ -name: Build Status +name: Test with Node + on: push: - branches: - - main - - rocksdb - tags: # To trigger the canary - - '*' + branches: [main, rocksdb] pull_request: - branches: - - main - - rocksdb + jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 https://github.com/actions/checkout/releases/tag/v4.1.1 - - uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2 https://github.com/actions/setup-node/releases/tag/v3.8.2 - - run: npm install - - run: npm run lint - build: - if: ${{ !startsWith(github.ref, 'refs/tags/')}} # Already runs for the push of the commit, no need to run again for the tag + test: strategy: matrix: - node-version: [lts/*] - os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + platform: linux + arch: x64 + + - os: macos-latest + platform: darwin + arch: x64 + + - os: windows-latest + platform: win32 + arch: x64 + runs-on: ${{ matrix.os }} + name: ${{ matrix.platform }}-${{ matrix.arch }} steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 https://github.com/actions/checkout/releases/tag/v4.1.1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2 https://github.com/actions/setup-node/releases/tag/v3.8.2 + - uses: holepunchto/actions/node-base@v1 with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test - - run: npm -g install bare - - run: npm run test:bare - trigger_canary: - if: startsWith(github.ref, 'refs/tags/') # Only run when a new package is published (detects when a new tag is pushed) - runs-on: ubuntu-latest - steps: - - name: trigger canary - run: | - curl -L -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.CANARY_DISPATCH_PAT }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/holepunchto/canary-tests/dispatches \ - -d '{"event_type":"triggered-by-${{ github.event.repository.name }}-${{ github.ref_name }}"}' + allow-git: true + + - name: Run tests + run: npm run test:node diff --git a/package.json b/package.json index 4848a184..4fd5a06d 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "scripts": { "format": "prettier --write .", "lint": "prettier --check . && lunte", - "test": "brittle test/all.js", - "test:bare": "bare test/all.js", - "test:generate": "brittle -r test/all.js test/*.js" + "test": "npm run test:node && npm run test:bare", + "test:node": "brittle-node test/all.mjs", + "test:bare": "brittle-bare -j 4 test/all.mjs", + "test:generate": "brittle-make-test test/all.mjs test/*.js" }, "repository": { "type": "git", @@ -67,7 +68,7 @@ "z32": "^1.0.0" }, "devDependencies": { - "brittle": "^3.0.0", + "brittle": "github:holepunchto/brittle#v4", "debugging-stream": "^3.1.0", "hyperswarm": "^4.3.6", "lunte": "^1.3.0", diff --git a/test/all.js b/test/all.js deleted file mode 100644 index 40c818d2..00000000 --- a/test/all.js +++ /dev/null @@ -1,43 +0,0 @@ -// This runner is auto-generated by Brittle - -runTests() - -async function runTests() { - const test = (await import('brittle')).default - - test.pause() - - await import('./atomic.js') - await import('./basic.js') // todo: implement storageInfo API - await import('./batch.js') - await import('./bit-interlude.js') - await import('./bitfield.js') - await import('./clear.js') // todo: replace Info.bytesUsed API - // await import('./compat.js') // todo: how to test compat? - await import('./conflicts.js') - await import('./core.js') - await import('./encodings.js') - await import('./encryption.js') - await import('./extension.js') - await import('./fully-remote-proof.js') - await import('./manifest.js') - await import('./mark-n-sweep.js') - await import('./merkle-tree.js') - await import('./merkle-tree-recovery.js') - await import('./move-to.js') - await import('./mutex.js') - await import('./preload.js') - // await import('./purge.js') // todo: implement purge - await import('./push.js') - await import('./remote-bitfield.js') - await import('./remote-length.js') - await import('./replicate.js') - await import('./sessions.js') - await import('./snapshots.js') - await import('./streams.js') - await import('./timeouts.js') - await import('./user-data.js') - await import('./wants.js') - - test.resume() -} diff --git a/test/all.mjs b/test/all.mjs new file mode 100644 index 00000000..7ab7f679 --- /dev/null +++ b/test/all.mjs @@ -0,0 +1,43 @@ +// This runner is auto-generated by Brittle + +await runTests() + +async function runTests() { + const test = (await import('brittle')).default + + test.pause() + + await test.load(import.meta.resolve('./atomic.js')) + await test.load(import.meta.resolve('./basic.js')) // todo: implement storageInfo API + await test.load(import.meta.resolve('./batch.js')) + await test.load(import.meta.resolve('./bit-interlude.js')) + await test.load(import.meta.resolve('./bitfield.js')) + await test.load(import.meta.resolve('./clear.js')) // todo: replace Info.bytesUsed API + // await test.load(import.meta.resolve('./compat.js')) // todo: how to test compat? + await test.load(import.meta.resolve('./conflicts.js')) + await test.load(import.meta.resolve('./core.js')) + await test.load(import.meta.resolve('./encodings.js')) + await test.load(import.meta.resolve('./encryption.js')) + await test.load(import.meta.resolve('./extension.js')) + await test.load(import.meta.resolve('./fully-remote-proof.js')) + await test.load(import.meta.resolve('./manifest.js')) + await test.load(import.meta.resolve('./mark-n-sweep.js')) + await test.load(import.meta.resolve('./merkle-tree.js')) + await test.load(import.meta.resolve('./merkle-tree-recovery.js')) + await test.load(import.meta.resolve('./move-to.js')) + await test.load(import.meta.resolve('./mutex.js')) + await test.load(import.meta.resolve('./preload.js')) + // await test.load(import.meta.resolve('./purge.js')) // todo: implement purge + await test.load(import.meta.resolve('./push.js')) + await test.load(import.meta.resolve('./remote-bitfield.js')) + await test.load(import.meta.resolve('./remote-length.js')) + await test.load(import.meta.resolve('./replicate.js')) + await test.load(import.meta.resolve('./sessions.js')) + await test.load(import.meta.resolve('./snapshots.js')) + await test.load(import.meta.resolve('./streams.js')) + await test.load(import.meta.resolve('./timeouts.js')) + await test.load(import.meta.resolve('./user-data.js')) + await test.load(import.meta.resolve('./wants.js')) + + test.resume() +} diff --git a/test/mark-n-sweep.js b/test/mark-n-sweep.js index 6000322d..ed84b5ef 100644 --- a/test/mark-n-sweep.js +++ b/test/mark-n-sweep.js @@ -3,7 +3,7 @@ const { create, createStorage } = require('./helpers') const Hypercore = require('../') -test('startMarking - basic', async (t) => { +test('startMarking - basic', { timeout: 60_000 }, async (t) => { const core = await create(t) const num = 50_000 @@ -90,7 +90,7 @@ test('startMarking then immediate sweep', async (t) => { t.absent(await core.has(0, core.length), 'cleared all blocks') }) -test('startMarking - on session', async (t) => { +test('startMarking - on session', { timeout: 60_000 }, async (t) => { const core = await create(t) const num = 50_000