Skip to content

Commit

Permalink
refactor: replace prettier with biome
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Nov 24, 2024
1 parent 27af3fa commit 0b0505b
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: "Install dependencies"
run: pnpm install

- name: "Check format"
run: pnpm run format:check
- name: "Run Biome"
run: pnpm biome ci

build:
name: "Build"
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"editor.linkedEditing": true,
"editor.renderWhitespace": "trailing",
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"files.associations": {
"**/.github/workflows/*.yaml": "github-actions-workflow"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![License](https://img.shields.io/github/license/jcwillox/install-tool-action?style=flat-square)](https://github.com/jcwillox/install-tool-action/blob/main/LICENSE)
[![Version](https://img.shields.io/github/v/release/jcwillox/install-tool-action?style=flat-square)](https://github.com/jcwillox/install-tool-action/releases)
[![Size](https://img.shields.io/github/size/jcwillox/install-tool-action/dist%2Findex.js?branch=main&style=flat-square)](dist/index.js)
[![Code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Code style](https://img.shields.io/badge/code_style-biome-60a5fa?style=flat-square)](https://biomejs.dev)

Install any tool or binary with full cache, dynamic latest version, easy to configure and has presets.

Expand Down
25 changes: 25 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"formatter": {
"enabled": true,
"ignore": ["**/pnpm-lock.yaml", "**/dist/**/*"],
"useEditorconfig": true
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "warn",
"noUnusedVariables": "warn"
},
"style": {
"noParameterAssign": "off"
}
},
"ignore": ["**/dist/**/*"]
}
}
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@
"license": "MIT",
"private": true,
"repository": "jcwillox/install-tool-action",
"keywords": [
"actions",
"install",
"setup",
"tool"
],
"keywords": ["actions", "install", "setup", "tool"],
"scripts": {
"dev": "pnpm build --watch",
"build": "tsup src/index.ts --treeshake --minify --clean",
"typecheck": "tsc",
"lint": "eslint . --cache --max-warnings=0 --ext js,cjs,mjs,jsx,ts,tsx",
"lint:fix": "pnpm run lint --fix",
"format": "prettier --cache --write .",
"format:check": "prettier --cache --check ."
"lint": "biome lint",
"lint:fix": "biome lint -w",
"format": "biome format --write",
"format:check": "biome format"
},
"devDependencies": {
"@actions/core": "1.11.1",
"@actions/exec": "1.1.1",
"@actions/http-client": "2.2.3",
"@actions/tool-cache": "2.0.1",
"@biomejs/biome": "1.9.4",
"@types/node": "22.8.2",
"prettier": "3.3.3",
"radash": "12.1.0",
"tsup": "8.3.5",
"typescript": "5.6.3",
Expand Down
101 changes: 91 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from "node:path";
import * as core from "@actions/core";
import { shake, template } from "radash";
import { downloadTool, getVersion } from "./install";
import { Config } from "./types";
import type { Config } from "./types";
import presets from "./presets";

export async function main() {
Expand All @@ -31,7 +31,7 @@ export async function main() {
cache: core.getBooleanInput("cache"),
};

core.debug("loaded config: " + JSON.stringify(config));
core.debug(`loaded config: ${JSON.stringify(config)}`);

// if preset is set, load preset config
if (config.preset) {
Expand All @@ -50,10 +50,9 @@ export async function main() {
if (!config.versionUrl && !config.versionPath && config.repo)
config.versionPath = "tag_name";
if (!config.versionUrl && config.repo)
config.versionUrl =
"https://api.github.com/repos/" + config.repo + "/releases/latest";
config.versionUrl = `https://api.github.com/repos/${config.repo}/releases/latest`;

core.debug("resolved config: " + JSON.stringify(config));
core.debug(`resolved config: ${JSON.stringify(config)}`);

if (!config.downloadUrl) {
throw new Error("Download URL missing");
Expand All @@ -64,7 +63,7 @@ export async function main() {
const version = await getVersion(config);
if (!version) throw new Error("Version not found");
config.version = version;
core.debug("resolved version: " + config.version);
core.debug(`resolved version: ${config.version}`);
}

// template download url
Expand All @@ -73,22 +72,21 @@ export async function main() {
...templateArgs,
});
if (config.downloadUrl.startsWith("/") && config.repo)
config.downloadUrl =
"https://github.com/" + config.repo + config.downloadUrl;
config.downloadUrl = `https://github.com/${config.repo}${config.downloadUrl}`;

core.debug("templated download url: " + config.downloadUrl);
core.debug(`templated download url: ${config.downloadUrl}`);

// download or pull from cache
const toolPath = await downloadTool(config);

if (config.binPath != "") {
if (config.binPath !== "") {
config.binPath = template(config.binPath, {
...config,
...templateArgs,
});
}

core.debug("cached path: " + toolPath);
core.debug(`cached path: ${toolPath}`);
core.addPath(path.join(toolPath, config.binPath));
core.info(`Successfully installed version ${config.version}`);

Expand Down
26 changes: 13 additions & 13 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "./types";
import type { Config } from "./types";
import { get } from "radash";
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
Expand Down Expand Up @@ -47,20 +47,20 @@ export async function downloadTool(config: Config) {
}

// check cache
if (config.cache) {
const toolPath = tc.find(toolName!, config.version);
if (config.cache && toolName) {
const toolPath = tc.find(toolName, config.version);
if (toolPath) {
core.debug("cache hit: " + toolName + "@" + config.version);
core.debug(`cache hit: ${toolName}@${config.version}`);
return toolPath;
}
core.debug("cache miss: " + toolName + "@" + config.version);
const versions = tc.findAllVersions(toolName!).join(", ");
if (versions) core.debug("available versions: " + versions);
core.debug(`cache miss: ${toolName}@${config.version}`);
const versions = tc.findAllVersions(toolName).join(", ");
if (versions) core.debug(`available versions: ${versions}`);
}

// download file
let downloadPath = await tc.downloadTool(config.downloadUrl);
core.debug("downloaded path: " + downloadPath);
const downloadPath = await tc.downloadTool(config.downloadUrl);
core.debug(`downloaded path: ${downloadPath}`);

// handle extracting downloaded file
let extractedPath: string | undefined;
Expand All @@ -73,20 +73,20 @@ export async function downloadTool(config: Config) {
} else if (config.downloadUrl.endsWith(".pkg")) {
extractedPath = await tc.extractXar(downloadPath);
}
core.debug("extracted path: " + extractedPath);
core.debug(`extracted path: ${extractedPath}`);

// ensure binaries are executable
if (!extractedPath && process.platform !== "win32")
await exec("chmod", ["+x", downloadPath]);

// cache downloaded or extracted path
if (config.cache)
if (config.cache && toolName)
return extractedPath
? await tc.cacheDir(extractedPath, toolName!, config.version)
? await tc.cacheDir(extractedPath, toolName, config.version)
: await tc.cacheFile(
downloadPath,
config.downloadName || path.basename(config.downloadUrl),
toolName!,
toolName,
config.version,
);
return extractedPath || downloadPath;
Expand Down
2 changes: 1 addition & 1 deletion src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "../types";
import type { Config } from "../types";

const presets: Record<string, Partial<Config>> = {
"infisical-cli": {
Expand Down

0 comments on commit 0b0505b

Please sign in to comment.