Skip to content

Commit

Permalink
Bump dependencies / ESM / bundle with esbuild (#36)
Browse files Browse the repository at this point in the history
* Support arm64 architecture
* Bump references to v1 rc
* Bump dependencies / ESM / bundle with esbuild
  • Loading branch information
CarsonF authored Oct 13, 2023
1 parent 8bc9e10 commit abd93e5
Show file tree
Hide file tree
Showing 18 changed files with 3,448 additions and 19,241 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
cli-version: [stable, nightly]
server-version: [stable, nightly, 1.0-rc.2]
server-version: [stable, nightly, 3.0-rc.1]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -44,13 +44,13 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
cli-version: [stable, nightly]
server-version: [stable, nightly, 1.0-rc.2]
server-version: [stable, nightly, 3.0-rc.1]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Create edgedb.toml
run: |
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
echo -e '[edgedb]\nserver-version = "3.0-rc.1"' >> edgedb.toml
- uses: ./
with:
cli-version: ${{ matrix.cli-version }}
Expand All @@ -67,7 +67,7 @@ jobs:
fail-fast: false
services:
edgedb:
image: edgedb/edgedb:1-rc2
image: edgedb/edgedb:3
env:
EDGEDB_SERVER_SECURITY: insecure_dev_mode
ports:
Expand All @@ -76,7 +76,7 @@ jobs:
- uses: actions/checkout@v2
- name: Create edgedb.toml
run: |
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
echo -e '[edgedb]\nserver-version = "3.0-rc.1"' >> edgedb.toml
- uses: ./
with:
server-dsn: edgedb://localhost:5656
Expand Down
152 changes: 69 additions & 83 deletions __tests__/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,64 @@
import * as main from '../src/main'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {ExecOptions} from '@actions/exec/lib/interfaces'
import * as io from '@actions/io'
import * as tc from '@actions/tool-cache'
import type * as coreType from '@actions/core'
import type * as execType from '@actions/exec'
import type * as tcType from '@actions/tool-cache'
import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
jest
} from '@jest/globals'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as process from 'process'
import url from 'url'
import type * as mainType from '../src/main'
import {SpiedModule, spyOnModule} from './spy-on-module'

const toolDir = path.join(
__dirname,
'runner',
path.join(Math.random().toString(36).substring(7)),
'tools'
)
const tempDir = path.join(
__dirname,
path.dirname(url.fileURLToPath(import.meta.url)),
'runner',
path.join(Math.random().toString(36).substring(7)),
'temp'
Math.random().toString(36).substring(7)
)

process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir
process.env.RUNNER_TOOL_CACHE = path.join(tempDir, 'tools')
process.env.RUNNER_TEMP = path.join(tempDir, 'temp')

