From b9fb64b0934e234f1d2cd0ea9c3554ee5b555855 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 17 Jun 2019 09:32:51 -0400 Subject: [PATCH] Add ci and fix linux tests (#8) * Add actions ci * Add format-check * Test doesnt depend on build * Fix linux tests * Fix other linux test * Use azp for cross-platform support for now * Dogfood ci * Update main.workflow.yml * Update main.workflow.yml * Update main.workflow.yml * Update main.workflow.yml * Update main.workflow.yml * Update main.workflow.yml * back to runs-on * Try lowercase * Back to upper * Pool under runs-on * Switch from install to ci * Make sure we have right version of node * Indenting issues * Install instead of ci to avoid reinstalling tarballs * Update main.workflow.yml * Update main.workflow.yml * Try ci again * Update main.workflow.yml * Update main.workflow.yml * Update main.workflow.yml * Remove logging step * Try pruning first so that devDeps definitely aren't installed * Clean tests * Spacing * Randomize folder for concurrent builds * Dont fail on not being able to unlink * Dont fail on not being able to unlink --- .github/main.workflow.yml | 22 ++++++++++++++ __tests__/installer.test.ts | 60 +++++++++++++++++++++++++++++-------- package.json | 1 + 3 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 .github/main.workflow.yml diff --git a/.github/main.workflow.yml b/.github/main.workflow.yml new file mode 100644 index 00000000..6b27b44a --- /dev/null +++ b/.github/main.workflow.yml @@ -0,0 +1,22 @@ +on: push +jobs: + build: + runs-on: + pool: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [Linux, macOS, Windows] + actions: + - name: Set Node.js 10.x + uses: bryanmacfarlane/node-config@master + with: + version: 10.x + + - name: npm install + run: npm prune --production && npm install + + - name: Lint + run: npm run format-check + + - name: npm test + run: npm test diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 591e4018..b5b3899c 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -3,29 +3,61 @@ import fs = require('fs'); import os = require('os'); import path = require('path'); -const toolDir = path.join(__dirname, 'runner', 'tools'); -const tempDir = path.join(__dirname, 'runner', 'temp'); +const toolDir = path.join( + process.cwd(), + 'runner', + path.join( + Math.random() + .toString(36) + .substring(7) + ), + 'tools' +); +const tempDir = path.join( + process.cwd(), + 'runner', + path.join( + Math.random() + .toString(36) + .substring(7) + ), + 'temp' +); process.env['RUNNER_TOOLSDIRECTORY'] = toolDir; process.env['RUNNER_TEMPDIRECTORY'] = tempDir; import * as installer from '../src/installer'; +const IS_WINDOWS = process.platform === 'win32'; + describe('installer tests', () => { - beforeAll(() => {}); beforeAll(async () => { await io.rmRF(toolDir); await io.rmRF(tempDir); - }); + }, 100000); + + afterAll(async () => { + try { + await io.rmRF(toolDir); + await io.rmRF(tempDir); + } catch { + console.log('Failed to remove test directories'); + } + }, 100000); it('Acquires version of node if no matching version is installed', async () => { await installer.getNode('10.16.0'); const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch()); expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); - expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); + } }, 100000); - if (process.platform === 'win32') { + if (IS_WINDOWS) { it('Falls back to backup location if first one doesnt contain correct version', async () => { await installer.getNode('5.10.1'); const nodeDir = path.join(toolDir, 'node', '5.10.1', os.arch()); @@ -58,7 +90,11 @@ describe('installer tests', () => { const nodeDir = path.join(toolDir, 'node', '8.8.1', os.arch()); expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); - expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true); + } }, 100000); it('Uses version of node installed in cache', async () => { @@ -71,7 +107,7 @@ describe('installer tests', () => { }); it('Doesnt use version of node that was only partially installed in cache', async () => { - const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch()); + const nodeDir: string = path.join(toolDir, 'node', '251.0.0', os.arch()); await io.mkdirP(nodeDir); let thrown = false; try { @@ -85,12 +121,12 @@ describe('installer tests', () => { }); it('Resolves semantic versions of node installed in cache', async () => { - const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch()); + const nodeDir: string = path.join(toolDir, 'node', '252.0.0', os.arch()); await io.mkdirP(nodeDir); fs.writeFileSync(`${nodeDir}.complete`, 'hello'); // These will throw if it doesn't find it in the cache (because no such version exists) - await installer.getNode('250.0.0'); - await installer.getNode('250'); - await installer.getNode('250.0'); + await installer.getNode('252.0.0'); + await installer.getNode('252'); + await installer.getNode('252.0'); }); }); diff --git a/package.json b/package.json index 0dd0839f..03136b18 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "build": "tsc", "format": "prettier --write **/*.ts", + "format-check": "prettier --check **/*.ts", "test": "jest" }, "repository": {