Skip to content

Commit 562e249

Browse files
committed
fix: exiting after completion
Signed-off-by: Sam Gammon <[email protected]>
1 parent 9a9d261 commit 562e249

File tree

7 files changed

+44
-25
lines changed

7 files changed

+44
-25
lines changed

__tests__/index.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import * as main from '../src/main'
22
import { setupCoreMocks } from './utils'
33

44
const { clearMocks, resetState } = setupCoreMocks()
5-
const runMock = jest.spyOn(main, 'entry').mockImplementation(() => Promise.resolve())
6-
const cleanupMock = jest.spyOn(main, 'cleanup').mockImplementation(() => Promise.resolve())
5+
const runMock = jest
6+
.spyOn(main, 'entry')
7+
.mockImplementation(() => Promise.resolve())
8+
const cleanupMock = jest
9+
.spyOn(main, 'cleanup')
10+
.mockImplementation(() => Promise.resolve())
711

812
describe('index', () => {
913
afterEach(() => {

__tests__/main.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { setupCoreMocks } from './utils'
22
import * as main from '../src/main'
33
import { ActionOutputName } from '../src/outputs'
44

5-
const { setupMocks, clearMocks, resetState, errorMock, getInputMock, setFailedMock, setOutputMock } = setupCoreMocks()
5+
const {
6+
setupMocks,
7+
clearMocks,
8+
resetState,
9+
errorMock,
10+
getInputMock,
11+
setFailedMock,
12+
setOutputMock
13+
} = setupCoreMocks()
614
const runMock = jest.spyOn(main, 'entry')
715

816
describe('action entry', () => {

__tests__/utils.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,30 @@ export function resetState() {
7575
}
7676

7777
export function setupCoreMocks(): {
78-
debugMock: jest.SpyInstance,
79-
errorMock: jest.SpyInstance,
80-
getInputMock: jest.SpyInstance,
81-
setFailedMock: jest.SpyInstance,
82-
setOutputMock: jest.SpyInstance,
83-
getJsonMock: jest.SpyInstance,
84-
getOctokitMock: jest.SpyInstance,
85-
execMock: jest.SpyInstance,
86-
clearMocks: () => void,
87-
setupMocks: () => void,
88-
resetState: () => void,
78+
debugMock: jest.SpyInstance
79+
errorMock: jest.SpyInstance
80+
getInputMock: jest.SpyInstance
81+
setFailedMock: jest.SpyInstance
82+
setOutputMock: jest.SpyInstance
83+
getJsonMock: jest.SpyInstance
84+
getOctokitMock: jest.SpyInstance
85+
execMock: jest.SpyInstance
86+
clearMocks: () => void
87+
setupMocks: () => void
88+
resetState: () => void
8989
} {
9090
let debugMock: jest.SpyInstance = jest.spyOn(core, 'debug')
9191
let errorMock: jest.SpyInstance = jest.spyOn(core, 'error')
9292
let getInputMock: jest.SpyInstance = jest.spyOn(core, 'getInput')
9393
let setFailedMock: jest.SpyInstance = jest.spyOn(core, 'setFailed')
9494
let setOutputMock: jest.SpyInstance = jest.spyOn(core, 'setOutput')
9595
let execMock: jest.SpyInstance = jest.spyOn(exec, 'exec')
96-
let getOctokitMock: jest.SpyInstance = jest.spyOn(github, 'getOctokit').mockImplementation()
97-
let getJsonMock: jest.SpyInstance = jest.spyOn(httpClient, 'getJson').mockImplementation()
96+
let getOctokitMock: jest.SpyInstance = jest
97+
.spyOn(github, 'getOctokit')
98+
.mockImplementation()
99+
let getJsonMock: jest.SpyInstance = jest
100+
.spyOn(httpClient, 'getJson')
101+
.mockImplementation()
98102

99103
return {
100104
debugMock,
@@ -118,6 +122,6 @@ export function setupCoreMocks(): {
118122
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
119123
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
120124
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
121-
},
125+
}
122126
}
123127
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build": "pnpm run bundle",
2828
"release": "pnpm run build && pnpm run sentry:sourcemaps",
2929
"bundle": "pnpm run format:write && pnpm run package",
30-
"ci-test": "jest",
30+
"ci-test": "jest --forceExit --coverage",
3131
"clean": "shx rm -fr dist src/gen",
3232
"gen": "test -d src/gen || buf generate --include-imports",
3333
"coverage": "make-coverage-badge --output-path ./badges/coverage.svg",
@@ -38,7 +38,8 @@
3838
"package:main": "ncc build src/index.ts --license licenses.txt --minify --source-map",
3939
"package:cleanup": "ncc build src/cleanup.ts -o dist/cleanup --minify --source-map",
4040
"package:watch": "pnpm run package -- --watch",
41-
"test": "jest",
41+
"test": "jest --runInBand --forceExit --no-watchman --coverage",
42+
"test:debug": "jest --runInBand --detectOpenHandles",
4243
"all": "pnpm run format:write && pnpm run lint && pnpm run test && pnpm run coverage && pnpm run package",
4344
"commitlint": "commitlint --edit",
4445
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org elide --project buildless-setup ./dist && sentry-cli sourcemaps upload --org elide --project buildless-setup ./dist"

src/diagnostics.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ export async function error(err: Error | unknown, fatal = true): Promise<void> {
218218
/**
219219
* Exit hook for making sure Sentry finishes reporting.
220220
*/
221-
export async function onExit(): Promise<void> {
221+
export async function onExit(exit: boolean): Promise<void> {
222222
core.debug('Closing resources')
223223
try {
224224
httpClient.dispose()
225225
} catch (err) {
226226
// Ignore.
227227
}
228-
process.exit(0)
228+
if (exit) {
229+
process.exit(0)
230+
}
229231
}

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export async function install(
484484
core.setOutput(ActionOutputName.PATH, outputs.path)
485485
core.setOutput(ActionOutputName.VERSION, outputs.version)
486486
}
487-
core.info(`✅ Buildless installed at version ${outputs.version}.`)
487+
core.info(`✅ Buildless installed at version '${outputs.version}'.`)
488488
if (agentEnabled) {
489489
if (agentManaged) {
490490
core.info(`✅ Buildless Agent installed and running.`)
@@ -586,7 +586,7 @@ export async function entry(options?: Partial<Options>): Promise<void> {
586586

587587
try {
588588
await install(options || {}, true)
589-
await onExit()
589+
await onExit(process.env.RUNNER_ENVIRONMENT === 'github-hosted')
590590
} catch (err) {
591591
core.warning(
592592
'Buildless failed to install; this build may not be accelerated. Please see CI logs for more information.'
@@ -605,7 +605,7 @@ export async function cleanup(options?: Partial<Options>): Promise<void> {
605605
try {
606606
await postExecute(options)
607607
core.info(`Thanks for using Buildless. 🎉`)
608-
await onExit()
608+
await onExit(process.env.RUNNER_ENVIRONMENT === 'github-hosted')
609609
} catch (err) {
610610
core.notice(
611611
'Cleanup stage for the Buildless action failed. Please see CI logs for more information.'

src/releases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ export async function downloadRelease(
446446
// resolve applicable version
447447
let versionInfo: BuildlessVersionInfo
448448
if (options.version === 'latest') {
449-
core.info('Resolving latest version via GitHub API')
449+
core.info('Resolving latest version...')
450450
versionInfo = await resolveLatestVersion(options.token)
451451
} else {
452452
/* istanbul ignore next */

0 commit comments

Comments
 (0)