Skip to content

Commit

Permalink
Test package fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bill DeRusha <[email protected]>
  • Loading branch information
bderusha committed Sep 11, 2023
1 parent 1f1cc05 commit 408fcb1
Show file tree
Hide file tree
Showing 29 changed files with 167 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/1-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
DLL_FILE_PATH: "./bin/Release/net6.0/CarbonAware.WebApi.dll"
DOTNET_SRC_DIR: "./src"
# console app packages
DOTNET_SOLUTION: "src/GSF.CarbonAware/src/GSF.CarbonAware.csproj"
DOTNET_SOLUTION: "src/CarbonAwareSDK.sln"
OUTPUT_DIR: "packages"
CONSOLE_APP: "samples/lib-integration/ConsoleApp/ConsoleApp.csproj"
CREATE_PKGS: "scripts/package/create_packages.ps1"
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/verify-azure-function-with-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,28 @@ jobs:
- name: Docker Target Final
run: |
docker build --no-cache . -f ${{ env.DOCKERFILE_PATH }} -t ${{ env.CONTAINER_IMAGE_NAME }}
docker rmi -f $(docker images -f "dangling=true" -q)
docker image prune -f
- name: Docker Run Container
run: docker run -d --name ${{ env.CONTAINER_RUNTIME_NAME }} -p 8080:80 ${{ env.CONTAINER_IMAGE_NAME }}
run: |
docker run -d --name ${{ env.CONTAINER_RUNTIME_NAME }} -p 8080:80 ${{ env.CONTAINER_IMAGE_NAME }}
timeout 30 bash -c -- 'while [ -z "$(docker ps -q)" ]; do echo "waiting for container to start" && sleep 5s; done'
docker ps
# Request fails with authentication error. Expected
- name: Get Average Carbon Intensity
run: |
set +e
ret_code=$(wget -S -t 5 --waitretry=5 "http://0.0.0.0:8080/api/GetAverageCarbonIntensity?startDate=2022-03-01T15:30:00Z&endDate=2022-03-01T18:30:00Z&location=eastus" 2>&1 | grep "HTTP/" | awk '{print $2}')
ret_code=$(wget --server-response "http://0.0.0.0:8080/api/GetAverageCarbonIntensity?startDate=2022-03-01T15:30:00Z&endDate=2022-03-01T18:30:00Z&location=eastus" 2>&1 | awk '/^ HTTP/{print $2}')
echo "Return Code: $ret_code"
set -e
[ "401" == $ret_code ]
[ "401" = "$ret_code" ]
# Request fails with authentication error. Expected
- name: Get Current Forecast
run: |
set +e
ret_code=$(wget -S -t 5 --waitretry=5 "http://0.0.0.0:8080/api/GetCurrentForecast" --header "Content-Type: application/json" --post-data '{"startDate":"2022-11-02T15:30:00Z","endDate":"2022-11-02T18:30:00Z","location":"eastus","duration":"15"}' 2>&1 | grep "HTTP/" | awk '{print $2}')
ret_code=$(wget --server-response "http://0.0.0.0:8080/api/GetCurrentForecast" --header "Content-Type: application/json" --post-data '{"startDate":"2022-11-02T15:30:00Z","endDate":"2022-11-02T18:30:00Z","location":"eastus","duration":"15"}' 2>&1 | awk '/^ HTTP/{print $2}')
echo "Return Code: $ret_code"
set -e
[ "401" == $ret_code ]
[ "401" = "$ret_code" ]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ src/data/location-sources/custom-azure-zones.json

# exclude artifacts on java-client example
samples/java-client/target

