🐛 fix: praying

Signed-off-by: Pauline <git@ethanlibs.co>
This commit is contained in:
Pauline 2024-08-05 05:46:11 +02:00
parent 13580a0a2c
commit 3e77988443
No known key found for this signature in database
GPG key ID: 722BB181973296AE
7 changed files with 127179 additions and 121 deletions

File diff suppressed because one or more lines are too long

View file

@ -15,8 +15,10 @@
"build": "ncc build src/index.ts --minify"
},
"dependencies": {
"@actions/artifact": "^2.1.9",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0",
"@actions/http-client": "^2.2.1",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",

View file

@ -1,120 +1,94 @@
import os from 'node:os';
import { tmpdir as getTmpdir } from 'node:os';
import { promises as fs } from 'node:fs';
import process from 'node:process';
import { env, cwd as getCwd } from 'node:process';
import { Buffer } from 'node:buffer';
import { join, relative } from 'pathe';
import { rmRF } from '@actions/io';
import { exec } from '@actions/exec';
import core from '@actions/core';
import { getInput as getCoreInput, group, info } from '@actions/core';
import { installReviewdog } from './installer';
async function run(): Promise<void> {
const runnerTmpdir = process.env.RUNNER_TEMP || os.tmpdir();
const runnerTmpdir = env.RUNNER_TEMP || getTmpdir();
const tmpdir = await fs.mkdtemp(join(runnerTmpdir, 'reviewdog-'));
const getInput = <T = string>(name: string): T => getCoreInput(name) as T;
try {
const reviewdogVersion = core.getInput('reviewdog_version') || 'latest';
const toolName = core.getInput('tool_name') || 'clippy';
const clippyFlags = core.getInput('clippy_flags');
const clippyDebug = core.getInput('clippy_debug') || 'false';
const level = core.getInput('level') || 'error';
const reporter = core.getInput('reporter') || 'github-pr-check';
const filterMode = core.getInput('filter_mode') || 'added';
const failOnError = core.getInput('fail_on_error') || 'false';
const reviewdogFlags = core.getInput('reviewdog_flags');
const workdir = core.getInput('workdir') || '.';
const cwd = relative(process.env.GITHUB_WORKSPACE || process.cwd(), workdir);
const reviewdog = await core.group('installing reviewdog', async () => await installReviewdog(reviewdogVersion, tmpdir));
const reviewdogVersion = getInput('reviewdog_version') || 'latest';
const toolName = getInput('tool_name') || 'clippy';
const clippyFlags = getInput('clippy_flags');
const clippyDebug = getInput('clippy_debug') || 'false';
const level = getInput('level') || 'error';
const reporter = getInput('reporter') || 'github-pr-check';
const filterMode = getInput('filter_mode') || 'added';
const failOnError = getInput('fail_on_error') || 'false';
const reviewdogFlags = getInput('reviewdog_flags');
const workdir = getInput('workdir') || '.';
const cwd = relative(env.GITHUB_WORKSPACE || getCwd(), workdir);
const reviewdog = await group('installing reviewdog', async () => await installReviewdog(reviewdogVersion, tmpdir));
const code = await core.group(
'running clippy',
async (): Promise<number> => {
const output: string[] = [];
await exec(
'cargo',
[
'clippy',
'--color',
'never',
'-q',
'--message-format',
'json',
...parse(clippyFlags),
],
{
cwd,
ignoreReturnCode: true,
silent: clippyDebug !== 'true',
listeners: {
stdline: (line: string) => {
const content: CompilerMessage = JSON.parse(line);
const output: string[] = [];
await exec(
'cargo',
[
'clippy',
'--color',
'never',
'-q',
'--message-format',
'json',
...parse(clippyFlags),
],
{
cwd,
ignoreReturnCode: true,
silent: clippyDebug !== 'true',
listeners: {
stdline: (data) => {
const content: CompilerMessage = JSON.parse(data);
if (content.reason !== 'compiler-message') {
core.debug('ignore all but `compiler-message`');
return;
}
if (content.reason !== 'compiler-message')
return;
if (content.message.code === null) {
core.debug('message code is missing, ignore it');
return;
}
if (content.message.code === null)
return;
const span = content.message.spans[0]!;
const messageLevel = content.message.level === 'warning' ? 'w' : 'e';
const rendered = reporter === 'github-pr-review'
? ` \n<pre><code>${content.message.rendered}</code></pre>\n__END__`
: `${content.message.rendered}\n__END__`;
const ret = `${span.file_name}:${span.line_start}:${span.column_start}:${messageLevel}:${rendered}`;
output.push(ret);
},
},
},
);
const span = content.message.spans[0]!;
const messageLevel = content.message.level === 'warning' ? 'w' : 'e';
const rendered = reporter === 'github-pr-review'
? ` \n<pre><code>${content.message.rendered}</code></pre>\n__END__`
: `${content.message.rendered}\n__END__`;
const ret = `${span.file_name}:${span.line_start}:${span.column_start}:${messageLevel}:${rendered}`;
output.push(ret);
},
},
},
);
process.env.REVIEWDOG_GITHUB_API_TOKEN = core.getInput('github_token');
return await exec(
reviewdog,
[
'-efm=<pre><code>%E%f:%l:%c:%t:%m',
'-efm=%E%f:%l:%c:%t:%m',
'-efm=%Z__END__',
'-efm=%C%m</code></pre>',
'-efm=%C%m',
'-efm=%C',
env.REVIEWDOG_GITHUB_API_TOKEN = getInput('github_token');
await exec(
reviewdog,
[
'-efm=<pre><code>%E%f:%l:%c:%t:%m',
'-efm=%E%f:%l:%c:%t:%m',
'-efm=%Z__END__',
'-efm=%C%m</code></pre>',
'-efm=%C%m',
'-efm=%C',
`-name=${toolName}`,
`-reporter=${reporter}`,
`-filter-mode=${filterMode}`,
`-fail-on-error=${failOnError}`,
`-level=${level}`,
...parse(reviewdogFlags),
],
{
cwd,
input: Buffer.from(output.join('\n'), 'utf-8'),
ignoreReturnCode: true,
},
);
},
);
],
{
cwd,
input: Buffer.from(output.join('\n'), 'utf-8'),
ignoreReturnCode: true,
},
);
if (code !== 0)
throw new Error(`reviewdog exited with status code: ${code}`);
}
catch (error) {
if (error instanceof Error)
throw error;
}
finally {
try {
await rmRF(tmpdir);
}
catch (error) {
if (error instanceof Error)
core.info(`cleanup failed: ${error.message}`);
else
core.info(`cleanup failed: ${error}`);
}
}
await rmRF(tmpdir);
}
function parse(flags: string): string[] {

View file

@ -1,6 +1,5 @@
import process from 'node:process';
import { arch as getArch, platform as getPlatform } from 'node:process';
import { join } from 'pathe';
import { error } from '@actions/core';
import { Headers, HttpClient, HttpCodes } from '@actions/http-client';
import { downloadTool, extractTar } from '@actions/tool-cache';
@ -12,19 +11,19 @@ interface Release {
export async function installReviewdog(tag: string, directory: string): Promise<string> {
const version = await tagToVersion(tag, 'reviewdog', 'reviewdog');
const platform = process.platform === 'darwin' ? 'Darwin' : process.platform === 'linux' ? 'Linux' : process.platform === 'win32' ? 'Windows' : '';
const arch = process.arch === 'x64' ? 'x86_64' : process.arch === 'arm64' ? process.arch : '';
const platform = getPlatform === 'darwin' ? 'Darwin' : getPlatform === 'linux' ? 'Linux' : getPlatform === 'win32' ? 'Windows' : '';
const arch = getArch === 'x64' ? 'x86_64' : getArch === 'arm64' ? getArch : '';
if (platform === '')
throw new Error(`unsupported platform ${process.platform}!`);
throw new Error(`unsupported platform ${getPlatform}!`);
if (arch === '')
throw new Error(`unsupported architecture: ${process.arch}!`);
throw new Error(`unsupported architecture: ${getArch}!`);
const url = getUrl(version, platform, arch);
const archivePath = await downloadTool(url);
const extractedDir = await extractTar(archivePath, directory);
const executablePath = `reviewdog${process.platform === 'win32' ? '.exe' : ''}`;
const executablePath = `reviewdog${getPlatform === 'win32' ? '.exe' : ''}`;
return join(extractedDir, executablePath);
}
@ -35,7 +34,7 @@ async function tagToVersion(tag: string, owner: string, repo: string): Promise<s
const response = await client.getJson<Release>(url, headers);
if (response.statusCode !== HttpCodes.OK)
error(`${url} returned unexpected HTTP status code: ${response.statusCode}`);
throw new Error(`${url} returned unexpected HTTP status code: ${response.statusCode}`);
if (!response.result)
throw new Error(`unable to find '${tag}' - use 'latest' or see https://github.com/${owner}/${repo}/releases for details`);

File diff suppressed because one or more lines are too long

View file

@ -12,7 +12,7 @@
"bugs": "https://github.com/polyfrost/onelauncher/issues",
"sideEffects": false,
"scripts": {
"build": "ncc build src/index.ts --minify"
"build": "ncc build src/index.ts"
},
"dependencies": {
"@actions/artifact": "^2.1.9",

6
pnpm-lock.yaml generated
View file

@ -50,12 +50,18 @@ importers:
.github/actions/clippy:
dependencies:
'@actions/artifact':
specifier: ^2.1.9
version: 2.1.9
'@actions/core':
specifier: ^1.10.1
version: 1.10.1
'@actions/exec':
specifier: ^1.1.1
version: 1.1.1
'@actions/glob':
specifier: ^0.4.0
version: 0.4.0
'@actions/http-client':
specifier: ^2.2.1
version: 2.2.1