add CI
This commit is contained in:
33
.github/workflows/CI.yml
vendored
Normal file
33
.github/workflows/CI.yml
vendored
Normal 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: build/
|
||||
|
||||
- name: Test problem matcher
|
||||
run: |
|
||||
ls
|
||||
cat dist/gcc_matcher.json
|
||||
cp -r test build
|
||||
gcc -Wall -Wextra -O0 build/generate_warnings.c
|
||||
@@ -9,10 +9,9 @@ branding:
|
||||
color: yellow
|
||||
|
||||
inputs:
|
||||
root:
|
||||
build-directory:
|
||||
description: 'base directory for build, e.g. /workdir/build'
|
||||
required: false
|
||||
default: ''
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
|
||||
2
dist/gcc_matcher.jsontemplate
vendored
2
dist/gcc_matcher.jsontemplate
vendored
@@ -4,7 +4,7 @@
|
||||
"owner": "gcc-problem-matcher",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"regexp": "^.*?${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
|
||||
48
dist/index.js
vendored
48
dist/index.js
vendored
@@ -2845,32 +2845,50 @@ const path = __nccwpck_require__(17);
|
||||
const fs = __nccwpck_require__(561);
|
||||
const core = __nccwpck_require__(127);
|
||||
|
||||
// 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 });
|
||||
|
||||
// templatePath :: string
|
||||
const templatePath = __nccwpck_require__.ab + "gcc_matcher.jsontemplate";
|
||||
|
||||
const parsed =
|
||||
fs.readFileSync(__nccwpck_require__.ab + "gcc_matcher.jsontemplate", "ascii")
|
||||
.replace(variable("BASE"), escapeRegExp(root));
|
||||
|
||||
// matcherPath :: string
|
||||
const matcherPath = __nccwpck_require__.ab + "gcc_matcher.json";
|
||||
|
||||
fs.writeFileSync(__nccwpck_require__.ab + "gcc_matcher.json", parsed);
|
||||
// rootdir :: string
|
||||
const rootdir = () =>
|
||||
core.getInput('build-directory', {required: false}) || "/build";
|
||||
|
||||
console.log('::add-matcher::' + matcherPath);
|
||||
// parse :: IO() => IO() => Error | null
|
||||
const parse = (templatePath) => (matcherPath) => {
|
||||
const r = rootdir();
|
||||
|
||||
/* for testing */
|
||||
console.log(r);
|
||||
|
||||
const content = fs.readFileSync(templatePath, 'utf-8');
|
||||
|
||||
const parsed = content.replace(variable("BASE"), escapeRegExp(rootdir()));
|
||||
|
||||
fs.writeFileSync(matcherPath, parsed);
|
||||
|
||||
console.log('::add-matcher::' + matcherPath);
|
||||
}
|
||||
|
||||
// main:
|
||||
try {
|
||||
parse(__nccwpck_require__.ab + "gcc_matcher.jsontemplate")(__nccwpck_require__.ab + "gcc_matcher.json");
|
||||
} catch (err) {
|
||||
core.setFailed(`Action failed with error ${err}`)
|
||||
}
|
||||
|
||||
|
||||
// for testing
|
||||
exports.escapeRegExp = escapeRegExp
|
||||
exports.variable = variable;
|
||||
})();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"owner": "gcc-problem-matcher",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"regexp": "^.*?${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
|
||||
30
src/index.js
30
src/index.js
@@ -5,7 +5,7 @@ const core = require('@actions/core');
|
||||
// escapeRegExp :: string => string
|
||||
// escape all characters with special meanings in regexp
|
||||
const escapeRegExp = (s) =>
|
||||
s.replace(/[:.*+?^${}()|\/[\]\\]/g, "\\$&");
|
||||
s.replace(/[/\-^$*+?.()|[\]{}]/g, "\\$&");
|
||||
|
||||
// variable :: string => RegExp
|
||||
// create regex to match ${{ key }}
|
||||
@@ -18,25 +18,31 @@ const templatePath = path.join(__dirname, "gcc_matcher.jsontemplate");
|
||||
// matcherPath :: string
|
||||
const matcherPath = path.join(__dirname, "gcc_matcher.json");
|
||||
|
||||
// parse :: IO => IO => Error | null
|
||||
// rootdir :: string
|
||||
const rootdir = () =>
|
||||
core.getInput('build-directory', {required: false});
|
||||
|
||||
// parse :: IO() => IO() => Error | null
|
||||
const parse = (templatePath) => (matcherPath) => {
|
||||
fs.readFile(templatePath, 'utf-8', (err, content) => {
|
||||
if (err) throw err;
|
||||
const r = rootdir();
|
||||
|
||||
const root = core.getInput('root', { required: false });
|
||||
console.log(r);
|
||||
|
||||
const parsed = content.replace(variable("BASE"), escapeRegExp(root));
|
||||
const content = fs.readFileSync(templatePath, 'utf-8');
|
||||
|
||||
fs.writeFile(matcherPath, parsed, (err) => {
|
||||
if (err) throw err;
|
||||
const parsed = content.replace(variable("BASE"), escapeRegExp(rootdir()));
|
||||
|
||||
console.log('::add-matcher::' + matcherPath);
|
||||
});
|
||||
});
|
||||
fs.writeFileSync(matcherPath, parsed);
|
||||
|
||||
console.log('::add-matcher::' + matcherPath);
|
||||
}
|
||||
|
||||
// main:
|
||||
parse(templatePath)(matcherPath);
|
||||
try {
|
||||
parse(templatePath)(matcherPath);
|
||||
} catch (err) {
|
||||
core.setFailed(`Action failed with error ${err}`)
|
||||
}
|
||||
|
||||
|
||||
// for testing
|
||||
|
||||
20
test/generate_warnings.c
Normal file
20
test/generate_warnings.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <limits.h>
|
||||
|
||||
int bad_code(float n) {
|
||||
|
||||
int small[3];
|
||||
|
||||
char index = 10;
|
||||
|
||||
int x = small[index];
|
||||
|
||||
double promoted = 3.14159 * n * n;
|
||||
|
||||
return bad_code(x);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
printf("%s %s", bad_code(1.0f));
|
||||
}
|
||||
Reference in New Issue
Block a user