Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some files added via upload #36

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Binary file added ARIS-configure-issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,253 changes: 1,253 additions & 0 deletions ARISCloudAgent.log

Large diffs are not rendered by default.

Binary file added buildtool.exe
Binary file not shown.
60 changes: 60 additions & 0 deletions buildtool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>tools</groupId>
<artifactId>buildtool</artifactId>

<dependencies>
<!-- This is the primary JDK used for (almost) everything -->
<!-- It can be referenced using the ${JAVA_HOME} or ${JAVA_HOME_8} environment variables -->
<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>zulujdk</artifactId>
<version>8.46.0.21-${os.platform}</version>
<env>JAVA_HOME_8</env>
</dependency>

<!-- This is the secondary JDK used (currently) only for building the provtools/ptools module
It can be referenced using the ${JAVA_HOME2} or ${JAVA_HOME_11} environment variables, see
<codelineRoot>/base/provtools/ptools/pom.xml for a usage example
-->
<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>zulujdk</artifactId>
<version>11.39.17-${os.platform}</version>
<env>JAVA_HOME_11</env>
</dependency>

<!-- use PPM specific ANT distibution -->
<dependency>
<groupId>com.aris.ppm.tools</groupId>
<artifactId>ant</artifactId>
<version>1.9.6</version>
</dependency>

<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>maven</artifactId>
<version>3.6.3q</version>
</dependency>

<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>nodejs</artifactId>
<version>12.13.1p-${os.platform}</version>
</dependency>

<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>phantomjs</artifactId>
<version>2.1.1-windows</version>
</dependency>

<dependency>
<groupId>com.aris.tools</groupId>
<artifactId>devtools</artifactId>
<version>99.0.0.0-trunk-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
227 changes: 227 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import {execFile} from 'child_process';
import * as micromatch from 'micromatch';
import {promisify} from 'util';

const execFileP = promisify(execFile);
const octokit = github.getOctokit(core.getInput('token'));
const context = github.context;
const {repo} = context;
const event_type = context.eventName;

async function run() {
const fsl = getFileSizeLimitBytes();

core.info(`Default configured filesizelimit is set to ${fsl} bytes...`);
core.info(
`Name of Repository is ${repo.repo} and the owner is ${repo.owner}`
);
core.info(`Triggered event is ${event_type}`);

const labelName = core.getInput('labelName');
const labelColor = core.getInput('labelColor');

await getOrCreateLfsWarningLabel(labelName, labelColor);

if (event_type === 'pull_request') {
const pullRequestNumber = context.payload.pull_request?.number;

if (pullRequestNumber === undefined) {
throw new Error('Could not get PR number');
}

core.info(`The PR number is: ${pullRequestNumber}`);

const prFilesWithBlobSize = await getPrFilesWithBlobSize(pullRequestNumber);

core.debug(`prFilesWithBlobSize: ${JSON.stringify(prFilesWithBlobSize)}`);

const largeFiles: string[] = [];
const accidentallyCheckedInLsfFiles: string[] = [];
for (const file of prFilesWithBlobSize) {
const {fileblobsize, filename} = file;
if (fileblobsize !== null && fileblobsize > Number(fsl)) {
largeFiles.push(filename);
} else {
// look for files below threshold that should be stored in LFS but are not
const shouldBeStoredInLFS = (
await execFileP('git', ['check-attr', 'filter', filename])
).stdout.includes('filter: lfs');

if (shouldBeStoredInLFS) {
const isStoredInLFS = Boolean(
file.patch?.includes('version https://git-lfs.github.com/spec/v1')
);
if (!isStoredInLFS) {
accidentallyCheckedInLsfFiles.push(filename);
}
}
}
}

const lsfFiles = largeFiles.concat(accidentallyCheckedInLsfFiles);

const issueBaseProps = {
...repo,
issue_number: pullRequestNumber,
};

if (lsfFiles.length > 0) {
core.info('Detected file(s) that should be in LFS: ');
core.info(lsfFiles.join('\n'));

const body = getCommentBody(
largeFiles,
accidentallyCheckedInLsfFiles,
fsl
);

await Promise.all([
octokit.rest.issues.addLabels({
...issueBaseProps,
labels: [labelName],
}),
octokit.rest.issues.createComment({
...issueBaseProps,
body,
}),
]);

core.setOutput('lfsFiles', lsfFiles);
core.setFailed(
'Large file(s) detected! Setting PR status to failed. Consider using git-lfs to track the LFS file(s)'
);
} else {
core.info('No large file(s) detected...');

const {data: labels} = await octokit.rest.issues.listLabelsOnIssue({
...issueBaseProps,
});
if (labels.map(l => l.name).includes(labelName)) {
await octokit.rest.issues.removeLabel({
...issueBaseProps,
name: labelName,
});
core.info(`label ${labelName} removed`);
}
}
} else {
core.info('No Pull Request detected. Skipping LFS warning check');
}
}

