Skip to content

Commit efd6a56

Browse files
authored
fix: regression ci (cloudwego#96)
* docs: README * fix: python install * fix: run first testdata in script * tests: check run success in run_testdata * tests: update regression to use auto env setup and fix exit value * tests: add typescript to regression * fix: ts ci
1 parent a4432e4 commit efd6a56

6 files changed

Lines changed: 119 additions & 57 deletions

File tree

.github/workflows/regression.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
run_all_tests:
1313
runs-on: ubuntu-latest
1414
#if: "!contains(github.event.pull_request.title, '[NO-REGRESSION-TEST]')"
15+
env:
16+
LANGS: "go rust python java typescript"
1517
steps:
1618
- name: Setup Go environment
1719
uses: actions/setup-go@v5
@@ -29,16 +31,21 @@ jobs:
2931
with:
3032
python-version: '3.11'
3133

34+
- name: Setup JDK 21
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '21'
38+
distribution: 'temurin'
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: '22'
44+
3245
- name: Checkout pull request code
3346
uses: actions/checkout@v4
3447
with:
3548
path: 'pr_repo'
36-
submodules: true
37-
38-
- name: Install Python dependencies
39-
run: |
40-
pip install -r ./pr_repo/script/requirements.txt
41-
pip install ./pr_repo/pylsp
4249

4350
- name: Checkout main branch code
4451
uses: actions/checkout@v4
@@ -51,14 +58,26 @@ jobs:
5158
(cd main_repo && go build -o ../abcoder_old)
5259
(cd pr_repo && go build -o ../abcoder_new)
5360
54-
- name: Run test scripts and generate outputs
61+
- name: Install evaluation dependencies
62+
run: pip install -r ./pr_repo/script/requirements.txt
63+
64+
- name: Install LSPs
5565
run: |
56-
LANGS="go rust python" OUTDIR=out_old ABCEXE=./abcoder_old ./pr_repo/script/run_all_testdata.sh
57-
LANGS="go rust python" OUTDIR=out_new ABCEXE=./abcoder_new ./pr_repo/script/run_all_testdata.sh
66+
OUTDIR=out_new ABCEXE=./abcoder_new ./pr_repo/script/run_testdata.sh first
67+
# use the same JDTLS for consistency and to avoid wasting time installing a duplicate JDTLS
68+
echo "JDTLS_ROOT_PATH=$(realpath ./pr_repo/lang/java/lsp/jdtls/jdt-language-server-*)" >> $GITHUB_ENV
69+
70+
- name: Run OLD abcoder
71+
run:
72+
OUTDIR=out_old ABCEXE=./abcoder_old ./pr_repo/script/run_testdata.sh all
73+
74+
- name: Run NEW abcoder
75+
run:
76+
OUTDIR=out_new ABCEXE=./abcoder_new ./pr_repo/script/run_testdata.sh all
5877

5978
- name: Compare outputs and check for regression
6079
id: diff_check
61-
run: ./pr_repo/script/diffjson.py out_old out_new
80+
run: ./pr_repo/script/diffjson.py out_old out_new || echo "failed=true" >> $GITHUB_OUTPUT
6281
continue-on-error: true
6382

6483
- name: Upload output directories
@@ -70,3 +89,7 @@ jobs:
7089
out_old
7190
out_new
7291
retention-days: 3
92+
93+
- name: Status check
94+
if: steps.diff_check.outputs.failed == 'true'
95+
run: exit 1

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ see [UniAST Specification](docs/uniast-zh.md)
3636
2. Use ABCoder to parse a repository to UniAST (JSON)
3737

3838
```bash
39-
abcoder parse {language} {repo-path} > xxx.json
39+
abcoder parse {language} {repo-path} -o xxx.json
4040
```
4141

42+
ABCoder will try to install any dependency automatically.
43+
In case of failure (or if you want to customize installation), refer to the [docs](./docs/lsp-installation-en.md).
44+
4245
For example, to parse a Go repository:
4346

4447
```bash
4548
git clone https://github.com/cloudwego/localsession.git localsession
4649
abcoder parse go localsession -o /abcoder-asts/localsession.json
4750
```
4851

49-
To parse repositories in other languages, [install the corresponding language server first](./docs/lsp-installation-en.md).
5052

5153
3. Integrate ABCoder's MCP tools into your AI agent.
5254

lang/python/lib.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package python
1616

1717
import (
1818
"fmt"
19-
"os"
2019
"os/exec"
2120
"regexp"
2221
"strconv"
@@ -63,10 +62,6 @@ func InstallLanguageServer() (string, error) {
6362
log.Info("pylsp already installed: %v", out)
6463
return lspName, nil
6564
}
66-
if _, err := os.Stat("go.mod"); os.IsNotExist(err) {
67-
log.Error("Auto installation requires working directory to be /path/to/abcoder/")
68-
return "", fmt.Errorf("bad cwd")
69-
}
7065
if err := CheckPythonVersion(); err != nil {
7166
log.Error("python version check failed: %v", err)
7267
return "", err

script/run_all_testdata.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

script/run_testdata.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
# Generate uniast for all testdata.
3+
#
4+
# USAGE:
5+
# 1. Save the uniast for all testdata to out/
6+
# $ OUTDIR=out/ ./script/run_testdata.sh all
7+
#
8+
# 2. Save the uniast for the first testdata item (0_*) in each language to out/
9+
# $ OUTDIR=out/ ./script/run_testdata.sh first
10+
#
11+
# 3. Use a custom abcoder executable
12+
# OUTDIR=out/ ABCEXE="./other_abcoder" ./script/run_testdata.sh all
13+
14+
if [[ "$1" != "all" && "$1" != "first" ]]; then
15+
echo "Usage: $0 all|first [--dry-run|-n]" >&2
16+
echo " all: Run on all testdata." >&2
17+
echo " first: Run only on testdata starting with '0_*' in each language directory." >&2
18+
echo " --dry-run|-n: Print commands without executing them." >&2
19+
exit 1
20+
fi
21+
22+
MODE=$1
23+
DRY_RUN=false
24+
if [[ "$2" == "--dry-run" || "$2" == "-n" ]]; then
25+
DRY_RUN=true
26+
fi
27+
28+
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
29+
REPO_ROOT=$(realpath --relative-to=$(pwd) "$SCRIPT_DIR/..")
30+
31+
ABCEXE=${ABCEXE:-"$REPO_ROOT/abcoder"}
32+
OUTDIR=${OUTDIR:?Error: OUTDIR is a mandatory environment variable}
33+
PARALLEL_FLAGS=${PARALLEL_FLAGS:---tag}
34+
LANGS=${LANGS:-"go rust python cxx"}
35+
36+
detect_jobs() {
37+
local ABCEXE=${1:-$ABCEXE}
38+
for lang in ${LANGS[@]}; do
39+
local repo_glob="$REPO_ROOT/testdata/$lang/*"
40+
if [[ "$MODE" == "first" ]]; then
41+
repo_glob="$REPO_ROOT/testdata/$lang/0_*"
42+
fi
43+
for repo in $repo_glob; do
44+
# Skip if glob doesn't match anything to avoid errors
45+
[[ -e "$repo" ]] || continue
46+
local rel_path=$(realpath --no-symlinks --relative-to="$REPO_ROOT/testdata" "$repo")
47+
local outname=$(echo "$rel_path" | sed 's/[/:? ]/_/g')
48+
echo $ABCEXE parse $lang $repo -o $OUTDIR/$outname.json
49+
done
50+
done
51+
}
52+
53+
if [[ ! -x "$ABCEXE" ]]; then
54+
echo "Error: The specified abcoder executable '$ABCEXE' does not exist or is not executable." >&2
55+
exit 1
56+
fi
57+
mkdir -pv "$OUTDIR"
58+
detect_jobs
59+
if $DRY_RUN ; then
60+
exit 0
61+
fi
62+
echo
63+
detect_jobs | parallel $PARALLEL_FLAGS -j$(nproc --all) --jobs 0 "eval {}" 2>&1
64+
65+
echo
66+
echo "Verifying that all expected output files were generated..."
67+
all_files_exist=true
68+
# Rerun detect_jobs to get the list of expected json files and check for their existence.
69+
for file_path in $(detect_jobs | awk '{print $NF}'); do
70+
if [[ ! -f "$file_path" ]]; then
71+
echo "Error: Expected output file does not exist: $file_path" >&2
72+
all_files_exist=false
73+
fi
74+
done
75+
76+
if [[ "$all_files_exist" == "false" ]]; then
77+
echo "One or more output files are missing. Failing." >&2
78+
exit 1
79+
else
80+
echo "All expected output files were successfully generated."
81+
fi

testdata/typescript/0_test-repo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../ts-parser/test-repo

0 commit comments

Comments
 (0)