Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add more runtimes/versions to CI #98

Merged
merged 9 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/actions/pnpm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
description: Enable corepack
required: false
default: 'true'
node-version:
description: Node version to use
required: false
default: '20'

runs:
using: composite
Expand All @@ -16,7 +20,7 @@ runs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: ${{ inputs.node-version }}
- name: ⚙️ Enable Corepack
if: ${{ inputs.enable-corepack == 'true' }}
shell: bash
Expand Down Expand Up @@ -47,9 +51,9 @@ runs:
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
key: ${{ runner.os }}-node-${{ inputs.node-version }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
${{ runner.os }}-node-${{ inputs.node-version }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-

- name: Install dependencies
shell: bash
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/integration-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@ on: workflow_call
jobs:
integration-testing:
runs-on: ubuntu-latest
strategy:
matrix:
pm:
- name: npm
version: 10.8.1
- name: pnpm
version: 9.4.0
- name: yarn
version: 1.22.22
- name: bun
version: 1.1.17
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/pnpm-install
- name: Install Bun
uses: oven-sh/setup-bun@v2
if: ${{ matrix.pm.name == 'bun' }}
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Run Vitest
run: pnpm run test:integration
env:
INTEGRATION_PM_NAME: ${{ matrix.pm.name }}
INTEGRATION_PM_VERSION: ${{ matrix.pm.version }}
5 changes: 5 additions & 0 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ on: workflow_call
jobs:
unit-testing:
runs-on: ubuntu-latest
strategy:
matrix:
version: [18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/pnpm-install
with:
node-version: ${{ matrix.version }}
- name: Run Vitest
run: pnpm run test:unit
21 changes: 21 additions & 0 deletions integration/__tests__/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SeccoCLI } from '../helpers/invoke-cli'
import { version as seccoVersion } from '../../package.json'

const initQuestion = 'What is the absolute path to your source?'
const warning = '.seccorc file already exists in this directory'
Expand All @@ -19,3 +20,23 @@ describe('init', () => {
expect(exitCode).toBe(0)
})
})

describe('--help', () => {
it('should display usage overview', () => {
const [exitCode, logs] = SeccoCLI().invoke(['--help'])

logs.should.contain('Usage:')
logs.should.contain('Options:')
logs.should.contain('Examples:')
expect(exitCode).toBe(0)
})
})

describe('--version', () => {
it('should display current CLI version', () => {
const [exitCode, logs] = SeccoCLI().invoke(['--version'])

logs.should.contain(seccoVersion)
expect(exitCode).toBe(0)
})
})
23 changes: 10 additions & 13 deletions integration/__tests__/kitchen-sink.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import type { SetupReturn } from '../helpers/setup-kitchen-sink'
import { KitchenSink } from '../helpers/setup-kitchen-sink'
import type { Application } from '../models/application'
import { presets } from '../presets'

