diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..f9d007df --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,115 @@ +name: Build +defaults: + run: + shell: bash + +env: + SQLC_VERSION: 1.27.0 + WASI_SDK_VERSION: 22 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "*" ] + paths: + - "**" + - "!**.md" + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v4 + + - name: Set up .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "8.0.x" + + - name: .NET Lint + uses: zyactions/dotnet-lint@v1 + with: + implicit-restore: true + workspace: sqlc-gen-csharp.sln + exclude: | + GeneratedProtobuf + examples + + build-wasm: + name: Build (WASM) + needs: [lint] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + load-mode: strict + + - name: Setup Dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: install Wasi workload + run: dotnet workload install wasi-experimental + + - name: Setup Derived Variables + run: | + echo "WASI_SDK_FOLDER_NAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0" >> $GITHUB_ENV + echo "WASI_SDK_FILENAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz" >> $GITHUB_ENV + + - name: Download Wasi SDK + run: | + wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/${{ env.WASI_SDK_FILENAME }} + tar xf ${{ env.WASI_SDK_FILENAME }} + chmod -R 755 ${{ env.WASI_SDK_FILENAME }} + + - name: Dotnet Wasm Publish + shell: bash + run: | + set -e + WASI_SDK_PATH="$(pwd)/${{ env.WASI_SDK_FOLDER_NAME }}" dotnet publish WasmRunner -c release + ./scripts/wasm/copy_plugin_to.sh dist + + - name: upload wasm plugin as artifact + uses: actions/upload-artifact@v4 + with: + name: wasm-file + path: dist/plugin.wasm + + codegen-tests: + name: Codegen Tests + runs-on: ubuntu-latest + needs: [build-wasm] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: wasm-file + path: dist + + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + load-mode: strict + + - uses: sqlc-dev/setup-sqlc@v4 + with: + sqlc-version: '${{ env.SQLC_VERSION }}' + + - name: Updating plugin sha + run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml + + - name: Verify pushed generated code is synced + run: | + ./scripts/wasm/update_sha.sh sqlc.ci.yaml + sqlc -f sqlc.ci.yaml diff \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 3be28bec..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,230 +0,0 @@ -name: CI -defaults: - run: - shell: bash - -env: - SQLC_VERSION: 1.27.0 - WASI_SDK_VERSION: 22 - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "*" ] - paths: - - "**" - - "!**.md" - -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - name: Check out Git repository - uses: actions/checkout@v4 - - - name: Set up .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: "8.0.x" - - - name: .NET Lint - uses: zyactions/dotnet-lint@v1 - with: - implicit-restore: true - workspace: sqlc-gen-csharp.sln - exclude: | - GeneratedProtobuf - examples - - build-wasm: - name: Build (WASM) - needs: [lint] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Load .env file - uses: xom9ikk/dotenv@v2.3.0 - with: - load-mode: strict - - - name: Setup Dotnet - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.0.x' - - - name: install Wasi workload - run: dotnet workload install wasi-experimental - - - name: Setup Derived Variables - run: | - echo "WASI_SDK_FOLDER_NAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0" >> $GITHUB_ENV - echo "WASI_SDK_FILENAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz" >> $GITHUB_ENV - - - name: Download Wasi SDK - run: | - wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/${{ env.WASI_SDK_FILENAME }} - tar xf ${{ env.WASI_SDK_FILENAME }} - chmod -R 755 ${{ env.WASI_SDK_FILENAME }} - - - name: Dotnet Wasm Publish - shell: bash - run: | - set -e - WASI_SDK_PATH="$(pwd)/${{ env.WASI_SDK_FOLDER_NAME }}" dotnet publish WasmRunner -c release - ./scripts/wasm/copy_plugin_to.sh dist - - - name: upload wasm plugin as artifact - uses: actions/upload-artifact@v4 - with: - name: wasm-file - path: dist/plugin.wasm - - codegen-tests: - name: Codegen Tests - runs-on: ubuntu-latest - needs: [build-wasm] - - steps: - - uses: actions/checkout@v4 - - - uses: actions/download-artifact@v4 - with: - name: wasm-file - path: dist - - - name: Load .env file - uses: xom9ikk/dotenv@v2.3.0 - with: - load-mode: strict - - - uses: sqlc-dev/setup-sqlc@v4 - with: - sqlc-version: '${{ env.SQLC_VERSION }}' - - - name: Updating plugin sha - run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml - - - name: Verify pushed generated code is synced - run: | - ./scripts/wasm/update_sha.sh sqlc.ci.yaml - sqlc -f sqlc.ci.yaml diff - - end2end-tests: - name: End-to-End Tests - runs-on: ubuntu-latest - needs: [codegen-tests] - - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: wasm-file - path: dist - - - name: Unit Tests - run: dotnet test SqlcGenCsharpTests - - - uses: sqlc-dev/setup-sqlc@v4 - with: - sqlc-version: '${{ env.SQLC_VERSION }}' - - - name: Load .env file - uses: xom9ikk/dotenv@v2.3.0 - with: - load-mode: strict - - - name: Docker compose - uses: hoverkraft-tech/compose-action@v1.5.1 - - - name: End-to-End Tests - run: ./scripts/run_end2end_tests.sh - - legacy-end2end-tests: - # As this can run only on Windows machines, these tests should run only in CI - name: End-to-End Tests (Legacy) - runs-on: windows-latest - needs: [codegen-tests] - - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: wasm-file - path: dist - - - uses: sqlc-dev/setup-sqlc@v4 - with: - sqlc-version: '${{ env.SQLC_VERSION }}' - - - name: Load .env file - uses: xom9ikk/dotenv@v2.3.0 - with: - load-mode: strict - - - name: Setup Visual Studio for .NET Framework - uses: microsoft/setup-msbuild@v1 - with: - vs-version: 'latest' - - - name: Setup NuGet - uses: NuGet/setup-nuget@v2.0.1 - - - name: Install Chocolatey - shell: powershell - run: | - Set-ExecutionPolicy Bypass -Scope Process -Force - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 - iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) - - - uses: ikalnytskyi/action-setup-postgres@v7 - with: - username: ${{ env.POSTGRES_USER }} - password: ${{ env.POSTGRES_PASSWORD }} - database: ${{ env.TESTS_DB }} - postgres-version: "16" - id: postgres - - - name: Init PostgresSQL Schema - shell: powershell - run: psql -U $Env:POSTGRES_USER -f 'examples/config/postgresql/schema.sql' - env: - PGSERVICE: ${{ steps.postgres.outputs.service-name }} - PGPASSWORD: ${{ env.POSTGRES_PASSWORD }} - - - name: Install MySQL and restore test projects in parallel - shell: pwsh - run: | - $mysql_job = Start-Job -ScriptBlock { - choco install mysql --no-progress --version=8.0.31 -y --params "/serviceName:MySQL" - } - $restore_job = Start-Job -ScriptBlock { - Get-ChildItem -Path examples -Recurse -Filter *.csproj | - Where-Object { $_.FullName -like '*Legacy*' } | - ForEach-Object { nuget restore $_.FullName } - nuget restore ./LegacyEndToEndTests/LegacyEndToEndTests.csproj - msbuild.exe ./LegacyEndToEndTests/LegacyEndToEndTests.csproj -p:Configuration=Release -p:FrameworkVersion=v4.7.2 - } - - Wait-Job -Job $mysql_job, $restore_job - Receive-Job -Job $mysql_job - Receive-Job -Job $restore_job - - - name: Init MySQL Schema - shell: powershell - run: | - $env:Path += ";C:\Program Files\MySQL\MySQL Server 8.0\bin" - [Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine") - mysql -u root -e "CREATE DATABASE $Env:TESTS_DB;" - mysql -u root $Env:TESTS_DB --execute="source examples/config/mysql/schema.sql" - - - name: End-to-End Tests - shell: powershell - run: | - $path = vswhere -latest -products * -requires Microsoft.VisualStudio.Workload.ManagedDesktop Microsoft.VisualStudio.Workload.Web -requiresAny -property installationPath - $path = join-path $path 'Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe' - & $path ./LegacyEndToEndTests/bin/Release/net472/LegacyEndToEndTests.dll \ No newline at end of file diff --git a/.github/workflows/legacy-tests.yml b/.github/workflows/legacy-tests.yml new file mode 100644 index 00000000..27216b37 --- /dev/null +++ b/.github/workflows/legacy-tests.yml @@ -0,0 +1,90 @@ +name: .Net Framework Tests (Legacy) +defaults: + run: + shell: bash + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "*" ] + paths: + - "**" + - "!**.md" + +jobs: + # As this can run only on Windows machines, these tests should run only in CI + end2end-tests: + name: End-to-End Tests + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + load-mode: strict + + - name: Setup Visual Studio for .NET Framework + uses: microsoft/setup-msbuild@v1 + with: + vs-version: 'latest' + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2.0.1 + + - name: Install Chocolatey + shell: powershell + run: | + Set-ExecutionPolicy Bypass -Scope Process -Force + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 + iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + + - uses: ikalnytskyi/action-setup-postgres@v7 + with: + username: ${{ env.POSTGRES_USER }} + password: ${{ env.POSTGRES_PASSWORD }} + database: ${{ env.TESTS_DB }} + postgres-version: "16" + id: postgres + + - name: Init PostgresSQL Schema + shell: powershell + run: psql -U $Env:POSTGRES_USER -f 'examples/config/postgresql/schema.sql' + env: + PGSERVICE: ${{ steps.postgres.outputs.service-name }} + PGPASSWORD: ${{ env.POSTGRES_PASSWORD }} + + - name: Install MySQL and restore test projects in parallel + shell: pwsh + run: | + $mysql_job = Start-Job -ScriptBlock { + choco install mysql --no-progress --version=8.0.31 -y --params "/serviceName:MySQL" + } + $restore_job = Start-Job -ScriptBlock { + Get-ChildItem -Path examples -Recurse -Filter *.csproj | + Where-Object { $_.FullName -like '*Legacy*' } | + ForEach-Object { nuget restore $_.FullName } + nuget restore ./LegacyEndToEndTests/LegacyEndToEndTests.csproj + msbuild.exe ./LegacyEndToEndTests/LegacyEndToEndTests.csproj -p:Configuration=Release -p:FrameworkVersion=v4.7.2 + } + + Wait-Job -Job $mysql_job, $restore_job + Receive-Job -Job $mysql_job + Receive-Job -Job $restore_job + + - name: Init MySQL Schema + shell: powershell + run: | + $env:Path += ";C:\Program Files\MySQL\MySQL Server 8.0\bin" + [Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine") + mysql -u root -e "CREATE DATABASE $Env:TESTS_DB;" + mysql -u root $Env:TESTS_DB --execute="source examples/config/mysql/schema.sql" + + - name: Run Tests + shell: powershell + run: | + $path = vswhere -latest -products * -requires Microsoft.VisualStudio.Workload.ManagedDesktop Microsoft.VisualStudio.Workload.Web -requiresAny -property installationPath + $path = join-path $path 'Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe' + & $path ./LegacyEndToEndTests/bin/Release/net472/LegacyEndToEndTests.dll \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7903c666..4f0ba5cf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ permissions: on: workflow_run: - workflows: [CI] + workflows: [Build] types: [completed] branches: [main] diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..47332900 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,42 @@ +name: .Net Core Tests +defaults: + run: + shell: bash + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "*" ] + paths: + - "**" + - "!**.md" + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Run Tests + run: dotnet test SqlcGenCsharpTests + + end2end-tests: + name: End-to-End Tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + load-mode: strict + + - name: Docker compose + uses: hoverkraft-tech/compose-action@v1.5.1 + + - name: Run Tests + run: ./scripts/run_end2end_tests.sh \ No newline at end of file diff --git a/docs/01_Intro.md b/docs/01_Intro.md index c078ec86..4ad3cc37 100644 --- a/docs/01_Intro.md +++ b/docs/01_Intro.md @@ -1,5 +1,9 @@ #

sqlc-gen-csharp

-

CI

+

+ Build + .Net Core Tests + .Net Framework Tests (Legacy) +

sqlc-gen-csharp is a .Net plugin for [sqlc](https://github.com/sqlc-dev/sqlc).
It leverages the SQLC plugin system to generate type-safe C# code for SQL queries, supporting PostgresSQL, MySQL & SQLite via the corresponding driver or suitable Dapper abstraction.