Skip to content

Commit 87066f3

Browse files
committed
自動スクリプト
1 parent 68af418 commit 87066f3

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

.github/workflows/fix-e2e.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,8 @@ jobs:
7171
# comment on PR with results
7272
- name: List and display file contents
7373
run: |
74-
DIR="result"
75-
OUTPUT="## Result of test fix\n\n"
76-
FOUND_FILES=0
77-
78-
while IFS= read -r -d '' FILE; do
79-
FOUND_FILES=1
80-
echo "Processing $FILE"
81-
CONTENT=$(cat "$FILE")
82-
OUTPUT+="### Contents of \`$(basename "$FILE")\`\n\n\`\`\`\n$CONTENT\n\`\`\`\n\n"
83-
done < <(find "$DIR" -maxdepth 1 -type f -print0)
84-
85-
if [ "$FOUND_FILES" -eq 0 ]; then
86-
OUTPUT="No test fix required"
87-
fi
88-
89-
echo -e "$OUTPUT" > comment.txt
74+
chmod +x ./scripts/suggest-repair/index.sh
75+
./scripts/suggest-repair/index.sh
9076
9177
- name: Comment on PR
9278
run: gh pr comment ${{ github.event.number }} --body-file comment.txt

scripts/suggest-repair/index.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
project_root_dir=$(pwd)
4+
result_file_dir="$project_root_dir/result"
5+
6+
files=$(find $project_root_dir/e2e)
7+
8+
for file in $files; do
9+
if [ -d $file ]; then
10+
# If $file directory, do nothing.
11+
continue
12+
fi
13+
14+
node ./scripts/suggest-repair/main.mjs --projectRootDir $project_root_dir --testFile $file --resultFileDir $result_file_dir
15+
done

scripts/suggest-repair/main.mjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _traverse from '@babel/traverse'
33
import yargs from 'yargs'
44

55
import { getAst } from '../util/get-ast.mjs'
6-
import { readFile } from '../util/file.mjs'
6+
import { readFile, writeFile } from '../util/file.mjs'
77
import { TEST_ID_ATTRIBUTE_NAME } from '../util/constant.mjs'
88

99
/** @type {typeof _traverse} */
@@ -36,6 +36,10 @@ const COLLECT_FUNCTIONS = new Set([
3636

3737
const argv = await yargs(process.argv.slice(2))
3838
.options({
39+
projectRootDir: {
40+
demandOption: true,
41+
string: true,
42+
},
3943
testFile: {
4044
demandOption: true,
4145
string: true,
@@ -142,6 +146,7 @@ traverse(ast, {
142146
},
143147
})
144148

149+
let comment = ''
145150
for (const testName in results) {
146151
const fixedResults = await readFile(
147152
path.join(argv.resultFileDir, `${testName}.json`),
@@ -318,9 +323,9 @@ for (const testName in results) {
318323
}
319324
}
320325

321-
console.log(
322-
`### Suggested Repairs for test "${testName}" in "${
323-
argv.testFile
324-
}"\n${suggestedRepairs.join('\n')}`
325-
)
326+
comment += `### Suggested Repairs for test "${testName}" in "${
327+
argv.testFile
328+
}"\n${suggestedRepairs.join('\n')}\n`
326329
}
330+
331+
await writeFile(path.join(argv.projectRootDir, 'comment.txt'), comment, true)

scripts/util/file.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import path from 'path'
44
/**
55
* @param {string} filePath
66
* @param {string} content
7+
* @param {boolean} [append=false]
78
* @return {void}
89
*/
9-
export function writeFile(filePath, content) {
10+
export function writeFile(filePath, content, append = false) {
1011
const dir = path.dirname(filePath)
1112
if (!fs.existsSync(dir)) {
1213
fs.mkdirSync(dir, { recursive: true })
1314
}
14-
fs.writeFileSync(filePath, content, 'utf-8')
15+
fs.writeFileSync(filePath, content, {
16+
encoding: 'utf-8',
17+
flag: append ? 'a' : 'w',
18+
})
1519
}
1620

1721
/**

0 commit comments

Comments
 (0)