describe('setup-edgedb', () => {
let inputs = {} as any
let inSpy: jest.SpyInstance
let inBooleanSpy: jest.SpyInstance
let cnSpy: jest.SpyInstance
let logSpy: jest.SpyInstance
let dbgSpy: jest.SpyInstance
let warningSpy: jest.SpyInstance
let dlSpy: jest.SpyInstance
let findSpy: jest.SpyInstance
let cacheSpy: jest.SpyInstance
let execSpy: jest.SpyInstance

beforeEach(() => {
// @actions/core
let inputs: Record<string, string | boolean> = {}
let core: SpiedModule<typeof coreType>
let exec: SpiedModule<typeof execType>
let tc: SpiedModule<typeof tcType>
let main: typeof mainType

beforeAll(async () => {
core = await spyOnModule<typeof coreType>('@actions/core')
tc = await spyOnModule<typeof tcType>('@actions/tool-cache')
exec = await spyOnModule<typeof execType>('@actions/exec')
// After mocks have been set up
main = await import('../src/main')
})

beforeEach(async () => {
// eslint-disable-next-line no-console
console.log('::stop-commands::stoptoken')
process.env['GITHUB_PATH'] = ''
inputs = {
'server-dsn': false
}
inSpy = jest.spyOn(core, 'getInput')
inSpy.mockImplementation(name => inputs[name] || '')
inBooleanSpy = jest.spyOn(core, 'getBooleanInput')
inBooleanSpy.mockImplementation(name => inputs[name])

// @actions/tool-cache
dlSpy = jest.spyOn(tc, 'downloadTool')
findSpy = jest.spyOn(tc, 'find')
cacheSpy = jest.spyOn(tc, 'cacheFile')

// @actions/exec
execSpy = jest.spyOn(exec, 'exec')

// writes
cnSpy = jest.spyOn(process.stdout, 'write')
logSpy = jest.spyOn(core, 'info')
dbgSpy = jest.spyOn(core, 'debug')
warningSpy = jest.spyOn(core, 'warning')
cnSpy.mockImplementation(line => {
// uncomment to debug
process.stderr.write('write:' + line + '\n')
})
logSpy.mockImplementation(line => {

core.getInput.mockImplementation(name => String(inputs[name] || ''))
core.getBooleanInput.mockImplementation(name => Boolean(inputs[name]))

core.info.mockImplementation(line => {
// uncomment to debug
process.stderr.write('log:' + line + '\n')
process.stderr.write(`log:${line}\n`)
})
dbgSpy.mockImplementation(msg => {
core.debug.mockImplementation(msg => {
// uncomment to see debug output
process.stderr.write(msg + '\n')
process.stderr.write(`${msg}\n`)
})
})

Expand All @@ -83,71 +68,72 @@ describe('setup-edgedb', () => {
})

it('Installs CLI', async () => {
inputs['cli-version'] = '>=1.0.0-rc.1 <=1.0.0-rc.2'
inputs['cli-version'] = '>=3.2.0 <=3.4.0'

let libc = ''
if (os.platform() == 'linux') {
if (os.platform() === 'linux') {
libc = 'musl'
}
const baseDist = main.getBaseDist(os.arch(), os.platform(), libc)
const pkgBase = `https://packages.edgedb.com/archive/${baseDist}`
const expectedVer = '1.0.0-rc.2\\+([0-9a-f]{7})'
const expectedVer = '3.4.0\\+([0-9a-f]{7})'
const expectedUrl = `${pkgBase}/edgedb-cli-${expectedVer}`

const tmpdir = fs.mkdtempSync('edgedb-setup')
let tmp = path.join(tmpdir, 'foo')
fs.closeSync(fs.openSync(tmp, 'w'))
tmp = fs.realpathSync(tmp)

dlSpy.mockImplementation(async () => tmp)
tc.downloadTool.mockImplementation(async () => tmp)

findSpy.mockImplementation(() => '')
tc.find.mockImplementation(() => '')

const cliPath = path.normalize('/cache/edgedb/1.0.0-rc.2')
cacheSpy.mockImplementation(async () => cliPath)
const cliPath = path.normalize('/cache/edgedb/3.4.0')
tc.cacheFile.mockImplementation(async () => cliPath)

await main.run()

fs.unlinkSync(tmp)
fs.rmdirSync(tmpdir)

expect(dlSpy).toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledWith(
expect(tc.downloadTool).toHaveBeenCalled()
expect(core.info).toHaveBeenCalledWith(
expect.stringMatching(
new RegExp(
`Downloading edgedb-cli ${expectedVer} - ${os.arch} from ${expectedUrl}`
`Downloading edgedb-cli ${expectedVer} - ${os.arch()} from ${expectedUrl}`
)
)
)
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${cliPath}${os.EOL}`)
expect(core.addPath).toHaveBeenCalledWith(cliPath)
})

it('Installs server', async () => {
inputs['cli-version'] = '>=1.0.0-rc.1 <=1.0.0-rc.2'
inputs['cli-version'] = '>=3.2.0 <=3.4.0'
inputs['server-version'] = 'stable'

let libc = ''
if (os.platform() == 'linux') {
if (os.platform() === 'linux') {
libc = 'musl'
}
const baseDist = main.getBaseDist(os.arch(), os.platform(), libc)
const pkgBase = `https://packages.edgedb.com/archive/${baseDist}`
const expectedVer = '1.0.0-rc.2\\+([0-9a-f]{7})'
const expectedVer = '3.4.0\\+([0-9a-f]{7})'
const expectedUrl = `${pkgBase}/edgedb-cli-${expectedVer}`

const tmpdir = fs.mkdtempSync('edgedb-setup')
let tmp = path.join(tmpdir, 'foo')
fs.closeSync(fs.openSync(tmp, 'w'))
tmp = fs.realpathSync(tmp)

dlSpy.mockImplementation(async () => tmp)
tc.downloadTool.mockImplementation(async () => tmp)

findSpy.mockImplementation(() => '')
tc.find.mockImplementation(() => '')

execSpy.mockImplementation(async (cmd, args, opts: ExecOptions) => {
if (args[0] === 'server' && args[1] === 'install') {
exec.exec.mockImplementation(async (cmd, args, opts) => {
if (args && args[0] === 'server' && args[1] === 'install') {
return 0
} else if (
args &&
args[0] === 'server' &&
args[1] === 'info' &&
args[2] === '--bin-path'
Expand All @@ -161,24 +147,24 @@ describe('setup-edgedb', () => {
}
})

const cliPath = path.normalize('/cache/edgedb/1.0.0-rc.2')
cacheSpy.mockImplementation(async () => cliPath)
const cliPath = path.normalize('/cache/edgedb/3.4.0')
tc.cacheFile.mockImplementation(async () => cliPath)
const serverPath = path.dirname(tmp)

await main.run()

fs.unlinkSync(tmp)
fs.rmdirSync(tmpdir)

expect(dlSpy).toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledWith(
expect(tc.downloadTool).toHaveBeenCalled()
expect(core.info).toHaveBeenCalledWith(
expect.stringMatching(
new RegExp(
`Downloading edgedb-cli ${expectedVer} - ${os.arch} from ${expectedUrl}`
`Downloading edgedb-cli ${expectedVer} - ${os.arch()} from ${expectedUrl}`
)
)
)
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${serverPath}${os.EOL}`)
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${cliPath}${os.EOL}`)
expect(core.addPath).toHaveBeenCalledWith(serverPath)
expect(core.addPath).toHaveBeenCalledWith(cliPath)
})
})
27 changes: 27 additions & 0 deletions __tests__/spy-on-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {jest} from '@jest/globals'
import {FunctionLike} from 'jest-mock'

export type SpiedModule<T extends object> = {
[K in keyof T]: T[K] extends FunctionLike
? jest.SpiedFunction<T[K]> & T[K]
: T[K]
}

export const spyOnModule = async <T extends object>(
moduleName: string
): Promise<SpiedModule<T>> => {
const actual = await import(moduleName)
const props = Object.getOwnPropertyNames(actual)
jest.unstable_mockModule(moduleName, () =>
Object.fromEntries(
props.map(key => {
let value = actual[key]
if (typeof value === 'function') {
value = jest.fn(value)
}
return [key, value]
})
)
)
return await import(moduleName)
}
3 changes: 2 additions & 1 deletion __tests__/ver.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as main from '../src/main'
import {expect, describe, it} from '@jest/globals'

describe('setup-edgedb', () => {
it('Sorts versions correctly', async () => {
let versionMap = new Map([
const versionMap = new Map([
['1.0.0-beta.2+d20210806.g803b254e6', 'foo'],
['1.0.0-beta.2+d20210808.g121de78de', 'baz'],
['1.0.0-beta.2+d20210807.gba2c70f52', 'bar'],
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inputs:
description: >
Version of EdgeDB server to install, or "stable" for the latest
stable release, or "nightly" for the latest nightly build,
or "none" to skip installaion. Defaults to "stable".
or "none" to skip installation. Defaults to "stable".
default: 'stable'
instance-name:
required: false
Expand All @@ -38,5 +38,5 @@ inputs:
If set, specifies the directory with edgedb.toml project manifest.
default: ''
runs:
using: 'node12'
main: 'dist/index.js'
using: 'node20'
main: 'dist/index.cjs'
Loading

0 comments on commit abd93e5

Please sign in to comment.