Skip to content

Commit

Permalink
Merge pull request #9 from Theauxm/feature/actions_release
Browse files Browse the repository at this point in the history
1.3.0 -- Actions NuGet/Testing
  • Loading branch information
Theauxm authored Aug 8, 2024
2 parents fb38797 + c2fc818 commit df93f88
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 88 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"CSharpier": {
"version": "0.26.7",
"commands": [
"dotnet-csharpier"
]
}
}
}
81 changes: 81 additions & 0 deletions .github/workflows/nuget_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Release NuGet Package

on:
push:
branches:
- main
paths:
- 'Directory.Build.props'

permissions:
contents: write # Ensure the token has write permissions to contents

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.204'

- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Build.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Verify version change
id: version
run: |
props_file="Directory.Build.props"
version_line=$(grep '<Version>' $props_file)
new_version=$(echo $version_line | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
echo "New version: $new_version"
git fetch --tags
last_tag=$(git tag --sort=-creatordate | head -n 1)
echo "Last tag: $last_tag"
if [ "$new_version" == "${last_tag#v}" ]; then
echo "Version has not changed. Exiting."
exit 0
fi
echo "Version has changed. Proceeding."
- name: Build project
run: dotnet build --configuration Release

- name: Pack NuGet package
run: dotnet pack --configuration Release --no-build --output ./nupkgs

- name: Publish NuGet package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./nupkgs/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
new_version=$(grep '<Version>' Directory.Build.props | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag v$new_version
git push origin v$new_version
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v'${new_version}'",
"target_commitish": "main",
"name": "v'${new_version}'",
"body": "Release of version '${new_version}'",
"draft": false,
"prerelease": false
}'
53 changes: 53 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "GraphQL-Client: Run CI/CD Test Suite"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- "main"
push:
branches:
- "main"

# Allow manual runs
workflow_dispatch: ~

env:
DOTNET_VERSION: '8.0.204' # The .NET SDK version to use

jobs:
cleanupcode:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install tools
run: dotnet tool restore

- name: Cleanup Code
run: dotnet dotnet-csharpier --check .

test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Build Project
run: dotnet build --configuration Release /clp:ErrorsOnly

- name: Run Tests
run: dotnet test --configuration Release --no-restore /clp:ErrorsOnly
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.3.0</Version>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# GraphQL-Client
C# GraphQL Client

[![Build Status](https://github.com/Theauxm/ChainSharp/workflows/Release%20NuGet%20Package/badge.svg)](https://github.com/Theauxm/GraphQL-Client/actions)
[![Test Status](https://github.com/Theauxm/ChainSharp/workflows/ChainSharp:%20Run%20CI/CD%20Test%20Suite/badge.svg)](https://github.com/Theauxm/GraphQL-Client/actions)
26 changes: 14 additions & 12 deletions src/GraphQL-Client/Configuration/GraphQLClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ namespace GraphQL;
public class GraphQLClientConfiguration : IGraphQLClientConfiguration
{
public GraphQLClientConfiguration(
Uri baseAddress,
IGraphQLWebsocketJsonSerializer jsonSerializer,
GraphQLHttpClientOptions graphQLHttpClientOptions,
JsonSerializerOptions jsonSerializerOptions,
bool disposeHttpClient,
bool validateAssemblies,
HttpClient httpClient)
Uri baseAddress,
IGraphQLWebsocketJsonSerializer jsonSerializer,
GraphQLHttpClientOptions graphQLHttpClientOptions,
JsonSerializerOptions jsonSerializerOptions,
bool disposeHttpClient,
bool validateAssemblies,
HttpClient httpClient
)
{
HttpClient = httpClient;
HttpClient.BaseAddress = baseAddress;
Expand All @@ -27,20 +28,21 @@ public GraphQLClientConfiguration(
GraphQLHttpClient = new GraphQLHttpClient(
serializer: jsonSerializer,
options: graphQLHttpClientOptions,
httpClient: httpClient);
httpClient: httpClient
);
}

public IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; init; }

public JsonSerializerOptions JsonSerializerOptions { get; init; }

public GraphQLHttpClientOptions GraphQLClientOptions { get; init; }
public GraphQLHttpClientOptions GraphQLClientOptions { get; init; }

public bool ValidateAssemblies { get; init; }

public GraphQLHttpClient GraphQLHttpClient { get; }

public HttpClient HttpClient { get; init; }

public bool DisposeHttpClient { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace GraphQL;

public class GraphQLClientConfigurationBuilder(Uri baseAddress)
{
public GraphQLClientConfiguration Build()
=> new(
public GraphQLClientConfiguration Build() =>
new(
baseAddress,
WebsocketJsonSerializer,
GraphQLClientOptions,
Expand All @@ -20,23 +20,25 @@ public GraphQLClientConfiguration Build()
HttpClient
);

public IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; set; } = new SystemTextJsonSerializer();

public JsonSerializerOptions JsonSerializerOptions { get; set; } = new()
{
PropertyNameCaseInsensitive = true,
Converters =
public IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; set; } =
new SystemTextJsonSerializer();

public JsonSerializerOptions JsonSerializerOptions { get; set; } =
new()
{
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper),
new DateOnlyConverter()
}
};
PropertyNameCaseInsensitive = true,
Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper),
new DateOnlyConverter()
}
};

public GraphQLHttpClientOptions GraphQLClientOptions { get; set; } = new();

public bool ValidateAssemblies { get; set; } = false;

public HttpClient HttpClient { get; set; } = new();

public bool DisposeHttpClient { get; set; } = false;
}
}
12 changes: 6 additions & 6 deletions src/GraphQL-Client/Configuration/IGraphQLClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace GraphQL;
public interface IGraphQLClientConfiguration
{
public IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; }

