Skip to content

Commit

Permalink
migrate script to generate problem matcher from commonjs to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Dec 22, 2024
1 parent 201ad96 commit d3399fe
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/matcher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Update test data
run: make ./scripts/generate-actionlint-matcher/test/* SKIP_GO_GENERATE=true
- name: Test actionlint-matcher.json
run: node ./scripts/generate-actionlint-matcher/test.js
run: node ./scripts/generate-actionlint-matcher/test.mjs
- name: Ensure .github/actionlint-matcher.json is up-to-date
run: |
make .github/actionlint-matcher.json
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ man: man/actionlint.1
bench:
go test -bench Lint -benchmem

.github/actionlint-matcher.json: scripts/generate-actionlint-matcher/object.js
node ./scripts/generate-actionlint-matcher/main.js .github/actionlint-matcher.json
.github/actionlint-matcher.json: scripts/generate-actionlint-matcher/object.mjs
node ./scripts/generate-actionlint-matcher/main.mjs .github/actionlint-matcher.json

scripts/generate-actionlint-matcher/test/escape.txt: actionlint
./actionlint -color ./testdata/err/one_error.yaml > ./scripts/generate-actionlint-matcher/test/escape.txt || true
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-actionlint-matcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ make .github/actionlint-matcher.json
or directly run the script

```sh
node ./scripts/generate-actionlint-matcher/main.js .github/actionlint-matcher.json
node ./scripts/generate-actionlint-matcher/main.mjs .github/actionlint-matcher.json
```

## Test

```sh
node ./scripts/generate-actionlint-matcher/test.js
node ./scripts/generate-actionlint-matcher/test.mjs
```

The test uses test data at `./scripts/generate-actionlint-matcher/test/*.txt`. They should be updated when actionlint changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs').promises;
const object = require('./object.js');
import { promises as fs } from 'node:fs';
import object from './object.mjs';

async function main(args) {
const json = JSON.stringify(object, null, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ const object = {
],
};

module.exports = object;
export default object;
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const path = require('path');
const fs = require('fs');
const assert = require('assert').strict;
const pattern = require('./object.js').problemMatcher[0].pattern[0];
import path from 'node:path';
import fs from 'node:fs';
import assert from 'node:assert';
import { fileURLToPath } from 'node:url';
import object from './object.mjs';

const pattern = object.problemMatcher[0].pattern[0];
const regexp = new RegExp(pattern.regexp);
const dirname = path.dirname(fileURLToPath(import.meta.url));

{
const want = require('./test/want.json')[0];
const file = path.join(dirname, 'test', 'want.json');
const want = JSON.parse(fs.readFileSync(file, 'utf8'))[0];

for (const file of ['escape.txt', 'no_escape.txt']) {
console.log(`Testing test/${file}`);
const escaped = path.join(__dirname, 'test', file);
const escaped = path.join(dirname, 'test', file);
const lines = fs.readFileSync(escaped, 'utf8').split('\n');
const m = lines[0].match(regexp);
assert.ok(m); // not null
Expand All @@ -23,7 +28,7 @@ const regexp = new RegExp(pattern.regexp);
}

for (const parent of ['examples', 'err']) {
const dir = path.join(__dirname, '..', '..', 'testdata', parent);
const dir = path.join(dirname, '..', '..', 'testdata', parent);
for (const name of fs.readdirSync(dir)) {
if (!name.endsWith('.out')) {
continue;
Expand Down

0 comments on commit d3399fe

Please sign in to comment.