Skip to content

Commit 9cc19a9

Browse files
authored
Merge pull request #43 from codefuse-ai/cyz_dev
feat(ci): Add gdl checker in workflow and status badges to README
2 parents 973cd17 + b9b8d31 commit 9cc19a9

File tree

4 files changed

+199
-0
lines changed

4 files changed

+199
-0
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: GDL script file checker
2+
on:
3+
push:
4+
branches-ignore:
5+
- 'none'
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
checking-job:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out the repository to the runner
14+
uses: actions/checkout@v4
15+
16+
- name: Install locales
17+
run: |
18+
sudo apt-get update && sudo apt-get install -y locales
19+
sudo locale-gen zh_CN.UTF-8
20+
env:
21+
LANG: zh_CN.UTF-8
22+
LANGUAGE: zh_CN:zh:en_US:en
23+
24+
- name: Download and extract the latest sparrow-cli release
25+
run: |
26+
ASSET_NAME="sparrow-cli.*.linux.tar.gz" # This pattern should match only the tar.gz file
27+
mkdir -p $HOME/sparrow-cli
28+
29+
# Use GitHub API to get the latest release information
30+
RELEASE_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/codefuse-ai/CodeFuse-Query/releases/latest")
31+
32+
# Extract the asset download URL for the asset name specified
33+
# The test function is used to ensure we match only the tar.gz file, not the checksum file
34+
ASSET_URL=$(echo "$RELEASE_INFO" | jq --arg asset_name "$ASSET_NAME" -r '.assets[] | select(.name | test($asset_name)) | select(.content_type == "application/x-gzip").browser_download_url')
35+
36+
# Check if the asset URL is empty or not
37+
if [ -z "$ASSET_URL" ]; then
38+
echo "Error: Asset URL is empty."
39+
exit 1
40+
fi
41+
42+
# Download and extract the asset
43+
echo "Downloading $ASSET_URL to $HOME/sparrow-cli/sparrow-cli.tar.gz"
44+
curl -fL --retry 5 "$ASSET_URL" | tar -xz -C $HOME/sparrow-cli
45+
env:
46+
# The GitHub token is needed for API requests to avoid rate limits
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Set execute permissions for script
50+
run: chmod +x ./tool/aci/check_gdl.sh
51+
52+
- name: Run GDL script checking
53+
run: ./tool/aci/check_gdl.sh .
54+
env:
55+
LC_ALL: zh_CN.UTF-8

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<a href="https://marketplace.visualstudio.com/items?itemName=CodeFuse-Query.codefuse-query-extension">
2424
<img alt="VSCode Plugin" src="https://img.shields.io/visual-studio-marketplace/i/CodeFuse-Query.codefuse-query-extension?style=social&logo=visualstudiocode&logoColor=%23007ACC" />
2525
</a>
26+
<a href="https://github.com/codefuse-ai/CodeFuse-Query/actions/workflows/check_gdl_workflow.yml">
27+
<img alt="GDL script file checker" src="https://github.com/codefuse-ai/CodeFuse-Query/actions/workflows/check_gdl_workflow.yml/badge.svg" />
28+
</a>
2629
</p>
2730
</div>
2831

README_cn.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<a href="https://marketplace.visualstudio.com/items?itemName=CodeFuse-Query.codefuse-query-extension">
2424
<img alt="VSCode Plugin" src="https://img.shields.io/visual-studio-marketplace/i/CodeFuse-Query.codefuse-query-extension?style=social&logo=visualstudiocode&logoColor=%23007ACC" />
2525
</a>
26+
<a href="https://github.com/codefuse-ai/CodeFuse-Query/actions/workflows/check_gdl_workflow.yml">
27+
<img alt="GDL script file checker" src="https://github.com/codefuse-ai/CodeFuse-Query/actions/workflows/check_gdl_workflow.yml/badge.svg" />
28+
</a>
2629
</p>
2730
</div>
2831
<div align="center">

