chore: migrate to esm (#334)

* chore: update unit tests

* fix: follow latest action template

* chore: add licenses and workflows

* chore: remove bloat

* chore: fix linter
This commit is contained in:
Han Qiao
2025-07-23 15:04:43 +08:00
committed by GitHub
parent 6c3c96bfbe
commit b60b5899c7
48 changed files with 40108 additions and 32534 deletions

View File

@@ -1,12 +1,13 @@
import {getDownloadUrl} from '../src/utils'
import {CLI_CONFIG_REGISTRY} from '../src/main'
import { getDownloadUrl } from '../src/utils'
import { CLI_CONFIG_REGISTRY } from '../src/main'
import * as os from 'os'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import * as fs from 'fs'
import * as yaml from 'js-yaml'
import {expect, test} from '@jest/globals'
import * as url from 'url'
import { expect, test } from '@jest/globals'
test('gets download url to binary', async () => {
const url = await getDownloadUrl('1.28.0')
@@ -37,22 +38,24 @@ test('gets download url to latest version', async () => {
})
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['RUNNER_TEMP'] = os.tmpdir()
const config = path.join(__dirname, '..', 'action.yml')
const action: any = yaml.load(fs.readFileSync(config, 'utf8'))
process.env['INPUT_VERSION'] = action.inputs.version.default
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
env: process.env
test('runs main action', () => {
const { env, execPath } = process
const repo = path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))
const config = path.join(repo, 'action.yml')
const action = yaml.load(fs.readFileSync(config, 'utf8')) as {
inputs: { version: { default: string } }
}
const stdout = cp.execFileSync(np, [ip], options).toString()
console.log(stdout)
// FIXME: This has been broken for a while. Using the CLI_CONFIG_REGISTRY
// variable runs `run()` in src/main.ts which triggers the error. Couldn't
// figure out the source of the error.
// expect
// .stringContaining(`::set-env name=${CLI_CONFIG_REGISTRY}::`)
// .asymmetricMatch(stdout)
const ip = path.join(repo, 'dist', 'index.js')
const stdout = cp
.execFileSync(execPath, [ip], {
env: {
...env,
RUNNER_TEMP: os.tmpdir(),
INPUT_VERSION: action.inputs.version.default
}
})
.toString()
expect
.stringContaining(`::set-env name=${CLI_CONFIG_REGISTRY}::`)
.asymmetricMatch(stdout)
})