Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JSON examples from artifacts #450

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/1-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ jobs:
directory: ${{ env.DOTNET_SRC_DIR }}

- name: Generate Open API
env:
DataSources__EmissionsDataSource: Json
DataSources__Configurations__Json__Type: JSON
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
working-directory: ./src/CarbonAware.WebApi/src

Expand All @@ -144,7 +147,7 @@ jobs:

- name: Docker Run Container
run: |
docker run -d --name runnable-container -p 8080:80 ca-api
docker run -d --name runnable-container -e DataSources__EmissionsDataSource=Json -e DataSources__Configurations__Json__Type=JSON -p 8080:80 ca-api
docker container ls

- name: Docker WGET Health Endpoint
Expand Down Expand Up @@ -244,4 +247,4 @@ jobs:
command: config
globs: |
./custom.markdownlint.jsonc
{"*[^.github]/**,*"}.md
{"*[^.github]/**,*"}.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@
Include="..\..\..\CarbonAware.DataSources\CarbonAware.DataSources.ElectricityMapsFree\mock\CarbonAware.DataSources.ElectricityMapsFree.Mocks.csproj" />
<ProjectReference Include="..\..\src\CarbonAware.CLI.csproj" />
</ItemGroup>
</Project>

<Target Name="CopyDataFiles" AfterTargets="Build">
<Copy SourceFiles="$(ProjectDir)..\..\..\data\data-sources\test-data-azure-emissions.json"
DestinationFiles="$(TargetDir)\data-sources\json\demo.json" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(ProjectDir)..\..\..\data\location-sources\azure-regions.json"
DestinationFiles="$(TargetDir)\location-sources\json\azure-regions.json" SkipUnchangedFiles="true" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void Setup()
{
Environment.SetEnvironmentVariable("DataSources__EmissionsDataSource", "Json");
Environment.SetEnvironmentVariable("DataSources__Configurations__Json__Type", "JSON");
Environment.SetEnvironmentVariable("DataSources__Configurations__Json__DataFileLocation", "test-data-azure-emissions.json");
_dataSourceMocker = new JsonDataSourceMocker();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public JsonDataSourceMocker() { }

public void SetupDataMock(DateTimeOffset start, DateTimeOffset end, string location)
{
string path = new JsonDataSourceConfiguration().DataFileLocation;
var config = new JsonDataSourceConfiguration();
config.DataFileLocation = "test-data-azure-emissions.json";
string path = config.DataFileLocation;

var data = new List<EmissionsData>();
DateTimeOffset pointTime = start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Content Include="$(ProjectDir)..\..\..\data\data-sources\**\*.json"
Link="\data-sources\json\%(RecursiveDir)%(Filename)%(Extension)">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="CarbonAware.DataSources.Json.Mocks" />
<InternalsVisibleTo Include="CarbonAware.DataSources.Json.Tests" />
Expand All @@ -24,4 +17,8 @@
<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>
</Project>

<Target Name="CreateDatasourceDirectory" AfterTargets="Build">
<MakeDir Directories="$(PublishDir)\data-sources\json" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace CarbonAware.DataSources.Json.Configuration;
internal class JsonDataSourceConfiguration
{
private const string BaseDirectory = "data-sources/json";
private const string DefaultDataFile = "test-data-azure-emissions.json";
private const string DirectoryRegExPattern = @"^(?!\.{2})[-\\/a-zA-Z_\d\.: ]*$";
private string assemblyDirectory;
private string? dataFileLocation;
Expand All @@ -34,7 +33,6 @@ public JsonDataSourceConfiguration()
{
var assemblyPath = Assembly.GetExecutingAssembly().Location;
assemblyDirectory = Path.GetDirectoryName(assemblyPath)!;
DataFileLocation = DefaultDataFile;
}

private static bool IsValidDirPath(string fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ public void Setup()
AssemblyPath = Assembly.GetExecutingAssembly().Location;
}

[Test]
public void GetDefaultDataFileLocation_IsNotNull_ExpectedBaseDir()
{
Assert.That(_configuration.DataFileLocation, Is.Not.Null);
var expectedDir = Path.Combine(Path.GetDirectoryName(AssemblyPath)!, BaseDir);
Assert.That(_configuration.DataFileLocation, Contains.Substring(expectedDir));
}

[TestCase("../newfile.json", TestName = "setting parent's dir")]
[TestCase("~/newfile.json", TestName = "setting user's home dir")]
[TestCase(null, TestName = "setting null filepath")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Content Include="$(ProjectDir)..\..\data\location-sources\**\*.json"
Link="\location-sources\json\%(RecursiveDir)%(Filename)%(Extension)">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GSF.CarbonAware" />
<InternalsVisibleTo Include="CarbonAware.LocationSources.Test" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
</Project>

<Target Name="CreateLocationDirectory" AfterTargets="Build">
<MakeDir Directories="$(PublishDir)\location-sources\json" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.LocationSources.csproj" />
</ItemGroup>

<Target Name="CreateLocationDirectory" AfterTargets="Build">
<MakeDir Directories="$(TargetDir)\location-sources\json" />
</Target>
</Project>
3 changes: 3 additions & 0 deletions src/CarbonAware.WebApi/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ COPY . ./
RUN dotnet publish CarbonAware.WebApi/src/CarbonAware.WebApi.csproj -c Release -o publish
# Generate OpenAPI spec
WORKDIR /app/CarbonAware.WebApi/src
# Set environment variables for dummy datasource to start "dotnet tool run"
ENV DataSources__EmissionsDataSource=Json
ENV DataSources__Configurations__Json__Type=JSON
RUN dotnet tool restore && \
mkdir -p /app/publish/wwwroot/api/v1 && \
dotnet tool run swagger tofile --output /app/publish/wwwroot/api/v1/swagger.yaml --yaml /app/publish/CarbonAware.WebApi.dll v1
Expand Down
10 changes: 0 additions & 10 deletions src/CarbonAware.WebApi/src/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
{
"DataSources": {
"EmissionsDataSource": "test-json",
"ForecastDataSource": "", // We don't currently publish a sample test data source for forecasts.
"Configurations": {
"test-json": {
"Type": "JSON",
"DataFileLocation": "test-data-azure-emissions.json"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<Target Name="CopyDataFiles" AfterTargets="Build">
<Copy SourceFiles="$(ProjectDir)..\..\..\data\data-sources\test-data-azure-emissions.json"
DestinationFiles="$(TargetDir)\data-sources\json\demo.json" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(ProjectDir)..\..\..\data\location-sources\azure-regions.json"
DestinationFiles="$(TargetDir)\location-sources\json\azure-regions.json" SkipUnchangedFiles="true" />
</Target>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace CarbonAware.WepApi.IntegrationTests;
[TestFixture(DataSourceType.JSON)]
[TestFixture(DataSourceType.WattTime)]
[TestFixture(DataSourceType.ElectricityMaps)]
[TestFixture(DataSourceType.ElectricityMapsFree)]
//[TestFixture(DataSourceType.ElectricityMapsFree)] // TODO: need to implement data source into IntegrationTestingBase.cs
class CarbonAwareControllerTests : IntegrationTestingBase
{
private readonly string healthURI = "/health";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CarbonAware.WepApi.IntegrationTests;
[TestFixture(DataSourceType.JSON)]
[TestFixture(DataSourceType.WattTime)]
[TestFixture(DataSourceType.ElectricityMaps)]
[TestFixture(DataSourceType.ElectricityMapsFree)]
//[TestFixture(DataSourceType.ElectricityMapsFree)] // TODO: need to implement data source into IntegrationTestingBase.cs
class LocationsControllerTests : IntegrationTestingBase
{
private readonly string locationsURI = "/locations";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace CarbonAware.WebApi.IntegrationTests;

/// <summary>
/// Tests that the Web API starts without configuration.
/// Tests that static Web API endpoints.
/// </summary>
[TestFixture(DataSourceType.None)]
class UnconfiguredWebApiTests : IntegrationTestingBase
[TestFixture(DataSourceType.JSON)]
class WebApiEndpointTests : IntegrationTestingBase
{
private readonly string healthURI = "/health";
private readonly string fakeURI = "/fake-endpoint";

public UnconfiguredWebApiTests(DataSourceType dataSource) : base(dataSource) { }
public WebApiEndpointTests(DataSourceType dataSource) : base(dataSource) { }

[Test]
public async Task HealthCheck_ReturnsOK()
Expand Down
9 changes: 5 additions & 4 deletions src/GSF.CarbonAware/src/GSF.CarbonAware.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
<Content Include="$(AssemblyName).targets" Pack="true"
PackagePath="build/$(AssemblyName).targets" />
<Content Include="$(TargetDir)/CarbonAware*.dll" Pack="true" PackagePath="lib/net6.0/" />
<Content Include="$(TargetDir)/data-sources/**/*.json" Pack="true" PackagePath="data-sources/" />
<Content Include="$(TargetDir)/location-sources/**/*.json" Pack="true"
PackagePath="location-sources/" />
</ItemGroup>

<ItemGroup Label="IncludeSymbols" Condition="$(IncludeSymbols) == true">
<Content Include="$(TargetDir)/CarbonAware*.pdb" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>
</Project>

<Target Name="CreateDatasourceDirectory" AfterTargets="Build">
<MakeDir Directories="$(TargetDir)\data-sources\json,$(TargetDir)\location-sources\json" />
</Target>
</Project>
19 changes: 3 additions & 16 deletions src/GSF.CarbonAware/src/GSF.CarbonAware.targets
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
<Project>
<ItemGroup>
<DataSourceFiles Include="$(MSBuildThisFileDirectory)/../data-sources/**/*.*" />
</ItemGroup>
<Target Name="CopyDataSourceFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DataSourceFiles)" DestinationFolder="$(TargetDir)/data-sources/%(RecursiveDir)" />
<!-- Copy to bin dir for Azure Functions to work -->
<Copy SourceFiles="@(DataSourceFiles)" DestinationFolder="$(TargetDir)/bin/data-sources/%(RecursiveDir)" />
</Target>
<ItemGroup>
<LocationSourceFiles Include="$(MSBuildThisFileDirectory)/../location-sources/**/*.*" />
</ItemGroup>
<Target Name="CopyLocationSourceFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(LocationSourceFiles)" DestinationFolder="$(TargetDir)/location-sources/%(RecursiveDir)" />
<!-- Copy to bin dir for Azure Functions to work -->
<Copy SourceFiles="@(LocationSourceFiles)" DestinationFolder="$(TargetDir)/bin/location-sources/%(RecursiveDir)" />
</Target>
<ItemGroup>
<DllFiles Include="$(MSBuildThisFileDirectory)/../lib/net6.0/*.dll" />
</ItemGroup>
<Target Name="CopyDllFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DllFiles)" DestinationFolder="$(TargetDir)" />
</Target>
<Target Name="CreateDatasourceDirectory" AfterTargets="Build">
<MakeDir Directories="$(PublishDir)\data-sources\json,$(PublishDir)\location-sources\json" />
</Target>
</Project>
Loading