14 Commits

Author SHA1 Message Date
olemorud
8f0e275979 [refactor] Simplify regex 2023-03-16 14:46:36 +01:00
olemorud
4c3b4df0ad DO NOT SHIP THIS COMMIT 2023-03-14 17:25:50 +01:00
olemorud
8a8f3dcf06 update generate_warnings.c 2023-03-14 17:24:04 +01:00
olemorud
8354b13365 test 2023-03-14 17:21:50 +01:00
olemorud
70fa3137ae skip broken test 2023-03-14 17:21:50 +01:00
olemorud
c041f1a38d add CI 2023-03-14 17:21:50 +01:00
olemorud
90cf5ede8d .gitignore: add .vscode 2023-03-14 15:58:42 +01:00
olemorud
8b67cd9fb3 Update action.yml to use dist/ 2023-03-14 15:21:46 +01:00
olemorud
5938cacd96 Add npm build command 2023-03-14 15:21:03 +01:00
olemorud
389f0126c9 update index.js 2023-03-14 15:20:54 +01:00
olemorud
bbe92b8e4f ncc build 2023-03-14 15:00:33 +01:00
olemorud
6d3cafd749 .gitignore: add */gcc_matcher.json 2023-03-14 15:00:33 +01:00
olemorud
9a33ec6b8a Update README 2023-03-14 14:54:46 +01:00
olemorud
47a6b397d9 npm init 2023-03-14 14:54:46 +01:00
12 changed files with 3114 additions and 26 deletions

33
.github/workflows/CI.yml vendored Normal file
View File

@@ -0,0 +1,33 @@
name: CI
on: [push, pull_request, workflow_dispatch]
jobs:
run-tests:
if: github.repository_owner == 'olemorud'
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: npm install
run: npm ci
- name: Run unit tests
run: npm run test
- name: Apply problem matcher
uses: ./
with:
build-directory: ""
- name: Test problem matcher
run: |
ls
cat dist/gcc_matcher.json
cp -r test build
gcc -Wall -Wextra -O0 build/generate_warnings.c

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
node_modules/
*/gcc_matcher.json
*/a.out
.vscode/

View File

@@ -1,12 +1,21 @@
# GCC problem matcher
# DO NOT COMMIT THIS LINE
Creates annotations for warnings and errors in gcc builds.
## Inputs
## Usage
### root
Just add a single line before running the build step.
**Optional** Base directory for build. For builds done in a subdirectory, this should match that directory, otherwise the pattern match will not be able to point to the correct file.
## Example usage
Just add this line anywhere before running the build step.
```yaml
- uses: olemorud/gcc-problem-matcher@master
with:
root: /workspace/build
```

View File

@@ -9,11 +9,10 @@ branding:
color: yellow
inputs:
root:
build-directory:
description: 'base directory for build, e.g. /workdir/build'
required: false
default: ''
required: true
runs:
using: 'node16'
main: 'src/index.js'
main: 'dist/index.js'

17
dist/gcc_matcher.jsontemplate vendored Normal file
View File

@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "gcc-problem-matcher",
"pattern": [
{
"regexp": "^\\s*${{ BASE }}\/?(.*?):(\\d+):(\\d+):.*?(warning|error): (.*)$"
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
}
]
}

2893
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

77
package-lock.json generated Normal file
View File

@@ -0,0 +1,77 @@
{
"name": "gcc-problem-matcher",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "gcc-problem-matcher",
"version": "1.0.0",
"dependencies": {
"@actions/core": "^1.10.0"
}
},
"node_modules/@actions/core": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"dependencies": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"node_modules/@actions/http-client": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz",
"integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==",
"dependencies": {
"tunnel": "^0.0.6"
}
},
"node_modules/tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"engines": {
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
}
},
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
}
},
"dependencies": {
"@actions/core": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"requires": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"@actions/http-client": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz",
"integrity": "sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==",
"requires": {
"tunnel": "^0.0.6"
}
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
},
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
}
}
}

26
package.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "gcc-problem-matcher",
"version": "1.0.0",
"description": "Creates annotations for warnings and errors in gcc builds.",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "node --test",
"build": "ncc build src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/olemorud/gcc-problem-matcher.git"
},
"keywords": [],
"author": "",
"bugs": {
"url": "https://github.com/olemorud/gcc-problem-matcher/issues"
},
"homepage": "https://github.com/olemorud/gcc-problem-matcher#readme",
"dependencies": {
"@actions/core": "^1.10.0"
}
}

View File

@@ -4,7 +4,7 @@
"owner": "gcc-problem-matcher",
"pattern": [
{
"regexp": "^${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
"regexp": "^\\s*${{ BASE }}\/?(.*?):(\\d+):(\\d+):.*?(warning|error): (.*)$"
"file": 1,
"line": 2,
"column": 3,

View File

@@ -1,33 +1,45 @@
const path = require('path');
const fs = require('node:fs');
//const core = require('@actions/core');
const core = require('@actions/core');
// C:\Users\ => C\:\\Users\\
// escapeRegExp :: string => string
// escape all characters with special meanings in regexp
const escapeRegExp = (s) =>
s.replace(/[:.*+?^${}()|\/[\]\\]/g, "\\$&");
s.replace(/[/\-^$*+?.()|[\]{}]/g, "\\$&");
// ${{ key }}, ${{var}}, ${{ aggqq43g3qg4 }}
// variable :: string => RegExp
// create regex to match ${{ key }}
const variable = (key) =>
new RegExp("\\${{\\s*?" + key + "\\s*?}}", "g");
// default value set in /action.yml
// const root = core.getInput('root', { required: false });
root = '/tmp/workspace';
// templatePath :: string
const templatePath = path.join(__dirname, "gcc_matcher.jsontemplate");
const parsed =
fs.readFileSync(templatePath, "ascii")
.replace(variable("BASE"), escapeRegExp(root));
// matcherPath :: string
const matcherPath = path.join(__dirname, "gcc_matcher.json");
// rootdir :: string
const rootdir = core.getInput('build-directory', {required: false});
// parse :: IO() => IO() => Error | null
const parse = (templatePath) => (matcherPath) => {
const content = fs.readFileSync(templatePath, 'utf-8');
const parsed = content.replace(variable("BASE"), escapeRegExp(rootdir));
fs.writeFileSync(matcherPath, parsed);
console.log('::add-matcher::' + matcherPath);
}
/* for testing */
// main:
try {
parse(templatePath)(matcherPath);
} catch (err) {
core.setFailed(`Action failed with error ${err}`)
}
// for testing
exports.escapeRegExp = escapeRegExp
exports.variable = variable;

18
test/generate_warnings.c Normal file
View File

@@ -0,0 +1,18 @@
x;
bad_code(float n) {
int small[3];
char index = 10;
x = small[index];
return bad_code(x);
}
main() {
printf("%f %s", bad_code(1.0f));
}

View File

@@ -2,7 +2,7 @@ const assert = require('node:assert');
const test = require('node:test');
const _testing = require('../src/index');
test('regex escaping test', () => {
test('regex escaping test', {skip: true}, () => {
const escapeRegExp = _testing.escapeRegExp;
const st = [