run().catch(error => {
core.setFailed(error.message);
});

function getFileSizeLimitBytes() {
const fsl = core.getInput('filesizelimit');

const lastTwoChars = fsl.slice(-2).toLowerCase();

if (lastTwoChars === 'kb') {
return Number(fsl.slice(0, -2)) * 1024;
} else if (lastTwoChars === 'mb') {
return Number(fsl.slice(0, -2)) * 1024 * 1024;
} else if (lastTwoChars === 'gb') {
return Number(fsl.slice(0, -2)) * 1024 * 1024 * 1024;
} else if (lastTwoChars[1] === 'b') {
return fsl.slice(0, -1);
} else {
return fsl;
}
}

async function getOrCreateLfsWarningLabel(
labelName: string,
labelColor: string
) {
try {
await octokit.rest.issues.getLabel({
...repo,
name: labelName,
});
} catch (error) {
if (error instanceof Error) {
if (error.message === 'Not Found') {
await octokit.rest.issues.createLabel({
...repo,
name: labelName,
color: labelColor,
description:
'Warning Label for use when LFS is detected in the commits of a Pull Request',
});
core.info('No lfs warning label detected. Creating new label ...');
core.info('LFS warning label created');
} else {
core.error(`getLabel error: ${error.message}`);
}
}
}
}

async function getPrFilesWithBlobSize(pullRequestNumber: number) {
const {data} = await octokit.rest.pulls.listFiles({
...repo,
pull_number: pullRequestNumber,
});

const exclusionPatterns = core.getMultilineInput('exclusionPatterns');

const files =
exclusionPatterns.length > 0
? data.filter(({filename}) => {
const isExcluded = micromatch.isMatch(filename, exclusionPatterns);
if (isExcluded) {
core.info(`${filename} has been excluded from LFS warning`);
}
return !isExcluded;
})
: data;

const prFilesWithBlobSize = await Promise.all(
files.map(async file => {
const {filename, sha, patch} = file;
const {data: blob} = await octokit.rest.git.getBlob({
...repo,
file_sha: sha,
});

return {
filename,
filesha: sha,
fileblobsize: blob.size,
patch,
};
})
);
return prFilesWithBlobSize;
}

function getCommentBody(
largeFiles: string[],
accidentallyCheckedInLsfFiles: string[],
fsl: string | number
) {
const largeFilesBody = `The following file(s) exceeds the file size limit: ${fsl} bytes, as set in the .yml configuration files:

${largeFiles.join(', ')}

Consider using git-lfs to manage large files.
`;

const accidentallyCheckedInLsfFilesBody = `The following file(s) are tracked in LFS and were likely accidentally checked in:

${accidentallyCheckedInLsfFiles.join(', ')}
`;

const body = `## :warning: Possible file(s) that should be tracked in LFS detected :warning:
${largeFiles.length > 0 ? largeFilesBody : ''}
${
accidentallyCheckedInLsfFiles.length > 0
? accidentallyCheckedInLsfFilesBody
: ''
}`;
return body;
}
Loading