Skip to content

Commit 9a74081

Browse files
authored
fix: inverted conditional for semver check (#129)
* fix: inverted conditional for semver check * chore: add tests for default version * chore: parse default action input * chore: update binary files * chore: fix unit test
1 parent d7405cc commit 9a74081

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

__tests__/main.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {getDownloadUrl} from '../src/utils'
2+
import {CLI_CONFIG_REGISTRY} from '../src/main'
23
import * as os from 'os'
34
import * as process from 'process'
45
import * as cp from 'child_process'
56
import * as path from 'path'
7+
import * as fs from 'fs'
8+
import * as yaml from 'js-yaml'
69
import {expect, test} from '@jest/globals'
710

811
test('gets download url to binary', async () => {
@@ -36,11 +39,17 @@ test('gets download url to latest version', async () => {
3639
// shows how the runner will run a javascript action with env / stdout protocol
3740
test('test runs', () => {
3841
process.env['RUNNER_TEMP'] = os.tmpdir()
39-
process.env['INPUT_VERSION'] = '1.0.0'
42+
const config = path.join(__dirname, '..', 'action.yml')
43+
const action: any = yaml.load(fs.readFileSync(config, 'utf8'))
44+
process.env['INPUT_VERSION'] = action.inputs.version.default
4045
const np = process.execPath
4146
const ip = path.join(__dirname, '..', 'lib', 'main.js')
4247
const options: cp.ExecFileSyncOptions = {
4348
env: process.env
4449
}
45-
console.log(cp.execFileSync(np, [ip], options).toString())
50+
const stdout = cp.execFileSync(np, [ip], options).toString()
51+
console.log(stdout)
52+
expect
53+
.stringContaining(`::set-env name=${CLI_CONFIG_REGISTRY}::`)
54+
.asymmetricMatch(stdout)
4655
})

dist/index.js

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"semver": "^7.3.8"
3131
},
3232
"devDependencies": {
33+
"@types/js-yaml": "^4.0.5",
3334
"@types/node": "^16.11.47",
3435
"@types/semver": "^7.3.13",
3536
"@typescript-eslint/parser": "^5.49.0",
@@ -38,6 +39,7 @@
3839
"eslint-plugin-github": "^4.6.0",
3940
"eslint-plugin-jest": "^27.2.1",
4041
"jest": "^28.1.3",
42+
"js-yaml": "^4.1.0",
4143
"prettier": "2.8.3",
4244
"ts-jest": "^28.0.8",
4345
"typescript": "^4.8.4"

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as core from '@actions/core'
22
import * as tc from '@actions/tool-cache'
3-
import gte from 'semver/functions/lt'
3+
import gte from 'semver/functions/gte'
44
import {getDownloadUrl} from './utils'
55

6+
export const CLI_CONFIG_REGISTRY = 'SUPABASE_INTERNAL_IMAGE_REGISTRY'
7+
68
async function run(): Promise<void> {
79
try {
810
// Get version of tool to be installed
@@ -20,7 +22,7 @@ async function run(): Promise<void> {
2022

2123
// Use GHCR mirror by default
2224
if (version.toLowerCase() === 'latest' || gte(version, '1.28.0')) {
23-
core.exportVariable('SUPABASE_INTERNAL_IMAGE_REGISTRY', 'ghcr.io')
25+
core.exportVariable(CLI_CONFIG_REGISTRY, 'ghcr.io')
2426
}
2527
} catch (error) {
2628
if (error instanceof Error) core.setFailed(error.message)

0 commit comments

Comments
 (0)