public JsonSerializerOptions JsonSerializerOptions { get; }

public GraphQLHttpClientOptions GraphQLClientOptions { get; }

public bool ValidateAssemblies { get; }

public GraphQLHttpClient GraphQLHttpClient { get; }

public HttpClient HttpClient { get; }

public bool DisposeHttpClient { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,42 @@ namespace GraphQL;

public static class GraphQLClientConfigurationExtensions
{
public static ISchema IntrospectSchema(this IGraphQLClientConfiguration configuration)
=> FetchSchemaJson(configuration)
.AsSchema();
public static ISchema IntrospectSchema(this IGraphQLClientConfiguration configuration) =>
FetchSchemaJson(configuration).AsSchema();

public static JsonElement FetchSchemaJson(IGraphQLClientConfiguration configuration)
{
var request = new GraphQLHttpRequest(IntrospectionQuery.Classic);

var response = Task.Run(async () =>
await configuration.GraphQLHttpClient.SendQueryAsync<JsonElement>(request)
).Result;
var response = Task.Run(
async () => await configuration.GraphQLHttpClient.SendQueryAsync<JsonElement>(request)
).Result;

if (response.Errors is not null)
{
throw new Exception(
$"Could not introspect ({configuration.HttpClient.BaseAddress}). Got the following errors: ({response.Errors})");
$"Could not introspect ({configuration.HttpClient.BaseAddress}). Got the following errors: ({response.Errors})"
);
}

return response.Data;
}

public static ISchema AsSchema(this JsonElement schemaJson)
{
var schemaResponse = schemaJson.Deserialize<GraphQLData>(new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
});
var schemaResponse = schemaJson.Deserialize<GraphQLData>(
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
}
);

if (schemaResponse?.__Schema is null)
{
throw new Exception(
$"Could not get data from __schema introspection. Data likely came back null. Schema: ({schemaJson.GetRawText()})");
$"Could not get data from __schema introspection. Data likely came back null. Schema: ({schemaJson.GetRawText()})"
);
}

var converter = new ASTConverter();
Expand All @@ -52,4 +55,4 @@ public static ISchema AsSchema(this JsonElement schemaJson)

return Schema.For(sdl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace GraphQL;

public static class GraphQLClientValidatorExtensions
{
public static GraphQLClientValidator ValidateAssemblies(this GraphQLClientValidator validator, params Assembly[] assemblies)
public static GraphQLClientValidator ValidateAssemblies(
this GraphQLClientValidator validator,
params Assembly[] assemblies
)
{
foreach (var assembly in assemblies)
{
Expand All @@ -26,4 +29,4 @@ public static GraphQLClientValidator ValidateAssemblies(this GraphQLClientValida

return validator;
}
}
}
11 changes: 6 additions & 5 deletions src/GraphQL-Client/Extensions/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ public static IServiceCollection AddGraphQLClientServices(
this IServiceCollection services,
Uri baseAddress,
Action<GraphQLClientConfigurationBuilder>? options = null,
params Assembly[] assemblies)
params Assembly[] assemblies
)
{
var configuration = BuildConfiguration(baseAddress, options);

var validator = new GraphQLClientValidator(configuration);

if (configuration.ValidateAssemblies)
Expand All @@ -33,10 +34,10 @@ private static IGraphQLClientConfiguration BuildConfiguration(
{
// Create Builder to be used after Options are invoked
var builder = new GraphQLClientConfigurationBuilder(baseAddress);

// Options able to be null since all values have defaults
options?.Invoke(builder);

return builder.Build();
return builder.Build();
}
}
}
Loading

0 comments on commit df93f88

Please sign in to comment.