diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..10d2580 --- /dev/null +++ b/.github/workflows/CI.yml @@ -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 \ No newline at end of file diff --git a/action.yml b/action.yml index a96d57e..4a0261a 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/gcc_matcher.jsontemplate b/dist/gcc_matcher.jsontemplate index 0c338d9..d157a38 100644 --- a/dist/gcc_matcher.jsontemplate +++ b/dist/gcc_matcher.jsontemplate @@ -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, diff --git a/dist/index.js b/dist/index.js index b6ef0f0..18b78d9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; })(); diff --git a/src/gcc_matcher.jsontemplate b/src/gcc_matcher.jsontemplate index 0c338d9..d157a38 100644 --- a/src/gcc_matcher.jsontemplate +++ b/src/gcc_matcher.jsontemplate @@ -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, diff --git a/src/index.js b/src/index.js index 04c6728..bae4398 100644 --- a/src/index.js +++ b/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 diff --git a/test/generate_warnings.c b/test/generate_warnings.c new file mode 100644 index 0000000..10a55cb --- /dev/null +++ b/test/generate_warnings.c @@ -0,0 +1,20 @@ +#include + +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)); +} \ No newline at end of file