describe.sequential('mode: sequential', () => {
let cleanup: SetupReturn['cleanup']
let cli: SetupReturn['cli']
let app: Application

beforeAll(async () => {
const { cleanup: _cleanup, cli: _cli } = await KitchenSink().setup()

cleanup = _cleanup
cli = _cli
app = await presets.kitchenSink.commit()
})

afterAll(async () => {
await cleanup()
await app.cleanup()
})

it('should run Verdaccio with --force-verdaccio', () => {
const [exitCode, logs] = cli(['--scan-once', '--force-verdaccio'], { verbose: true })
const [exitCode, logs] = app.cli(['--scan-once', '--force-verdaccio'], { verbose: true })

logs.should.contain('[log] [Verdaccio] Starting server...')
logs.should.contain('[log] [Verdaccio] Started successfully!')
logs.should.contain('[log] Publishing `[email protected]')
logs.should.contain('[log] Published `[email protected]')
logs.should.contain(`[debug] Detected package manager in destination: ${app.packageManager.split('@')[0]}`)
logs.should.contain('[log] Installing packages from local registry:')
logs.should.contain('[success] Installation finished successfully!')

expect(exitCode).toBe(0)
})

it('verbose should be enabled through --verbose flag', () => {
const [exitCode, logs] = cli(['--verbose', '--scan-once'])
const [exitCode, logs] = app.cli(['--verbose', '--scan-once'])

logs.should.contain('[debug] Found 1 packages in source.')
logs.should.contain('[debug] Found 1 destination packages.')
Expand All @@ -39,7 +36,7 @@ describe.sequential('mode: sequential', () => {
})

it('verbose should be enabled through VERBOSE env var', () => {
const [exitCode, logs] = cli(['--scan-once'], { verbose: true })
const [exitCode, logs] = app.cli(['--scan-once'], { verbose: true })

logs.should.contain('[debug] Found 1 packages in source.')
logs.should.contain('[debug] Found 1 destination packages.')
Expand All @@ -48,7 +45,7 @@ describe.sequential('mode: sequential', () => {
})

it('should copy files on consecutive runs', () => {
const [exitCode, logs] = cli(['--scan-once'], { verbose: true })
const [exitCode, logs] = app.cli(['--scan-once'], { verbose: true })

logs.should.not.contain('[log] [Verdaccio] Starting server...')
logs.should.not.contain('[success] Installation finished successfully!')
Expand Down
2 changes: 1 addition & 1 deletion integration/__tests__/missing-information.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path'
import { join } from 'pathe'
import { SeccoCLI } from '../helpers/invoke-cli'

const missingSourcePackagesLocation = join(__dirname, '..', 'fixtures', 'missing-source-packages')
Expand Down
12 changes: 12 additions & 0 deletions integration/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { resolve } from 'pathe'

/**
* Any fixture added to this record needs to be in the following folder format:
* - destination
* - source
*/
export const fixtures = {
'kitchen-sink': resolve(__dirname, 'kitchen-sink'),
} as const

export type Fixture = keyof typeof fixtures
1 change: 0 additions & 1 deletion integration/fixtures/kitchen-sink/destination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "destination",
"version": "1.0.0",
"private": true,
"packageManager": "[email protected]",
"main": "bin.mjs",
"scripts": {
"start": "node bin.mjs"
Expand Down
2 changes: 1 addition & 1 deletion integration/fixtures/kitchen-sink/source/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "say-hello-world",
"version": "0.0.2",
"packageManager": "[email protected].0",
"packageManager": "[email protected].0",
"main": "index.mjs"
}
2 changes: 1 addition & 1 deletion integration/helpers/invoke-cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'node:path'
import process from 'node:process'
import { join } from 'pathe'
import type { ExecaSyncError } from 'execa'
import { execaSync } from 'execa'
import strip from 'strip-ansi'
Expand Down
38 changes: 38 additions & 0 deletions integration/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { colors as consolaColors } from 'consola/utils'

const colors = [
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'redBright',
'greenBright',
'yellowBright',
'blueBright',
'magentaBright',
'cyanBright',
] as const

type Color = typeof colors[number]

function getRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}

interface CreateLoggerOptions {
prefix: string
color?: Color
}

export function createLogger(opts: CreateLoggerOptions) {
const { prefix, color = getRandomColor() } = opts

return {
log: (msg: string) => {
// eslint-disable-next-line no-console
console.log(consolaColors[color](`[${prefix}] ${msg}`))
},
}
}
74 changes: 0 additions & 74 deletions integration/helpers/setup-kitchen-sink.ts

This file was deleted.

70 changes: 70 additions & 0 deletions integration/models/application-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { cp, mkdtemp, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import fs from 'fs-extra'
import { basename, join } from 'pathe'
import { CONFIG_FILE_NAME } from '../../src/constants'
import { createLogger } from '../helpers/logger'
import { packageManager as rootPackageManager } from '../../package.json'
import { application } from './application'

export type ApplicationConfig = ReturnType<typeof applicationConfig>

type PackageManagerName = 'npm' | 'pnpm' | 'yarn' | 'bun'

export function applicationConfig() {
let name = ''
let template = ''
let packageManager: `${PackageManagerName}@${string}` = rootPackageManager as `pnpm@${string}`
const logger = createLogger({ prefix: 'appConfig', color: 'yellow' })

const self = {
setName: (_name: string) => {
name = _name
return self
},
setTemplate: (_template: string) => {
template = _template
return self
},
get name() {
return name
},
get packageManager() {
return packageManager
},
clone: () => {
const clone = applicationConfig()
clone.setName(name)
clone.setTemplate(template)

return clone
},
setPackageManager: (name?: PackageManagerName, version?: string) => {
if (name && version) {
packageManager = `${name}@${version}`
}
return self
},
commit: async () => {
logger.log(`Creating application "${name}"`)

const isolatedDir = await mkdtemp(join(tmpdir(), `secco-${name}-`))

logger.log(`Copying template "${basename(template)}" to "${isolatedDir}"`)
await cp(template, isolatedDir, { recursive: true })

logger.log('Creating .seccorc file')
await writeFile(join(isolatedDir, 'destination', CONFIG_FILE_NAME), `source.path="${join(isolatedDir, 'source')}"`, { encoding: 'utf-8' })

logger.log(`Setting package manager to "${packageManager}" in destination`)
const pkgJsonPath = join(isolatedDir, 'destination', 'package.json')
const contents = await fs.readJSON(pkgJsonPath)
contents.packageManager = packageManager
await fs.writeJSON(pkgJsonPath, contents, { spaces: 2 })

return application(self, isolatedDir)
},
}

return self
}
Loading
Loading