Skip to content

Commit

Permalink
feat: ✨ More configuration flags
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Jan 2, 2025
1 parent b891ee8 commit 86e68ce
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:

- name: 'Run CodeLimit action'
uses: getcodelimit/codelimit-action@main
with:
check: false
codelimit-version: 'main'
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ jobs:
- name: 'Run CodeLimit'
uses: getcodelimit/codelimit-action@v1
```
## Inputs
| Name | Description | Required | Default |
| --- | --- | --- | --- |
| token | GitHub token for storing results | false | ${{ github.token }} |
| check | Check changed files | false | true |
| codelimit-version | CodeLimit version | false | 'latest' |
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ runs:
image: 'Dockerfile'
inputs:
token:
description: 'GitHub token for repository'
default: ${{ github.token }}
description: 'GitHub token for storing results'
required: false
default: ${{ github.token }}
check:
description: 'Checked changed files'
default: 'true'
description: 'Check changed files'
required: false
default: true
codelimit-version:
description: 'CodeLimit version'
required: false
default: 'latest'
45 changes: 32 additions & 13 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import {getInput} from "@actions/core";
import {getBooleanInput, getInput} from "@actions/core";
import {context} from "@actions/github";
import {Octokit} from "@octokit/action";
import {
Expand All @@ -14,7 +14,13 @@ import {
updateComment
} from "./github";
import {exec, getExecOutput} from "@actions/exec";
import {downloadCodeLimitBinary, getReportContent, makeNotFoundBadgeSvg, makeStatusBadgeSvg} from "./codelimit";
import {
downloadCodeLimitBinary,
getReportContent,
installCodeLimit,
makeNotFoundBadgeSvg,
makeStatusBadgeSvg
} from "./codelimit";
import {getChangedFiles} from "./utils";
import {version} from "./version";
import signale, {error, info, success} from "signale";
Expand Down Expand Up @@ -87,22 +93,12 @@ async function checkChangedFiles(octokit: Octokit, clBinary: string): Promise<nu
}
}

async function main() {
info(`CodeLimit action, version: ${version.revision}`);
let exitCode = 0;
const clBinary = await downloadCodeLimitBinary();
info('Scanning codebase...');
await exec(clBinary, ['scan', '.']);
async function updateRepository(octokit: Octokit, clBinary: string) {
const reportMarkdown = (await getExecOutput(clBinary, ['report', '--format', 'markdown'])).stdout;
const findingsMarkdown = (await getExecOutput(clBinary, ['findings', '--format', 'markdown'])).stdout;
const findingsFullMarkdown = (await getExecOutput(clBinary, ['findings', '--full', '--format', 'markdown'])).stdout;
const markdownReport = await generateMarkdownReport(reportMarkdown, findingsMarkdown);
const markdownFullFindingsReport = await generateMarkdownReport(reportMarkdown, findingsFullMarkdown);
const octokit = new Octokit({auth: getInput('token')});
const doCheck = getInput('check') || true;
if (doCheck) {
exitCode = await checkChangedFiles(octokit, clBinary);
}
const owner = getRepoOwner(context);
const repo = getRepoName(context);
const branch = getSourceBranch();
Expand All @@ -128,6 +124,29 @@ async function main() {
}
}
}
}

async function main() {
info(`CodeLimit-action, version: ${version.revision}`);
const codeLimitVersion = getInput('codelimit-version') || 'latest';
let clBinary;
if (codeLimitVersion === 'latest') {
clBinary = await downloadCodeLimitBinary();
} else {
clBinary = await installCodeLimit();
}
info(`CodeLimit binary: ${clBinary}`);
info('CodeLimit version:');
await exec(clBinary, ['--version']);
info('Scanning codebase...');
await exec(clBinary, ['scan', '.']);
const octokit = new Octokit({auth: getInput('token')});
const doCheck = getBooleanInput('check');
let exitCode = 0;
if (doCheck) {
exitCode = await checkChangedFiles(octokit, clBinary);
}
await updateRepository(octokit, clBinary);
fs.unlinkSync(clBinary);
success('Done!');
process.exit(exitCode);
Expand Down
9 changes: 8 additions & 1 deletion src/codelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {promisify} from "util";
import {makeBadge} from "badge-maker";
import {Codebase} from "./entities/Codebase";
import {info, success} from "signale";
import {exec} from "@actions/exec";

const streamPipeline = promisify(require('stream').pipeline);

Expand Down Expand Up @@ -33,7 +34,7 @@ async function getLatestBinaryUrl() {
return `${downloadUrl}/${getBinaryName()}`;
}

export async function downloadCodeLimitBinary() {
export async function downloadCodeLimitBinary(): Promise<string> {
const binaryUrl = await getLatestBinaryUrl();
info(`Downloading CodeLimit binary from URL: ${binaryUrl}`);
const response = await nodeFetch(binaryUrl);
Expand All @@ -44,6 +45,12 @@ export async function downloadCodeLimitBinary() {
return filename;
}

export async function installCodeLimit(): Promise<string> {
await exec('pipx', ['install', 'git+https://github.com/getcodelimit/codelimit.git']);
await exec('pipx', ['list']);
return 'codelimit';
}

export function getReportContent(): string | undefined {
return fs.readFileSync('.codelimit_cache/codelimit.json', 'utf8');
}
Expand Down

0 comments on commit 86e68ce

Please sign in to comment.