# exclude artifacts from default package builder
/packages
24 changes: 12 additions & 12 deletions docs/packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ showing how the package can be consumed.
- [Console App Sample](#console-app-sample)
- [Run the Sample Console App](#run-the-sample-console-app)

## Included Projects
## Included Packages

The current package include 7 projects from the SDK:
The current solution creates 5 packages from the SDK projects:

1. "GSF.CarbonAware"
2. "CarbonAware"
3. "CarbonAware.DataSources.ElectricityMapsFree"
4. "CarbonAware.DataSources.ElectricityMaps"
5. "CarbonAware.DataSources.Json"
6. "CarbonAware.DataSources.WattTime"
7. "CarbonAware.LocationSources"

These 7 projects enable users of the library to consume the current endpoints
exposed by the library. The package that needs to be added to a new C# project
is `GSF.CarbonAware`.
1. "CarbonAware"
2. "CarbonAware.LocationSources"
2. "CarbonAware.DataSources.ElectricityMapsFree"
3. "CarbonAware.DataSources.ElectricityMaps"
4. "CarbonAware.DataSources.Json"
5. "CarbonAware.DataSources.WattTime"

Adding the `GSF.CarbonAware` project to your C# projects gives you access to all
CarbonAware SDK interfaces.
Additionally, operators must add any data source packages they plan to use.

## Included Scripts

Expand Down
6 changes: 5 additions & 1 deletion samples/azure/azure-function/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ COPY ["scripts/", "data/scripts/"]
COPY ["samples/", "data/samples/"]

WORKDIR /data
RUN pwsh -c scripts/package/create_packages.ps1 src/GSF.CarbonAware/src/GSF.CarbonAware.csproj /packages && \
RUN pwsh -c scripts/package/create_packages.ps1 src/CarbonAwareSDK.sln /packages && \
dotnet nuget locals all --clear && \
dotnet nuget add source /packages -n carbonaware && \
dotnet restore "samples/azure/azure-function/function.csproj" && \
pwsh -c scripts/package/add_packages.ps1 samples/azure/azure-function/function.csproj /packages && \
dotnet build "samples/azure/azure-function/function.csproj" -c Release -o /app/build
Expand All @@ -20,4 +22,6 @@ RUN dotnet publish "samples/azure/azure-function/function.csproj" -c Release -o

FROM base AS final
WORKDIR /home/site/wwwroot
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=publish /app/publish .
3 changes: 3 additions & 0 deletions samples/azure/azure-function/function.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CarbonAware.DataSources.Json" Version="1.0.0" />
<PackageReference Include="CarbonAware.DataSources.WattTime" Version="1.0.0" />
<PackageReference Include="GSF.CarbonAware" Version="1.0.0-beta" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
Expand Down
6 changes: 5 additions & 1 deletion samples/azure/azure-function/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"default": "Information"
}
}
},
"tracing": {"consoleLevel": "verbose"}
}
5 changes: 5 additions & 0 deletions scripts/package/add_packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if ([string]::IsNullOrEmpty($DOTNET_PROJECT) -or [string]::IsNullOrEmpty($PACKAG

$packages = @(
"GSF.CarbonAware"
"CarbonAware.DataSources.Json"
"CarbonAware.DataSources.WattTime"
"CarbonAware.DataSources.ElectricityMaps"
"CarbonAware.DataSources.ElectricityMapsFree"
)

# Remove packages from project
Expand All @@ -21,6 +25,7 @@ foreach ($pname in $packages) {
}

Remove-Item -Recurse -Force ~/.nuget/packages/gsf.carbonaware*
Remove-Item -Recurse -Force ~/.nuget/packages/carbonaware.datasources*

# Add packages to project
foreach ($pname in $packages) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/package/create_packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if ([string]::IsNullOrEmpty($DOTNET_SOLUTION) -or [string]::IsNullOrEmpty($DEST_
$REVISION = $(git rev-parse HEAD)
$BRANCH = "dev"

New-Item -Path $DEST_PACKAGES -ItemType Directory
New-Item -Path $DEST_PACKAGES -ItemType Directory -Force | Out-Null

# Remove existing packages
Get-ChildItem -Path $path -Recurse -Include *.nupkg, *.snupkg | Remove-Item
Expand Down
8 changes: 8 additions & 0 deletions src/CarbonAware.CLI/src/CarbonAware.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
<ProjectReference Include="..\..\CarbonAware\src\CarbonAware.csproj" />
<ProjectReference Include="..\..\CarbonAware.LocationSources\src\CarbonAware.LocationSources.csproj" />
<ProjectReference Include="..\..\GSF.CarbonAware\src\GSF.CarbonAware.csproj" />
<ProjectReference
Include="..\..\CarbonAware.DataSources\CarbonAware.DataSources.Json\src\CarbonAware.DataSources.Json.csproj" />
<ProjectReference
Include="..\..\CarbonAware.DataSources\CarbonAware.DataSources.WattTime\src\CarbonAware.DataSources.WattTime.csproj" />
<ProjectReference
Include="..\..\CarbonAware.DataSources\CarbonAware.DataSources.ElectricityMaps\src\CarbonAware.DataSources.ElectricityMaps.csproj" />
<ProjectReference
Include="..\..\CarbonAware.DataSources\CarbonAware.DataSources.ElectricityMapsFree\src\CarbonAware.DataSources.ElectricityMapsFree.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.ElectricityMaps.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" PrivateAssets="all" />
</ItemGroup>

<!-- Add files required to create a package -->
<ItemGroup Label="FilesToCopy">
<Content Include="$(AssemblyName).targets" Pack="true"
PackagePath="build/$(AssemblyName).targets" />
<Content Include="$(TargetDir)/CarbonAware.dll" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>

<ItemGroup Label="IncludeSymbols" Condition="$(IncludeSymbols) == true">
<Content Include="$(TargetDir)/CarbonAware.pdb" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<ItemGroup>
<DllFiles Include="$(MSBuildThisFileDirectory)/../lib/net6.0/*.dll" />
</ItemGroup>
<Target Name="CopyDllFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DllFiles)" DestinationFolder="$(TargetDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.ElectricityMaps.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.ElectricityMapsFree.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
<Folder Include="Constants\" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,7 +21,18 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Constants\" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" PrivateAssets="all" />
</ItemGroup>

<!-- Add files required to create a package -->
<ItemGroup Label="FilesToCopy">
<Content Include="$(AssemblyName).targets" Pack="true"
PackagePath="build/$(AssemblyName).targets" />
<Content Include="$(TargetDir)/CarbonAware.dll" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>

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


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<ItemGroup>
<DllFiles Include="$(MSBuildThisFileDirectory)/../lib/net6.0/*.dll" />
</ItemGroup>
<Target Name="CopyDllFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DllFiles)" DestinationFolder="$(TargetDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware.LocationSources\src\CarbonAware.LocationSources.csproj" />
<ProjectReference Include="..\src\CarbonAware.DataSources.ElectricityMapsFree.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.Json.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -21,6 +20,18 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" PrivateAssets="all" />
</ItemGroup>

<!-- Add files required to create a package -->
<ItemGroup Label="FilesToCopy">
<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/" />
</ItemGroup>

<ItemGroup Label="IncludeSymbols" Condition="$(IncludeSymbols) == true">
<Content Include="$(TargetDir)/CarbonAware.pdb" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<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>
<DllFiles Include="$(MSBuildThisFileDirectory)/../lib/net6.0/*.dll" />
</ItemGroup>
<Target Name="CopyDllFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DllFiles)" DestinationFolder="$(TargetDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.Json.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.WattTime.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,7 +24,18 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" PrivateAssets="all" />
</ItemGroup>

<!-- Add files required to create a package -->
<ItemGroup Label="FilesToCopy">
<Content Include="$(AssemblyName).targets" Pack="true"
PackagePath="build/$(AssemblyName).targets" />
<Content Include="$(TargetDir)/CarbonAware.dll" Pack="true" PackagePath="lib/net6.0/" />
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<ItemGroup>
<DllFiles Include="$(MSBuildThisFileDirectory)/../lib/net6.0/*.dll" />
</ItemGroup>
<Target Name="CopyDllFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="@(DllFiles)" DestinationFolder="$(TargetDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\src\CarbonAware.DataSources.WattTime.csproj" />
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 408fcb1

Please sign in to comment.