@@ -24,17 +24,45 @@ jobs:
2424 - name : Checkout code
2525 uses : actions/checkout@v4
2626 with :
27- fetch-depth : 0
27+ submodules : recursive
2828
29- - name : Setup .NET
29+ - name : Setup .NET Core
3030 uses : actions/setup-dotnet@v4
3131 with :
32- dotnet-version : |
33- 8.0.x
34- 9.0.x
32+ dotnet-version : ${{ env.DOTNET_VERSION }}
3533
36- - name : Initialize submodules
37- run : git submodule update --init --recursive
34+ - name : Cache NuGet packages
35+ uses : actions/cache@v4
36+ with :
37+ path : ~/.nuget/packages
38+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props') }}
39+ restore-keys : |
40+ ${{ runner.os }}-nuget-
41+
42+ - name : Cache libpg_query build
43+ if : matrix.os != 'windows-latest'
44+ uses : actions/cache@v4
45+ with :
46+ path : |
47+ libpg_query/libpg_query.a
48+ libpg_query/pg_query.h
49+ libpg_query/.libs/
50+ libpg_query/src/
51+ key : ${{ runner.os }}-libpg_query-${{ hashFiles('libpg_query/**/*.c', 'libpg_query/**/*.h', 'libpg_query/Makefile') }}
52+ restore-keys : |
53+ ${{ runner.os }}-libpg_query-
54+
55+ - name : Cache native wrapper libraries
56+ if : matrix.os != 'windows-latest'
57+ uses : actions/cache@v4
58+ with :
59+ path : |
60+ libpgquery_wrapper.so
61+ libpgquery_wrapper.dylib
62+ src/PgQuery.NET/runtimes/
63+ key : ${{ runner.os }}-wrapper-${{ hashFiles('wrapper.c', 'libpg_query/libpg_query.a') }}
64+ restore-keys : |
65+ ${{ runner.os }}-wrapper-
3866
3967 - name : Build native libraries
4068 shell : bash
4674 exit 0
4775 fi
4876
49- cd libpg_query
50- make clean
51- make
52- cd ..
53-
54- # Determine platform and create wrapper
77+ # Determine platform
5578 if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
5679 LIBRARY_EXT="so"
5780 TARGET_RID="linux-x64"
6487 fi
6588 fi
6689
90+ # Check if wrapper library already exists (from cache)
91+ if [ -f "libpgquery_wrapper.$LIBRARY_EXT" ] && [ -f "src/PgQuery.NET/runtimes/$TARGET_RID/native/libpgquery_wrapper.$LIBRARY_EXT" ]; then
92+ echo "✅ Found cached native wrapper library - skipping expensive compilation"
93+ ls -la "libpgquery_wrapper.$LIBRARY_EXT"
94+ ls -la "src/PgQuery.NET/runtimes/$TARGET_RID/native/libpgquery_wrapper.$LIBRARY_EXT"
95+ exit 0
96+ fi
97+
98+ # Check if libpg_query is cached
99+ if [ ! -f "libpg_query/libpg_query.a" ]; then
100+ echo "🔨 Building libpg_query (this takes ~3-5 minutes)..."
101+ cd libpg_query
102+ make clean
103+ make
104+ cd ..
105+ else
106+ echo "✅ Found cached libpg_query - skipping compilation"
107+ ls -la libpg_query/libpg_query.a
108+ fi
109+
67110 # Create wrapper.c if it doesn't exist
68111 if [ ! -f "wrapper.c" ]; then
112+ echo "📝 Creating wrapper.c"
69113 cat > wrapper.c << 'EOF'
70114 #include "libpg_query/pg_query.h"
71115
@@ -114,6 +158,7 @@ jobs:
114158 fi
115159
116160 # Compile wrapper
161+ echo "🔨 Compiling native wrapper library..."
117162 if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
118163 gcc -shared -fPIC -I. -o "libpgquery_wrapper.so" wrapper.c libpg_query/libpg_query.a
119164 elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
@@ -124,11 +169,25 @@ jobs:
124169 mkdir -p "src/PgQuery.NET/runtimes/$TARGET_RID/native"
125170 if [ -f "libpgquery_wrapper.$LIBRARY_EXT" ]; then
126171 cp "libpgquery_wrapper.$LIBRARY_EXT" "src/PgQuery.NET/runtimes/$TARGET_RID/native/"
172+ echo "✅ Native library built and copied successfully"
173+ ls -la "libpgquery_wrapper.$LIBRARY_EXT"
127174 fi
128175
129176 - name : Restore dependencies
130177 run : dotnet restore
131178
179+ - name : Cache .NET build outputs
180+ uses : actions/cache@v4
181+ with :
182+ path : |
183+ src/**/bin/
184+ src/**/obj/
185+ tests/**/bin/
186+ tests/**/obj/
187+ key : ${{ runner.os }}-build-${{ hashFiles('**/*.csproj', '**/*.cs', '**/*.props') }}
188+ restore-keys : |
189+ ${{ runner.os }}-build-
190+
132191 - name : Build solution
133192 run : dotnet build --configuration Release --no-restore
134193
0 commit comments