tool/aci/check_gdl.sh

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
: '
4+
This script performs validation and compilation of Godel script files (.gs and .gdl).
5+
6+
Usage:
7+
./check_gdl.sh <directory>
8+
9+
Arguments:
10+
<directory> The directory to scan for Godel script files. The script will
11+
search for .gs and .gdl files to compile and validate.
12+
13+
Description:
14+
The script does the following:
15+
- Validates that a directory is provided as an argument.
16+
- Changes to the specified directory.
17+
- Finds all .gs and .gdl files within the specified directory (excluding specific paths).
18+
- For each located library directory, it concatenates the library files and compiles them.
19+
- For each script file, it runs a separate compilation process and checks for errors.
20+
- Reports any compilation errors and terminates execution if an error occurs.
21+
- If no errors occur, it reports successful compilation for each file.
22+
23+
Requires:
24+
- The "sparrow-cli" tool must be installed and available under the user"s home directory.
25+
- Command "find" available on the system (commonly available on Unix-like systems).
26+
- Command "mktemp" available on the system for creating temporary files.
27+
- Command "date" available on the system for time measurements.
28+
29+
Author: AntGroup
30+
Date: 2024-01-16
31+
Version: 1.0
32+
33+
'
34+
35+
set +x
36+
37+
# Check if the parameter is empty
38+
if [ -z "$1" ]; then
39+
echo "Please provide a directory as an argument"
40+
exit 1
41+
fi
42+
43+
# Change to the directory
44+
cd "$1" || exit 1
45+
46+
sparrow_godel_script="$HOME/sparrow-cli/sparrow-cli/godel-script/usr/bin/godel"
47+
sparrow_lib_1_0="$HOME/sparrow-cli/sparrow-cli/lib-1.0"
48+
49+
# Define get_files function
50+
get_files() {
51+
find "$1" -type f \( -name "*$2" \) -print
52+
}
53+
54+
# Define rebuild_lib function
55+
rebuild_lib() {
56+
local lib_path="$1"
57+
local lib="$2"
58+
local gdl_list=()
59+
local output_file
60+
local tmp_out
61+
local start_time
62+
local end_time
63+
local elapsed_time
64+
65+
gdl_list+=($(get_files "$lib_path" ".gs"))
66+
gdl_list+=($(get_files "$lib_path" ".gdl"))
67+
68+
output_file=$(mktemp "tempfile.XXXXXX.gdl")
69+
trap 'rm -f "$output_file"' EXIT
70+
71+
echo "// script" > "$output_file"
72+
for file_name in "${gdl_list[@]}"; do
73+
cat "$file_name" >> "$output_file"
74+
done
75+
76+
tmp_out=$(mktemp "tempfile.XXXXXX.gdl")
77+
trap 'rm -f "$tmp_out"' EXIT
78+
79+
start_time=$(date +%s%3N)
80+
if ! "$sparrow_godel_script" "$output_file" -o "$tmp_out"; then
81+
echo "$lib_path lib compile error, please check it yourself" >&2
82+
exit 1
83+
fi
84+
85+
mv "$tmp_out" "$sparrow_lib_1_0/coref.$lib.gdl"
86+
87+
end_time=$(date +%s%3N)
88+
elapsed_time=$((end_time - start_time))
89+
echo "$lib_path lib compile success time: ${elapsed_time} milliseconds" >&2
90+
}
91+
92+
# Define get_language function
93+
get_language() {
94+
local dir="$1"
95+
local dirname
96+
local language
97+
98+
dirname=$(dirname "$dir")
99+
language=$(basename "$dirname")
100+
echo "$language"
101+
}
102+
103+
# Get libs directories
104+
directories=($(find "$PWD" -type d \( -path "$PWD/language/*/lib" -o -path "$PWD/language/*/libs" \) -print))
105+
106+
# Get libs
107+
for dir in "${directories[@]}"; do
108+
lang=$(get_language "$dir")
109+
echo "Building lib for $lang ..."
110+
rebuild_lib "$dir" "$lang"
111+
done
112+
113+
# Define get_target_files function
114+
get_target_files() {
115+
find "$1" -type f \( -name "*.gs" -o -name "*.gdl" \) -not -name "tempfile.*.gdl" -not -path "$1/language/*/lib/*"
116+
}
117+
118+
files=$(get_target_files "$PWD")
119+
120+
# Iterate over the files
121+
for file in $files; do
122+
output=$(("$sparrow_godel_script" "$file" -p "$sparrow_lib_1_0" -o "${file%.*}_tmp.gdl") 2>&1)
123+
124+
# Check if the output is not empty
125+
if [ -n "$output" ]; then
126+
echo "The file $file produced the following output:"
127+
echo "$output"
128+
echo "Please check if this file is a godel script (.gs) or a godel 1.0 script (.gdl)"
129+
exit 1
130+
else
131+
echo "$file build successful"
132+
fi
133+
134+
# Remove temporary file
135+
rm -f "${file%.*}_tmp.gdl"
136+
done
137+
138+
exit 0

0 commit comments

Comments
 (0)