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
This commit is contained in:
Han Qiao
2023-01-30 18:38:33 +08:00
committed by GitHub
parent d7405cc5a0
commit 9a74081b27
6 changed files with 47 additions and 8 deletions

View File

@@ -1,8 +1,11 @@
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'
test('gets download url to binary', async () => {
@@ -36,11 +39,17 @@ 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()
process.env['INPUT_VERSION'] = '1.0.0'
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
}
console.log(cp.execFileSync(np, [ip], options).toString())
const stdout = cp.execFileSync(np, [ip], options).toString()
console.log(stdout)
expect
.stringContaining(`::set-env name=${CLI_CONFIG_REGISTRY}::`)
.asymmetricMatch(stdout)
})

18
dist/index.js generated vendored
View File

@@ -42,10 +42,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CLI_CONFIG_REGISTRY = void 0;
const core = __importStar(__nccwpck_require__(2186));
const tc = __importStar(__nccwpck_require__(7784));
const lt_1 = __importDefault(__nccwpck_require__(194));
const gte_1 = __importDefault(__nccwpck_require__(5522));
const utils_1 = __nccwpck_require__(918);
exports.CLI_CONFIG_REGISTRY = 'SUPABASE_INTERNAL_IMAGE_REGISTRY';
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
@@ -59,8 +61,8 @@ function run() {
// Expose the tool by adding it to the PATH
core.addPath(pathToCLI);
// Use GHCR mirror by default
if (version.toLowerCase() === 'latest' || (0, lt_1.default)(version, '1.28.0')) {
core.exportVariable('SUPABASE_INTERNAL_IMAGE_REGISTRY', 'ghcr.io');
if (version.toLowerCase() === 'latest' || (0, gte_1.default)(version, '1.28.0')) {
core.exportVariable(exports.CLI_CONFIG_REGISTRY, 'ghcr.io');
}
}
catch (error) {
@@ -6606,6 +6608,16 @@ const compare = (a, b, loose) =>
module.exports = compare
/***/ }),
/***/ 5522:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
const compare = __nccwpck_require__(4309)
const gte = (a, b, loose) => compare(a, b, loose) >= 0
module.exports = gte
/***/ }),
/***/ 194:

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View File

@@ -14,6 +14,7 @@
"semver": "^7.3.8"
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/node": "^16.11.47",
"@types/semver": "^7.3.13",
"@typescript-eslint/parser": "^5.49.0",
@@ -22,6 +23,7 @@
"eslint-plugin-github": "^4.6.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^28.1.3",
"js-yaml": "^4.1.0",
"prettier": "2.8.3",
"ts-jest": "^28.0.8",
"typescript": "^4.8.4"
@@ -1587,6 +1589,12 @@
"@types/istanbul-lib-report": "*"
}
},
"node_modules/@types/js-yaml": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.5.tgz",
"integrity": "sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==",
"dev": true
},
"node_modules/@types/json-schema": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@@ -7938,6 +7946,12 @@
"@types/istanbul-lib-report": "*"
}
},
"@types/js-yaml": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.5.tgz",
"integrity": "sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==",
"dev": true
},
"@types/json-schema": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",

View File

@@ -30,6 +30,7 @@
"semver": "^7.3.8"
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/node": "^16.11.47",
"@types/semver": "^7.3.13",
"@typescript-eslint/parser": "^5.49.0",
@@ -38,6 +39,7 @@
"eslint-plugin-github": "^4.6.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^28.1.3",
"js-yaml": "^4.1.0",
"prettier": "2.8.3",
"ts-jest": "^28.0.8",
"typescript": "^4.8.4"

View File

@@ -1,8 +1,10 @@
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import gte from 'semver/functions/lt'
import gte from 'semver/functions/gte'
import {getDownloadUrl} from './utils'
export const CLI_CONFIG_REGISTRY = 'SUPABASE_INTERNAL_IMAGE_REGISTRY'
async function run(): Promise<void> {
try {
// Get version of tool to be installed
@@ -20,7 +22,7 @@ async function run(): Promise<void> {
// Use GHCR mirror by default
if (version.toLowerCase() === 'latest' || gte(version, '1.28.0')) {
core.exportVariable('SUPABASE_INTERNAL_IMAGE_REGISTRY', 'ghcr.io')
core.exportVariable(CLI_CONFIG_REGISTRY, 'ghcr.io')
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)