Skip to content

Commit

Permalink
Log output also to matchOutput output variable
Browse files Browse the repository at this point in the history
  • Loading branch information
maso7 committed Aug 14, 2024
1 parent 77378db commit 78c3820
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# gh-action-log-parser


## update patterns file

To update patterns you need npm and nodejs installed. Check `.tool-versions` for version.


* Edit files in `patterns` directory.
* Update Changelog.md.
* Create package `npm run package`.
* Commit all changed files.
* Create 2 tags.
* Major, minor, patch e.g. 0.1.0.
* Major, minor e.g. 0.1.
* Push everything.
- Edit files in `patterns` directory.
- Update Changelog.md.
- Create package `npm run package`.
- Commit all changed files.
- Create 2 tags.
- Major, minor, patch e.g. 0.1.0.
- Major, minor e.g. 0.1.
- Push everything.

We use 2 tags to avoid updating workflows for every change. For patches and small tweaks we bump patch version.
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ inputs:
description: 'Type of log to check (e.g., node, python, java)'
required: false
default: 'unity'
matchOutputMaxChars:
description: 'Max size of matchOutput output variable'
required: false
default: '500'
outputs:
matchOutput:
description: 'Print matched output also to variable'

runs:
using: node20
Expand Down
11 changes: 10 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const core = require('@actions/core');
const fs = require('fs');
const readline = require('readline');

// const nodePatterns = require('./patterns/unity.js')
// store messages for output matchOutput
let matchOutput = "";

function loadPatterns(logType) {
try {
Expand Down Expand Up @@ -96,17 +97,25 @@ function printMatch(match) {
message += `\nContext Lines:\n${match.context.join("\n")}`;
}
console.log(message);
matchOutput += message + "\n";
}

async function run() {
try {
const filePath = core.getInput('filePath');
const logType = core.getInput('logType');
const matchOutputMaxCharsInput = core.getInput('matchOutputMaxChars');
const matchOutputMaxChars = parseInt(matchOutputMaxCharsInput, 10);

if (isNaN(matchOutputMaxChars)) {
core.setFailed('Input "matchOutputMaxChars" is not a valid integer.');
}

const patterns = await loadPatterns(logType);

if (patterns && patterns.length > 0) {
await checkFile(filePath, patterns);
core.setOutput("matchOutput", JSON.stringify(matchOutput.slice(0, matchOutputMaxChars) + "\n___Rest is truncated due to \"" + matchOutputMaxChars + "\" chars limit___\n"));
}

} catch (error) {
Expand Down

0 comments on commit 78c3820

Please sign in to comment.