Skip to content

Commit

Permalink
ci: update github action
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Nov 27, 2024
1 parent 65184e3 commit cfe43b4
Show file tree
Hide file tree
Showing 19 changed files with 5,381 additions and 46 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ env:
# FEED_SOURCE: https://api.nuget.org/v3/index.json
# FEED_API_KEY: ${{ secrets.FEED_API_KEY }}
GHC_API_KEY: ${{ secrets.GHC_TOKEN }}
NuGetDirectory: ${{ github.workspace }}/nuget
NuGetDirectory: nuget
BuildOutput: bin/Release/net8.0/

jobs:

Expand Down Expand Up @@ -46,16 +47,18 @@ jobs:
- name: Build Tree-Sitter binaries on ${{ matrix.os }}
run: |
if [[ "$(uname)" == "Linux" ]]; then
chmod +x ./scripts/install_tree_sitter.sh
chmod +x ./scripts/ci_install_tree_sitter.sh
fi
./scripts/install_tree_sitter.sh Release net8.0
./scripts/ci_install_tree_sitter.sh
shell: bash

- name: Upload compiled binaries
uses: actions/upload-artifact@v4
with:
name: tree-sitter-binaries-${{ matrix.os }}
path: tree-sitter/bins/*
path: |
tree-sitter/bins/*
tree-sitter/grammars/bins/*
create-nuget:
runs-on: ubuntu-latest
Expand All @@ -82,13 +85,13 @@ jobs:
uses: actions/download-artifact@v4
with:
name: tree-sitter-binaries-ubuntu-latest
path: ${{ env.NuGetDirectory }}
path: ${{ env.BuildOutput }}

- name: Download Windows binaries
uses: actions/download-artifact@v4
with:
name: tree-sitter-binaries-windows-latest
path: ${{ env.NuGetDirectory }}
path: -o ${{ env.BuildOutput }}

# https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/doc/nbgv-cli.md
- name: Install Nerdbank.GitVersioning
Expand All @@ -102,14 +105,19 @@ jobs:
echo "::set-output name=nuget_version::$nugetVersion"
- name: Restore dependencies
run: dotnet restore AIAssistant.sln
run: dotnet restore src/AIAssist/AIAssist.csproj

- name: Build Version
run: dotnet build AIAssistant.sln -c Release --no-restore
run: dotnet build src/AIAssist/AIAssist.csproj -o ${{ env.BuildOutput }} -c Release --no-restore

- name: List files in BuildOutput
run: |
echo "Listing files in ${{ env.BuildOutput }}:"
ls -la ${{ env.BuildOutput }}
# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack
- name: Pack NuGet Package Version ${{ steps.get_version.outputs.nuget_version }}
run: dotnet pack --no-restore src/AIAssist/AIAssist.csproj -c Release -o ${{ env.NuGetDirectory }}
run: dotnet pack src/AIAssist/AIAssist.csproj -o ${{ env.NuGetDirectory }} -c Release --no-restore --no-build
# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -151,6 +159,7 @@ jobs:
nugetVersion=$(nbgv get-version | grep "NuGetPackageVersion" | awk -F': ' '{print $2}' | xargs)
echo "NuGetPackageVersion: $nugetVersion"
echo "::set-output name=nuget_version::$nugetVersion"
# for publish package to github for each commit
- name: Publish NuGet Package Version ${{ steps.get_version.outputs.nuget_version }} to GitHub
run: dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ env.GHC_API_KEY }} --source ${{ env.GHC_SOURCE }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@ env

.git/

temp/
temp/
nuget/
1 change: 1 addition & 0 deletions AIAssistant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{0A4F
ProjectSection(SolutionItems) = preProject
scripts\install_tree_sitter.sh = scripts\install_tree_sitter.sh
scripts\generate_tree_sitter_bindings.sh = scripts\generate_tree_sitter_bindings.sh
scripts\ci_install_tree_sitter.sh = scripts\ci_install_tree_sitter.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TreeSitter.Bindings", "TreeSitter.Bindings", "{E295F56D-BF6F-4725-96E5-617DED7E0E21}"
Expand Down
54 changes: 24 additions & 30 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<RepositoryType>git</RepositoryType>
<PackageId>$(AssemblyName)</PackageId>
<Product>AIAssist</Product>
<Title>AIAssist</Title>
<Authors>Mehdi Hadeli</Authors>
<Description>Context aware AI coding assistant inside terminal to help in code development, code explanation, code refactor and review, bug fix and chat with supporting local and online language models.</Description>
<PackageTags>ai ollama gpt pgt-4o dotnet csharp azure-ai</PackageTags>
<PackageOutputPath>$(SolutionDir)nugets</PackageOutputPath>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageIcon>aiassist.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/mehdihadeli/AIAssist</PackageProjectUrl>
<RepositoryUrl>https://github.com/mehdihadeli/AIAssist</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>main</RepositoryBranch>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EnablePackageValidation>true</EnablePackageValidation>
<Copyright>Copyright (c) 2024 Mehdi Hadeli</Copyright>
</PropertyGroup>
<PropertyGroup>
<RepositoryType>git</RepositoryType>
<PackageId>$(AssemblyName)</PackageId>
<Product>AIAssist</Product>
<Title>AIAssist</Title>
<Authors>Mehdi Hadeli</Authors>
<Description>Context aware AI coding assistant inside terminal to help in code development, code explanation, code refactor and review, bug fix and chat with supporting local and online language models.</Description>
<PackageTags>ai ollama gpt pgt-4o dotnet csharp azure-ai</PackageTags>
<PackageOutputPath>$(SolutionDir)nugets</PackageOutputPath>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageIcon>aiassist.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/mehdihadeli/AIAssist</PackageProjectUrl>
<RepositoryUrl>https://github.com/mehdihadeli/AIAssist</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>main</RepositoryBranch>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EnablePackageValidation>true</EnablePackageValidation>
<Copyright>Copyright (c) 2024 Mehdi Hadeli</Copyright>
</PropertyGroup>

<ItemGroup>
<!-- <None Include="assets/aiassist.png" Visible="false" Pack="true" PackagePath="" />-->
<None Include="LICENSE" Visible="false" Pack="true" PackagePath="" />
<None Include="README.md" Visible="false" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.146" PrivateAssets="all" Condition="!Exists('packages.config')"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.146" PrivateAssets="all" Condition="!Exists('packages.config')"/>
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
> [!TIP]
> You can use ollama and its models that are more compatible with code like [deepseek-v2.5](https://ollama.com/library/deepseek-v2.5) or [qwen2.5-coder](https://ollama.com/library/qwen2.5-coder) locally. To use local models, you will need to run [Ollama](https://github.com/ollama/ollama) process first. For running ollama you can use [ollama docker](https://ollama.com/blog/ollama-is-now-available-as-an-official-docker-image) container.
Note: `vscode` and `jetbrains` plugins are in the plan and I will add them soon.
> [!NOTE]
> Development of `vscode` and `jetbrains` plugins are in the plan and I will add them soon.
## Features

Expand Down
161 changes: 161 additions & 0 deletions scripts/ci_install_tree_sitter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/bin/bash

# Create tree-sitter folder structure
mkdir -p tree-sitter/grammars/bins
mkdir -p tree-sitter/bins

# Get the OS type
OS=$(uname -s)

# Define paths for the source files and output binary
lib_src="tree-sitter/tree-sitter/lib/src/lib.c"

# Check for Linux
if [[ "$OS" == "Linux" ]]; then
echo "Detected Linux OS. Compiling for Linux..."

# Array of output files
linux_tree_sitter_output_files=("${treesitter_bin_output}/tree-sitter.so")

# Iterate over the arrays
for i in "${!linux_tree_sitter_output_files[@]}"; do
echo "Compiling ${linux_tree_sitter_output_files[$i]}..."
gcc -o "${linux_tree_sitter_output_files[$i]}" -shared "$lib_src" -I./tree-sitter/tree-sitter/lib/src -I./tree-sitter/tree-sitter/lib/include -fPIC
if [ $? -eq 0 ]; then
echo "Successfully compiled tree-sitter.so"
else
echo "Error during compilation of tree-sitter.so"
exit 1
fi
done
# Check for Windows (MINGW or MSYS environments)
elif [[ "$OS" == "MINGW"* || "$OS" == "MSYS"* ]]; then
echo "Detected Windows OS. Compiling for Windows..."

# Array of output files
windows_tree_sitter_output_files=("${treesitter_bin_output}/tree-sitter.dll")

# Iterate over the arrays
for i in "${!windows_tree_sitter_output_files[@]}"; do
echo "Compiling ${windows_tree_sitter_output_files[$i]}..."
gcc -o "${windows_tree_sitter_output_files[$i]}" -shared "$lib_src" -I./tree-sitter/tree-sitter/lib/src -I./tree-sitter/tree-sitter/lib/include
if [ $? -eq 0 ]; then
echo "Successfully compiled tree-sitter.dll"
else
echo "Error during compilation of tree-sitter.dll"
exit 1
fi
done
# Unsupported OS
else
echo "Unsupported operating system: $OS"
exit 1
fi

# File containing the list of URLs
grammar_file="tree-sitter/tree-sitter-grammar.txt"

# Check if the grammar file exists
if [ ! -f "$grammar_file" ]; then
echo "Error: File $grammar_file not found!"
exit 1
fi

# Read the list of URLs from the file into an array, skipping empty lines and stopping at the first empty line
repos=()
while IFS= read -r line; do
# Trim leading/trailing whitespace and check if the line is empty
trimmed_line=$(echo "$line" | xargs)

if [ -z "$trimmed_line" ]; then
# Stop parsing when an empty line is encountered
break
fi

# Add the non-empty line to the repos array
repos+=("$trimmed_line")
done < "$grammar_file"


# Iterate over each URL in the list and perform operations
for repo in "${repos[@]}"; do
echo "Processing repository: $repo"

# Get the repository name from the URL by extracting everything after the last /
repo_name=$(basename "$repo")

# Trim any trailing or leading whitespace (including newlines) from repo_name
repo_name=$(echo "$repo_name" | tr -d '[:space:]')

echo "Repository name (trimmed): $repo_name"

# Define paths for the source files and output binary
scanner_src="tree-sitter/grammars/$repo_name/src/scanner.c"
parser_src="tree-sitter/grammars/$repo_name/src/parser.c"
grammar_bin_output="tree-sitter/grammars/bins"

# Debugging: print paths to ensure correctness
echo "Scanner source path: $scanner_src"
echo "Parser source path: $parser_src"

# Check if source files exist
if [[ ! -f "$scanner_src" && ! -f "$parser_src" ]]; then
echo "Error: both scanner.c and parser.c files not found for $repo_name!"
continue
fi

# Check if parser.c exists (it should always exist)
if [ ! -f "$parser_src" ]; then
echo "Error: parser.c not found for $repo_name!"
continue
fi

# Prepare the GCC command based on available files
if [ -f "$scanner_src" ]; then
inputs="$scanner_src $parser_src"
else
inputs="$parser_src"
fi

# Run the appropriate gcc command based on the OS
if [[ "$OS" == "Linux" ]]; then
echo "Detected Linux OS. Compiling for Linux..."

# Array of output files
linux_grammar_output_files=("${grammar_bin_output}/${repo_name}.so")

# Iterate over the arrays
for i in "${!linux_grammar_output_files[@]}"; do
echo "Compiling ${linux_grammar_output_files[$i]}..."
gcc -o "${linux_grammar_output_files[$i]}" -shared $inputs -fPIC
if [ $? -eq 0 ]; then
echo "Successfully compiled ${repo_name}.so"
else
echo "Error during compilation of ${repo_name}.so"
exit 1
fi
done
elif [[ "$OS" == "MINGW"* || "$OS" == "MSYS"* ]]; then
echo "Detected Windows OS. Compiling for Windows..."

# Array of output files
windows_grammar_output_files=("${grammar_bin_output}/${repo_name}.dll")

# Iterate over the arrays
for i in "${!windows_grammar_output_files[@]}"; do
echo "Compiling ${windows_grammar_output_files[$i]}..."
gcc -o "${windows_grammar_output_files[$i]}" -shared $inputs
if [ $? -eq 0 ]; then
echo "Successfully compiled ${repo_name}.dll"
else
echo "Error during compilation of ${repo_name}.dll"
exit 1
fi
done
else
echo "Unsupported operating system: $OS"
exit 1
fi

echo "Compilation complete for: $repo_name"
done
31 changes: 31 additions & 0 deletions src/AIAssist/AIAssist.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- dotnet tool install &#45;&#45;global AIAssist &#45;&#45;version 1.0.0 &#45;&#45;add-source .-->
<!-- dotnet tool uninstall &#45;&#45;global AIAssist &#45;&#45;version 1.0.0-->
<!-- dotnet pack AIAssist.csproj -o nuget -c Debug-->

<PropertyGroup>
<PackAsTool>true</PackAsTool>
<ToolCommandName>aiassist</ToolCommandName>
<OutputType>Exe</OutputType>
<RootNamespace>AIAssist</RootNamespace>
</PropertyGroup>
Expand Down Expand Up @@ -39,4 +45,29 @@
<EmbeddedResource Include=".aiassistignore" />
</ItemGroup>

<!-- <ItemGroup>-->
<!-- <None Remove="DotnetToolSettings.xml" />-->
<!-- <Content Include="DotnetToolSettings.xml">-->
<!-- <CopyToOutputDirectory>Always</CopyToOutputDirectory>-->
<!-- </Content>-->
<!-- </ItemGroup>-->

<ItemGroup>
<!-- <None Include="assets/aiassist.png" Visible="false" Pack="true" PackagePath="" />-->
<None Include="../../LICENSE" Visible="false" Pack="true" PackagePath=""/>
<None Include="../../README.md" Pack="true" PackagePath=""/>
</ItemGroup>

<!-- Include native libraries during pack -->
<ItemGroup>
<Content Include="bin\$(Configuration)\$(TargetFramework)\tree-sitter*.dll">
<Pack>true</Pack>
<PackagePath>tools\$(TargetFramework)\any</PackagePath>
</Content>
<Content Include="bin\$(Configuration)\$(TargetFramework)\tree-sitter*.so">
<Pack>true</Pack>
<PackagePath>tools\$(TargetFramework)\any</PackagePath>
</Content>
</ItemGroup>

</Project>
Loading

0 comments on commit cfe43b4

Please sign in to comment.