-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathjustfile
More file actions
320 lines (275 loc) · 11.3 KB
/
justfile
File metadata and controls
320 lines (275 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# https://just.systems
# Path to the CLI project
cli_project := "ShopifySharp.GraphQL.Parser.CLI"
# Path to the generated GraphQL entitites folder
graph_entities := "ShopifySharp/Entities/GraphQL/Generated"
# Space-separated list of class names that test the GraphQL query builders
query_builder_tests := "ProductQueryTests QueryBuilderTests QueryBuilderMutationTests GraphHttpContentSerializerTests GraphQueryBuilderTests GraphUnionTypeConverterTests UnionCasesBuilderBaseTests"
# Build configuration
config := "Release"
# Dotnet verbosity
verbosity := "minimal"
# Test frameworks
netCoreApp := "net10.0"
netFramework := "net472"
default:
just --list
[private]
[script]
_buildCliProject:
if [ ! -d "{{cli_project}}/bin/Release" ]; then
dotnet build --configuration Release ./ShopifySharp.GraphQL.Parser.CLI/
fi
# Builds and packages the project for both prerelease and release configurations.
[private]
_buildAndPack project revision outputDir:
dotnet pack \
-c "{{config}}" \
--version-suffix "{{revision}}" \
-o "{{outputDir}}" \
--verbosity "{{verbosity}}" \
"{{project}}"
dotnet pack \
-c "{{config}}" \
-o "{{outputDir}}" \
--verbosity "{{verbosity}}" \
"{{project}}"
[private]
_cleanGraphEntities:
rm -r "{{graph_entities}}"
# Clean generated files
[group("graphql")]
clean:
git clean -df "{{graph_entities}}"
git checkout "{{graph_entities}}"
# Regenerates GraphQL types from the graphql.schema.graphql file
[group("graphql")]
[arg("noBuild", long="no-build", value="1")]
regenerate schemaFile="graphql.schema.graphql" noBuild="false": clean _cleanGraphEntities _buildCliProject
dotnet run {{if noBuild == "1" {"--no-build"} else { "" } }} \
--configuration Release \
--project "{{cli_project}}" \
-- \
generate \
--nullable true \
--casing camel \
-t "{{graph_entities}}/Types" \
-b "{{graph_entities}}/QueryBuilders" \
"{{ schemaFile }}"
# Regenerates GraphQL types and then builds the ShopifySharp project to ensure they're valid
[group("graphql")]
[arg("noBuild", long="no-build", value="1")]
regenerate-and-build schemaFile="graphql.schema.graphql" noBuild="false": clean (regenerate schemaFile noBuild)
dotnet build --configuration Release "./ShopifySharp/"
[group("graphql")]
[arg("version", long="api-version")]
[arg("domain", long)]
[arg("token", long)]
[arg("output", long)]
download-graphql-schema version domain token output="": _buildCliProject
#!/usr/bin/env bash
set -euo pipefail
output_file="{{ if output == "" { version + ".schema.json" } else { output } }}"
dotnet run --no-build \
--configuration Release \
--project "{{cli_project}}" \
-- \
download \
-o "$output_file" \
--api-version "{{version}}" \
--domain "{{domain}}" \
--token "{{token}}"
# Converts a .json GraphQL schema to .graphql
[group("graphql")]
[arg("jsonSchemaFile", long="input")]
[arg("graphqlSchemaFile", long="output")]
convert-graphql-schema jsonSchemaFile graphqlSchemaFile:
npx -- graphql-json-to-sdl@0.5.0 "{{jsonSchemaFile}}" "{{graphqlSchemaFile}}"
# Creates a pull request containing any changes to the graphql schema file and in the generated GraphQL types folder
[group("graphql")]
[script]
[arg("token", long)]
[arg("graphqlSchemaFile", long="graph-schema-file")]
[arg("jsonSchemaFile", long="json-schema-file")]
create-graphql-pr graphqlSchemaFile jsonSchemaFile token="":
# Use --token if provided, otherwise fall back to GH_TOKEN from environment
if [ -n "{{token}}" ]; then
export GH_TOKEN="{{token}}"
elif [ -z "${GH_TOKEN:-}" ]; then
echo "Error: GitHub token not provided. Either pass --token or set GH_TOKEN environment variable."
exit 1
fi
branch_name="graphql-types-update-$(date +%Y%m%d-%H%M%S)"
echo "Creating branch: $branch_name"
git switch -C "$branch_name"
git add ShopifySharp/Entities/GraphQL/Generated/
git add "{{graphqlSchemaFile}}"
git add "{{jsonSchemaFile}}"
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Add/update GraphQL schema and generated GraphQL types
Generated via automated workflow."
git push origin "$branch_name"
# Extract API version from schema filename (e.g., "graphql-schemas/2026-01.schema.graphql" -> "2026-01")
api_version=$(basename "{{graphqlSchemaFile}}" | sed 's/\.schema\.graphql$//')
gh pr create \
--title "Update GraphQL schema and generated types to API version $api_version" \
--body "## Summary
- Added/updated GraphQL schema \`{{graphqlSchemaFile}}\`
- Cleaned output directory before generation
- Updated GraphQL types generated from schema using ShopifySharp.GraphQL.Parser.CLI
🤖 Generated via the [Regenerate GraphQL Types](https://github.com/nozzlegear/ShopifySharp/blob/master/.github/workflows/regenerate-graphql-types.yaml) workflow." \
--base master \
--head "$branch_name"
# Build and pack projects for prerelease and release
[group("build")]
@build-and-pack runNumber outputDir:
echo "Building and packing projects with revision: {{runNumber}}"
echo "Output directory: {{outputDir}}"
# TODO: only pack projects that have git changes? (Only if this is running in a workflow.)
just _buildAndPack "ShopifySharp/ShopifySharp.csproj" "b{{runNumber}}" "{{outputDir}}"
just _buildAndPack "ShopifySharp.Extensions.DependencyInjection/ShopifySharp.Extensions.DependencyInjection.csproj" "b{{runNumber}}" "{{outputDir}}"
# Run .NET Framework unit tests
[group("test")]
test-dnf:
@echo "Testing .NET Framework tests..."
dotnet test \
-c "{{config}}" \
-f "{{netFramework}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=DotNetFramework.trx" \
--results-directory "TestResults" \
--filter "Category=DotNetFramework" \
"ShopifySharp.Tests/ShopifySharp.Tests.csproj"
@echo ""
@echo ".NET Framework tests passed."
# Run tests on the DI project.
[group("test")]
test-di:
@echo "Testing ShopifySharp.Extensions.DependencyInjection..."
dotnet test \
-c "{{config}}" \
-f "{{netCoreApp}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=ShopifySharp.Extensions.DependencyInjection.trx" \
--results-directory "TestResults" \
"ShopifySharp.Extensions.DependencyInjection.Tests/ShopifySharp.Extensions.DependencyInjection.Tests.csproj"
@echo ""
@echo "ShopifySharp.Extensions.DependencyInjection tests passed."
# Run integration tests.
[group("test")]
test-integration:
@echo "Testing integration project..."
dotnet test \
-c "{{config}}" \
-f "{{netCoreApp}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=ShopifySharp.Integration.Tests.trx" \
--results-directory "TestResults" \
"ShopifySharp.Tests.Integration/ShopifySharp.Tests.Integration.csproj"
@echo ""
@echo "Integration tests passed."
[private]
_test-query-builder-integrations:
dotnet test \
-c "{{config}}" \
-f "{{netCoreApp}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=ShopifySharp.GraphQL.QueryBuilders.Integrations.Tests.trx" \
--results-directory "TestResults" \
--filter "FullyQualifiedName~{{ replace(query_builder_tests, " ", "|") }}" \
"ShopifySharp.Tests.Integration/ShopifySharp.Tests.Integration.csproj"
# Run tests on the GraphQL query builders.
[group("test")]
[arg("skipIntegrationTests", long="skip-integration-tests", value="true")]
test-query-builders skipIntegrationTests="false":
@echo "Testing GraphQL query builders..."
dotnet test \
-c "{{config}}" \
-f "{{netCoreApp}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=ShopifySharp.GraphQL.QueryBuilders.Tests.trx" \
--results-directory "TestResults" \
--filter "FullyQualifiedName~{{ replace(query_builder_tests, " ", "|") }}" \
"ShopifySharp.Tests/ShopifySharp.Tests.csproj"
{{ if skipIntegrationTests != "true" { "just _test-query-builder-integrations" } else { "" } }}
@echo ""
@echo "Query builder tests passed."
# Run unit tests on the main ShopifySharp project.
[group("test")]
test-main-project:
@echo "Testing main project..."
dotnet test \
-c "{{config}}" \
-f "{{netCoreApp}}" \
--verbosity "{{verbosity}}" \
--logger "trx;LogFileName=ShopifySharp.Tests.trx" \
--results-directory "TestResults" \
--filter "Category!=DotNetFramework" \
"ShopifySharp.Tests/ShopifySharp.Tests.csproj"
@echo ""
@echo "Main project tests passed."
# Run all tests (DI, integration, and unit tests)
[group("test")]
test-everything: test-di test-integration test-main-project
@echo "All tests passed."
# Set package version for a project (used in release workflow)
[group("release")]
[script]
set-package-version version packageId:
projectFile="{{packageId}}/{{packageId}}.csproj"
echo "Setting version {{version}} for {{packageId}}"
# Requires the dotnet-setversion tool
setversion -p "{{version}}" "$projectFile"
# Publish packages to NuGet
[group("release")]
[script]
publish-to-nuget releaseType nugetToken artifactsDir:
if [ "{{releaseType}}" = "--prerelease" ]; then
echo "Publishing prerelease packages to NuGet..."
# Prerelease packages have a `-b*.nupkg` suffix
dotnet nuget push \
--skip-duplicate \
-k "{{nugetToken}}" \
-s "https://api.nuget.org/v3/index.json" \
"{{artifactsDir}}"/*-b*.nupkg
elif [ "{{releaseType}}" = "--full-release" ]; then
echo "Publishing full release packages to NuGet..."
# Full release packages don't have a suffix (i.e. exclude -b*.nupkg)
for package in "{{artifactsDir}}"/*.nupkg; do
case "$package" in
*-b[0-9]*.nupkg) continue ;;
esac
dotnet nuget push \
--skip-duplicate \
-k "{{nugetToken}}" \
-s "https://api.nuget.org/v3/index.json" \
"$package"
done
else
echo "Error: Invalid release type. Use --prerelease or --full-release"
exit 1
fi
echo "Publish complete."
# Generate service factory classes from T4 template
[group("build")]
[script]
generate-factories:
template_path="ShopifySharp/Factories/FactoryServiceTemplate.tt"
if [ ! -f "$template_path" ]; then
echo "Error: Template file at $template_path does not exist."
exit 1
fi
echo "Generating service factories from template..."
for service_file in ShopifySharp/Services/*/I*Service.cs; do
# Extract service name from interface definition (e.g., "public interface IProductService" -> "ProductService")
service_name=$(rg -o -e "public interface I([A-Z]\w+)Service" "$service_file" | sed 's/public interface I//')
if [ -n "$service_name" ]; then
echo "Generating ${service_name}Factory..."
factory_file_name="ShopifySharp/Factories/${service_name}Factory.cs"
dotnet t4 -p "TypeName=${service_name}" -o "$factory_file_name" "$template_path"
fi
done
echo "Factory generation complete."