Skip to content

Commit abd93e5

Browse files
authored
Bump dependencies / ESM / bundle with esbuild (#36)
* Support arm64 architecture * Bump references to v1 rc * Bump dependencies / ESM / bundle with esbuild
1 parent 8bc9e10 commit abd93e5

18 files changed

Lines changed: 3448 additions & 19241 deletions

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
matrix:
2626
os: [ubuntu-latest, macos-latest]
2727
cli-version: [stable, nightly]
28-
server-version: [stable, nightly, 1.0-rc.2]
28+
server-version: [stable, nightly, 3.0-rc.1]
2929
fail-fast: false
3030
steps:
3131
- uses: actions/checkout@v2
@@ -44,13 +44,13 @@ jobs:
4444
matrix:
4545
os: [ubuntu-latest, macos-latest]
4646
cli-version: [stable, nightly]
47-
server-version: [stable, nightly, 1.0-rc.2]
47+
server-version: [stable, nightly, 3.0-rc.1]
4848
fail-fast: false
4949
steps:
5050
- uses: actions/checkout@v2
5151
- name: Create edgedb.toml
5252
run: |
53-
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
53+
echo -e '[edgedb]\nserver-version = "3.0-rc.1"' >> edgedb.toml
5454
- uses: ./
5555
with:
5656
cli-version: ${{ matrix.cli-version }}
@@ -67,7 +67,7 @@ jobs:
6767
fail-fast: false
6868
services:
6969
edgedb:
70-
image: edgedb/edgedb:1-rc2
70+
image: edgedb/edgedb:3
7171
env:
7272
EDGEDB_SERVER_SECURITY: insecure_dev_mode
7373
ports:
@@ -76,7 +76,7 @@ jobs:
7676
- uses: actions/checkout@v2
7777
- name: Create edgedb.toml
7878
run: |
79-
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
79+
echo -e '[edgedb]\nserver-version = "3.0-rc.1"' >> edgedb.toml
8080
- uses: ./
8181
with:
8282
server-dsn: edgedb://localhost:5656

__tests__/setup.test.ts

Lines changed: 69 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,64 @@
1-
import * as main from '../src/main'
2-
import * as core from '@actions/core'
3-
import * as exec from '@actions/exec'
4-
import {ExecOptions} from '@actions/exec/lib/interfaces'
5-
import * as io from '@actions/io'
6-
import * as tc from '@actions/tool-cache'
1+
import type * as coreType from '@actions/core'
2+
import type * as execType from '@actions/exec'
3+
import type * as tcType from '@actions/tool-cache'
4+
import {
5+
afterEach,
6+
beforeAll,
7+
beforeEach,
8+
describe,
9+
expect,
10+
it,
11+
jest
12+
} from '@jest/globals'
713
import * as fs from 'fs'
814
import * as os from 'os'
915
import * as path from 'path'
1016
import * as process from 'process'
17+
import url from 'url'
18+
import type * as mainType from '../src/main'
19+
import {SpiedModule, spyOnModule} from './spy-on-module'
1120

12-
const toolDir = path.join(
13-
__dirname,
14-
'runner',
15-
path.join(Math.random().toString(36).substring(7)),
16-
'tools'
17-
)
1821
const tempDir = path.join(
19-
__dirname,
22+
path.dirname(url.fileURLToPath(import.meta.url)),
2023
'runner',
21-
path.join(Math.random().toString(36).substring(7)),
22-
'temp'
24+
Math.random().toString(36).substring(7)
2325
)
24-
25-
process.env['RUNNER_TOOL_CACHE'] = toolDir
26-
process.env['RUNNER_TEMP'] = tempDir
26+
process.env.RUNNER_TOOL_CACHE = path.join(tempDir, 'tools')
27+
process.env.RUNNER_TEMP = path.join(tempDir, 'temp')
2728

2829
describe('setup-edgedb', () => {
29-
let inputs = {} as any
30-
let inSpy: jest.SpyInstance
31-
let inBooleanSpy: jest.SpyInstance
32-
let cnSpy: jest.SpyInstance
33-
let logSpy: jest.SpyInstance
34-
let dbgSpy: jest.SpyInstance
35-
let warningSpy: jest.SpyInstance
36-
let dlSpy: jest.SpyInstance
37-
let findSpy: jest.SpyInstance
38-
let cacheSpy: jest.SpyInstance
39-
let execSpy: jest.SpyInstance
40-
41-
beforeEach(() => {
42-
// @actions/core
30+
let inputs: Record<string, string | boolean> = {}
31+
let core: SpiedModule<typeof coreType>
32+
let exec: SpiedModule<typeof execType>
33+
let tc: SpiedModule<typeof tcType>
34+
let main: typeof mainType
35+
36+
beforeAll(async () => {
37+
core = await spyOnModule<typeof coreType>('@actions/core')
38+
tc = await spyOnModule<typeof tcType>('@actions/tool-cache')
39+
exec = await spyOnModule<typeof execType>('@actions/exec')
40+
// After mocks have been set up
41+
main = await import('../src/main')
42+
})
43+
44+
beforeEach(async () => {
45+
// eslint-disable-next-line no-console
4346
console.log('::stop-commands::stoptoken')
4447
process.env['GITHUB_PATH'] = ''
4548
inputs = {
4649
'server-dsn': false
4750
}
48-
inSpy = jest.spyOn(core, 'getInput')
49-
inSpy.mockImplementation(name => inputs[name] || '')
50-
inBooleanSpy = jest.spyOn(core, 'getBooleanInput')
51-
inBooleanSpy.mockImplementation(name => inputs[name])
52-
53-
// @actions/tool-cache
54-
dlSpy = jest.spyOn(tc, 'downloadTool')
55-
findSpy = jest.spyOn(tc, 'find')
56-
cacheSpy = jest.spyOn(tc, 'cacheFile')
57-
58-
// @actions/exec
59-
execSpy = jest.spyOn(exec, 'exec')
60-
61-
// writes
62-
cnSpy = jest.spyOn(process.stdout, 'write')
63-
logSpy = jest.spyOn(core, 'info')
64-
dbgSpy = jest.spyOn(core, 'debug')
65-
warningSpy = jest.spyOn(core, 'warning')
66-
cnSpy.mockImplementation(line => {
67-
// uncomment to debug
68-
process.stderr.write('write:' + line + '\n')
69-
})
70-
logSpy.mockImplementation(line => {
51+
52+
core.getInput.mockImplementation(name => String(inputs[name] || ''))
53+
core.getBooleanInput.mockImplementation(name => Boolean(inputs[name]))
54+
55+
core.info.mockImplementation(line => {
7156
// uncomment to debug
72-
process.stderr.write('log:' + line + '\n')
57+
process.stderr.write(`log:${line}\n`)
7358
})
74-
dbgSpy.mockImplementation(msg => {
59+
core.debug.mockImplementation(msg => {
7560
// uncomment to see debug output
76-
process.stderr.write(msg + '\n')
61+
process.stderr.write(`${msg}\n`)
7762
})
7863
})
7964

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

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

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

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

102-
dlSpy.mockImplementation(async () => tmp)
87+
tc.downloadTool.mockImplementation(async () => tmp)
10388

104-
findSpy.mockImplementation(() => '')
89+
tc.find.mockImplementation(() => '')
10590

106-
const cliPath = path.normalize('/cache/edgedb/1.0.0-rc.2')
107-
cacheSpy.mockImplementation(async () => cliPath)
91+
const cliPath = path.normalize('/cache/edgedb/3.4.0')
92+
tc.cacheFile.mockImplementation(async () => cliPath)
10893

10994
await main.run()
11095

11196
fs.unlinkSync(tmp)
11297
fs.rmdirSync(tmpdir)
11398

114-
expect(dlSpy).toHaveBeenCalled()
115-
expect(logSpy).toHaveBeenCalledWith(
99+
expect(tc.downloadTool).toHaveBeenCalled()
100+
expect(core.info).toHaveBeenCalledWith(
116101
expect.stringMatching(
117102
new RegExp(
118-
`Downloading edgedb-cli ${expectedVer} - ${os.arch} from ${expectedUrl}`
103+
`Downloading edgedb-cli ${expectedVer} - ${os.arch()} from ${expectedUrl}`
119104
)
120105
)
121106
)
122-
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${cliPath}${os.EOL}`)
107+
expect(core.addPath).toHaveBeenCalledWith(cliPath)
123108
})
124109

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

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

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

143-
dlSpy.mockImplementation(async () => tmp)
128+
tc.downloadTool.mockImplementation(async () => tmp)
144129

145-
findSpy.mockImplementation(() => '')
130+
tc.find.mockImplementation(() => '')
146131

147-
execSpy.mockImplementation(async (cmd, args, opts: ExecOptions) => {
148-
if (args[0] === 'server' && args[1] === 'install') {
132+
exec.exec.mockImplementation(async (cmd, args, opts) => {
133+
if (args && args[0] === 'server' && args[1] === 'install') {
149134
return 0
150135
} else if (
136+
args &&
151137
args[0] === 'server' &&
152138
args[1] === 'info' &&
153139
args[2] === '--bin-path'
@@ -161,24 +147,24 @@ describe('setup-edgedb', () => {
161147
}
162148
})
163149

164-
const cliPath = path.normalize('/cache/edgedb/1.0.0-rc.2')
165-
cacheSpy.mockImplementation(async () => cliPath)
150+
const cliPath = path.normalize('/cache/edgedb/3.4.0')
151+
tc.cacheFile.mockImplementation(async () => cliPath)
166152
const serverPath = path.dirname(tmp)
167153

168154
await main.run()
169155

170156
fs.unlinkSync(tmp)
171157
fs.rmdirSync(tmpdir)
172158

173-
expect(dlSpy).toHaveBeenCalled()
174-
expect(logSpy).toHaveBeenCalledWith(
159+
expect(tc.downloadTool).toHaveBeenCalled()
160+
expect(core.info).toHaveBeenCalledWith(
175161
expect.stringMatching(
176162
new RegExp(
177-
`Downloading edgedb-cli ${expectedVer} - ${os.arch} from ${expectedUrl}`
163+
`Downloading edgedb-cli ${expectedVer} - ${os.arch()} from ${expectedUrl}`
178164
)
179165
)
180166
)
181-
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${serverPath}${os.EOL}`)
182-
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${cliPath}${os.EOL}`)
167+
expect(core.addPath).toHaveBeenCalledWith(serverPath)
168+
expect(core.addPath).toHaveBeenCalledWith(cliPath)
183169
})
184170
})

__tests__/spy-on-module.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {jest} from '@jest/globals'
2+
import {FunctionLike} from 'jest-mock'
3+
4+
export type SpiedModule<T extends object> = {
5+
[K in keyof T]: T[K] extends FunctionLike
6+
? jest.SpiedFunction<T[K]> & T[K]
7+
: T[K]
8+
}
9+
10+
export const spyOnModule = async <T extends object>(
11+
moduleName: string
12+
): Promise<SpiedModule<T>> => {
13+
const actual = await import(moduleName)
14+
const props = Object.getOwnPropertyNames(actual)
15+
jest.unstable_mockModule(moduleName, () =>
16+
Object.fromEntries(
17+
props.map(key => {
18+
let value = actual[key]
19+
if (typeof value === 'function') {
20+
value = jest.fn(value)
21+
}
22+
return [key, value]
23+
})
24+
)
25+
)
26+
return await import(moduleName)
27+
}

__tests__/ver.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as main from '../src/main'
2+
import {expect, describe, it} from '@jest/globals'
23

34
describe('setup-edgedb', () => {
45
it('Sorts versions correctly', async () => {
5-
let versionMap = new Map([
6+
const versionMap = new Map([
67
['1.0.0-beta.2+d20210806.g803b254e6', 'foo'],
78
['1.0.0-beta.2+d20210808.g121de78de', 'baz'],
89
['1.0.0-beta.2+d20210807.gba2c70f52', 'bar'],

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ inputs:
1616
description: >
1717
Version of EdgeDB server to install, or "stable" for the latest
1818
stable release, or "nightly" for the latest nightly build,
19-
or "none" to skip installaion. Defaults to "stable".
19+
or "none" to skip installation. Defaults to "stable".
2020
default: 'stable'
2121
instance-name:
2222
required: false
@@ -38,5 +38,5 @@ inputs:
3838
If set, specifies the directory with edgedb.toml project manifest.
3939
default: ''
4040
runs:
41-
using: 'node12'
42-
main: 'dist/index.js'
41+
using: 'node20'
42+
main: 'dist/index.cjs'

0 commit comments

Comments
 (0)