Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "setup-kosli-cli",
"version": "1.0.0",
"description": "Sets up the Kosli CLI for GitHub Actions runners",
"type": "module",
"main": "dist/index.js",
"scripts": {
"test": "ava",
Expand Down
9 changes: 3 additions & 6 deletions src/download.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require("path");
const github = require("@actions/github");
import * as github from "@actions/github";

// Map node arch to arch in download url
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
Expand All @@ -23,13 +22,13 @@ function mapOS(os) {
return mappings[os] || os;
}

function getDownloadUrl({ version, platform, arch }) {
export function getDownloadUrl({ version, platform, arch }) {
const filename = `kosli_${version}_${mapOS(platform)}_${mapArch(arch)}`;
const extension = platform === "win32" ? "zip" : "tar.gz";
return `https://github.com/kosli-dev/cli/releases/download/v${version}/${filename}.${extension}`;
}

async function resolveVersion(version, token, octokit) {
export async function resolveVersion(version, token, octokit) {
if (version !== "latest") {
return version;
}
Expand All @@ -46,5 +45,3 @@ async function resolveVersion(version, token, octokit) {
const tag = release.data.tag_name;
return tag.startsWith("v") ? tag.slice(1) : tag;
}

module.exports = { getDownloadUrl, resolveVersion };
15 changes: 5 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const path = require("path");
const os = require("os");
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const { getDownloadUrl, resolveVersion } = require("./download");
import os from "os";
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import { getDownloadUrl, resolveVersion } from "./download.js";

async function setup() {
try {
Expand Down Expand Up @@ -32,8 +31,4 @@ async function setup() {
}
}

module.exports = setup;

if (require.main === module) {
setup();
}
setup();
4 changes: 2 additions & 2 deletions test/download.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require("ava");
const { getDownloadUrl, resolveVersion } = require("../src/download");
import test from "ava";
import { getDownloadUrl, resolveVersion } from "../src/download.js";

const baseUrl = "https://github.com/kosli-dev/cli/releases/download/";
const testCases = [
Expand Down