From 98fc4546f3d785fbdb230998018e978993575d43 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Thu, 4 Jan 2024 23:29:55 +0100 Subject: [PATCH] Improve per version CI following mineflayer example. (#646) * Improve per version CI following mineflayer example. * Change build name for test. * fix simple test --- .github/workflows/ci.yml | 57 +++++++++++++++++++++++++++++----------- test/common/parallel.js | 33 ----------------------- test/mineflayer.test.js | 8 +----- test/portal.test.js | 5 +--- test/simple.test.js | 8 +----- 5 files changed, 44 insertions(+), 67 deletions(-) delete mode 100644 test/common/parallel.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1e1e801..fdd5e478 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,29 +2,54 @@ name: CI on: push: - branches: [ master ] + branches: + - master pull_request: - branches: [ master, "1.13" ] jobs: - build: + Lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 18.x + uses: actions/setup-node@v1.4.4 + with: + node-version: 18.x + - run: npm i && npm run lint + + PrepareSupportedVersions: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 18.x + uses: actions/setup-node@v1.4.4 + with: + node-version: 18.x + - id: set-matrix + run: | + node -e " + const supportedVersions = require('./src/lib/version').supportedVersions; + console.log('matrix='+JSON.stringify({'include': supportedVersions.map(mcVersion => ({mcVersion}))})) + " >> $GITHUB_OUTPUT + + Test: + needs: PrepareSupportedVersions + runs-on: ubuntu-latest strategy: - matrix: - node-version: [18.x] - mcVersionIndex: [0, 1, 2, 3, 4, 5, 6, 7, 8] + matrix: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}} fail-fast: false steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - env: - CIRCLE_NODE_INDEX: ${{ matrix.mcVersionIndex }} - CIRCLE_NODE_TOTAL: 9 - run: npm test + - uses: actions/checkout@v2 + - name: Use Node.js 18.x + uses: actions/setup-node@v1.4.4 + with: + node-version: 18.x + - name: Install Dependencies + run: npm install + - name: Start Tests + run: npm run mocha_test -- -g ${{ matrix.mcVersion }}v \ No newline at end of file diff --git a/test/common/parallel.js b/test/common/parallel.js deleted file mode 100644 index 2fe89f45..00000000 --- a/test/common/parallel.js +++ /dev/null @@ -1,33 +0,0 @@ -const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX) -const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL) -const parallel = process.env.CIRCLE_NODE_INDEX !== undefined && process.env.CIRCLE_NODE_TOTAL !== undefined -const mc = require('../../') - -// expected values : -// (0,4,10) -> (0,2) -// (1,4,10) -> (3,5) -// (2,4,10) -> (6,8) -// (3,4,10) -> (9,9) -function testedRange (nodeIndex, nodeTotal, numberOfVersions) { - const nbFirsts = Math.ceil(numberOfVersions / nodeTotal) - if (nodeIndex === (nodeTotal - 1)) { - return { - firstVersion: nbFirsts * nodeIndex, - lastVersion: numberOfVersions - 1 - } - } - - return { - firstVersion: nodeIndex * nbFirsts, - lastVersion: (nodeIndex + 1) * nbFirsts - 1 - } -} -console.log({ nodeIndex, nodeTotal, versions: mc.supportedVersions.length }) -const { firstVersion, lastVersion } = parallel - ? testedRange(nodeIndex, nodeTotal, mc.supportedVersions.length) - : { - firstVersion: 0, - lastVersion: mc.supportedVersions.length - 1 - } - -module.exports = { firstVersion, lastVersion } diff --git a/test/mineflayer.test.js b/test/mineflayer.test.js index ba38fe30..76ee41f6 100644 --- a/test/mineflayer.test.js +++ b/test/mineflayer.test.js @@ -12,19 +12,13 @@ function assertPosEqual (actual, expected, precision = 1) { const once = require('event-promise') -const { firstVersion, lastVersion } = require('./common/parallel') - squid.supportedVersions.forEach((supportedVersion, i) => { - if (!(i >= firstVersion && i <= lastVersion)) { - return - } - const mcData = require('minecraft-data')(supportedVersion) const version = mcData.version const Item = require('prismarine-item')(supportedVersion) - describe('server with mineflayer connection ' + version.minecraftVersion, () => { + describe('server with mineflayer connection ' + supportedVersion + 'v', () => { /** @type {import('mineflayer').Bot} */ let bot /** @type {import('mineflayer').Bot} */ diff --git a/test/portal.test.js b/test/portal.test.js index bf0d2b36..ac4cbff6 100644 --- a/test/portal.test.js +++ b/test/portal.test.js @@ -1,12 +1,9 @@ /* eslint-env mocha */ const squid = require('flying-squid') -const { firstVersion, lastVersion } = require('./common/parallel') const expect = require('expect').default squid.supportedVersions.forEach((supportedVersion, i) => { - if (!(i >= firstVersion && i <= lastVersion)) return - const mcData = require('minecraft-data')(supportedVersion) const version = mcData.version @@ -22,7 +19,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => { const { Vec3 } = require('vec3') - describe('generate portal ' + version.minecraftVersion, () => { + describe('generate portal ' + supportedVersion + 'v', () => { it('generate a line', () => { expect(generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2)).toEqual([new Vec3(3, 1, 1), new Vec3(4, 1, 1)]) }) diff --git a/test/simple.test.js b/test/simple.test.js index 4c0bb3b3..97ea0e7c 100644 --- a/test/simple.test.js +++ b/test/simple.test.js @@ -5,17 +5,11 @@ const squid = require('flying-squid') const settings = require('../config/default-settings') -const { firstVersion, lastVersion } = require('./common/parallel') - squid.supportedVersions.forEach((supportedVersion, i) => { - if (!(i >= firstVersion && i <= lastVersion)) { - return - } - const mcData = require('minecraft-data')(supportedVersion) const version = mcData.version - describe(`simple server ${version.minecraftVersion}`, () => { + describe(`simple server ${supportedVersion}v`, () => { let serv before(done => {