mirror of
https://github.com/supabase/setup-cli.git
synced 2025-12-08 16:16:25 +00:00
feat: support downloading the latest version automatically (#70)
This commit is contained in:
@@ -44,7 +44,7 @@ Since Supabase CLI relies on Docker Engine API, additional setup may be required
|
|||||||
|
|
||||||
The actions supports the following inputs:
|
The actions supports the following inputs:
|
||||||
|
|
||||||
- `version`: The version of `supabase` to install, defaulting to `1.0.0`
|
- `version`: The version of `supabase` to install, defaulting to `1.0.0`. You can also specify `latest` to use the latest version.
|
||||||
|
|
||||||
## Advanced Usage
|
## Advanced Usage
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ import * as path from 'path'
|
|||||||
import {expect, test} from '@jest/globals'
|
import {expect, test} from '@jest/globals'
|
||||||
|
|
||||||
test('gets download url to binary', async () => {
|
test('gets download url to binary', async () => {
|
||||||
const url = getDownloadUrl('0.1.0')
|
const url = await getDownloadUrl('0.1.0')
|
||||||
expect(url).toContain(
|
expect(url).toContain(
|
||||||
'https://github.com/supabase/cli/releases/download/v0.1.0/'
|
'https://github.com/supabase/cli/releases/download/v0.1.0/'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('gets download url to binary with "latest" version', async () => {
|
||||||
|
const url = await getDownloadUrl('latest')
|
||||||
|
expect(url).toMatch(
|
||||||
|
/^https:\/\/github.com\/supabase\/cli\/releases\/download\/v[0-9]+\.[0-9]+\.[0-9]+\/supabase_[0-9]+\.[0-9]+\.[0-9]+/
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
// shows how the runner will run a javascript action with env / stdout protocol
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
test('test runs', () => {
|
test('test runs', () => {
|
||||||
process.env['RUNNER_TEMP'] = os.tmpdir()
|
process.env['RUNNER_TEMP'] = os.tmpdir()
|
||||||
|
|||||||
57
dist/index.js
generated
vendored
57
dist/index.js
generated
vendored
@@ -48,7 +48,7 @@ function run() {
|
|||||||
// Get version of tool to be installed
|
// Get version of tool to be installed
|
||||||
const version = core.getInput('version');
|
const version = core.getInput('version');
|
||||||
// Download the specific version of the tool, e.g. as a tarball/zipball
|
// Download the specific version of the tool, e.g. as a tarball/zipball
|
||||||
const download = (0, utils_1.getDownloadUrl)(version);
|
const download = yield (0, utils_1.getDownloadUrl)(version);
|
||||||
const pathToTarball = yield tc.downloadTool(download);
|
const pathToTarball = yield tc.downloadTool(download);
|
||||||
// Extract the tarball/zipball onto host runner
|
// Extract the tarball/zipball onto host runner
|
||||||
const pathToCLI = yield tc.extractTar(pathToTarball);
|
const pathToCLI = yield tc.extractTar(pathToTarball);
|
||||||
@@ -71,12 +71,45 @@ run();
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getDownloadUrl = void 0;
|
exports.getDownloadUrl = void 0;
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
|
const httpm = __importStar(__nccwpck_require__(6255));
|
||||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||||
// return value in [amd64, arm64, arm]
|
// return value in [amd64, arm64, arm]
|
||||||
const mapArch = (arch) => {
|
const mapArch = (arch) => {
|
||||||
@@ -93,13 +126,27 @@ const mapOS = (platform) => {
|
|||||||
};
|
};
|
||||||
return mappings[platform] || platform;
|
return mappings[platform] || platform;
|
||||||
};
|
};
|
||||||
const getDownloadUrl = (version) => {
|
const getDownloadUrl = (version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const platform = mapOS(os_1.default.platform());
|
const platform = mapOS(os_1.default.platform());
|
||||||
const arch = mapArch(os_1.default.arch());
|
const arch = mapArch(os_1.default.arch());
|
||||||
const filename = `supabase_${version}_${platform}_${arch}`;
|
const resolvedVersion = yield resolveVersion(version);
|
||||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}.tar.gz`;
|
const filename = `supabase_${resolvedVersion}_${platform}_${arch}`;
|
||||||
};
|
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`;
|
||||||
|
});
|
||||||
exports.getDownloadUrl = getDownloadUrl;
|
exports.getDownloadUrl = getDownloadUrl;
|
||||||
|
const resolveVersion = (version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var _a;
|
||||||
|
if (version !== 'latest') {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
const http = new httpm.HttpClient('setup-cli');
|
||||||
|
const url = 'https://api.github.com/repos/supabase/cli/releases/latest';
|
||||||
|
const tag = (_a = (yield http.getJson(url)).result) === null || _a === void 0 ? void 0 : _a.tag_name;
|
||||||
|
if (!tag) {
|
||||||
|
throw new Error('Cannot fetch tag info');
|
||||||
|
}
|
||||||
|
return tag.substring(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
1
package-lock.json
generated
1
package-lock.json
generated
@@ -10,6 +10,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/tool-cache": "^2.0.1"
|
"@actions/tool-cache": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/tool-cache": "^2.0.1"
|
"@actions/tool-cache": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ async function run(): Promise<void> {
|
|||||||
const version = core.getInput('version')
|
const version = core.getInput('version')
|
||||||
|
|
||||||
// Download the specific version of the tool, e.g. as a tarball/zipball
|
// Download the specific version of the tool, e.g. as a tarball/zipball
|
||||||
const download = getDownloadUrl(version)
|
const download = await getDownloadUrl(version)
|
||||||
const pathToTarball = await tc.downloadTool(download)
|
const pathToTarball = await tc.downloadTool(download)
|
||||||
|
|
||||||
// Extract the tarball/zipball onto host runner
|
// Extract the tarball/zipball onto host runner
|
||||||
|
|||||||
28
src/utils.ts
28
src/utils.ts
@@ -1,4 +1,9 @@
|
|||||||
import os from 'os'
|
import os from 'os'
|
||||||
|
import * as httpm from '@actions/http-client'
|
||||||
|
|
||||||
|
interface GitHubTag {
|
||||||
|
tag_name: string
|
||||||
|
}
|
||||||
|
|
||||||
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
// arch in [arm, arm64, x64...] (https://nodejs.org/docs/latest-v16.x/api/os.html#osarch)
|
||||||
// return value in [amd64, arm64, arm]
|
// return value in [amd64, arm64, arm]
|
||||||
@@ -18,9 +23,26 @@ const mapOS = (platform: string): string => {
|
|||||||
return mappings[platform] || platform
|
return mappings[platform] || platform
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDownloadUrl = (version: string): string => {
|
export const getDownloadUrl = async (version: string): Promise<string> => {
|
||||||
const platform = mapOS(os.platform())
|
const platform = mapOS(os.platform())
|
||||||
const arch = mapArch(os.arch())
|
const arch = mapArch(os.arch())
|
||||||
const filename = `supabase_${version}_${platform}_${arch}`
|
const resolvedVersion = await resolveVersion(version)
|
||||||
return `https://github.com/supabase/cli/releases/download/v${version}/${filename}.tar.gz`
|
const filename = `supabase_${resolvedVersion}_${platform}_${arch}`
|
||||||
|
|
||||||
|
return `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}.tar.gz`
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveVersion = async (version: string): Promise<string> => {
|
||||||
|
if (version !== 'latest') {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
const http: httpm.HttpClient = new httpm.HttpClient('setup-cli')
|
||||||
|
const url = 'https://api.github.com/repos/supabase/cli/releases/latest'
|
||||||
|
const tag = (await http.getJson<GitHubTag>(url)).result?.tag_name
|
||||||
|
if (!tag) {
|
||||||
|
throw new Error('Cannot fetch tag info')
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag.substring(1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user