Skip to content

Commit

Permalink
Script for building package variants (#125)
Browse files Browse the repository at this point in the history
* Add configurations

* Fix the build

* Add scripts

* Call scripts in workflows

* Dont change workflow

* Update workflow

* Fix path

* Fix script

* Remove stray space

* Finalise package names
  • Loading branch information
nathanrw authored Aug 13, 2023
1 parent 0d7b542 commit a76ff8b
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 12 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ jobs:
6.0.x
7.0.x
- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore
run: ./scripts/Build.sh

- name: Test
run: dotnet test --logger trx --results-directory "TestResults"
run: ./scripts/Test.sh

- name: Upload dotnet test results
uses: actions/upload-artifact@v3
with:
name: dotnet-results
path: TestResults
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
if: ${{ always() }}
52 changes: 48 additions & 4 deletions Arch.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,73 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug-Events|Any CPU = Debug-Events|Any CPU
Debug-PureECS|Any CPU = Debug-PureECS|Any CPU
Release|Any CPU = Release|Any CPU
Release-Events|Any CPU = Release-Events|Any CPU
Release-PureECS|Any CPU = Release-PureECS|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release|Any CPU.Build.0 = Release|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release|Any CPU.Build.0 = Release|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug-Events|Any CPU.ActiveCfg = Debug-Events|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug-Events|Any CPU.Build.0 = Debug-Events|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug-PureECS|Any CPU.ActiveCfg = Debug-PureECS|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Debug-PureECS|Any CPU.Build.0 = Debug-PureECS|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release|Any CPU.Build.0 = Release|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release-Events|Any CPU.ActiveCfg = Release-Events|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release-Events|Any CPU.Build.0 = Release-Events|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release-PureECS|Any CPU.ActiveCfg = Release-PureECS|Any CPU
{D169F06F-F721-4D38-BC1E-9E3F7924B981}.Release-PureECS|Any CPU.Build.0 = Release-PureECS|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug|Any CPU.Build.0 = Release|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug-Events|Any CPU.ActiveCfg = Debug-Events|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug-Events|Any CPU.Build.0 = Debug-Events|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug-PureECS|Any CPU.ActiveCfg = Debug-PureECS|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Debug-PureECS|Any CPU.Build.0 = Debug-PureECS|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release|Any CPU.Build.0 = Release|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release-Events|Any CPU.ActiveCfg = Release-Events|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release-Events|Any CPU.Build.0 = Release-Events|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release-PureECS|Any CPU.ActiveCfg = Release-PureECS|Any CPU
{F7CC359A-23BA-4E17-8938-D9C297B53677}.Release-PureECS|Any CPU.Build.0 = Release-PureECS|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug-Events|Any CPU.ActiveCfg = Debug-Events|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug-Events|Any CPU.Build.0 = Debug-Events|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug-PureECS|Any CPU.ActiveCfg = Debug-PureECS|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Debug-PureECS|Any CPU.Build.0 = Debug-PureECS|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release|Any CPU.Build.0 = Release|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release-Events|Any CPU.ActiveCfg = Release-Events|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release-Events|Any CPU.Build.0 = Release-Events|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release-PureECS|Any CPU.ActiveCfg = Release-PureECS|Any CPU
{1A999F16-5944-4F66-B8C2-A2695B3FE74D}.Release-PureECS|Any CPU.Build.0 = Release-PureECS|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug-Events|Any CPU.ActiveCfg = Debug-Events|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug-Events|Any CPU.Build.0 = Debug-Events|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug-PureECS|Any CPU.ActiveCfg = Debug-PureECS|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Debug-PureECS|Any CPU.Build.0 = Debug-PureECS|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release|Any CPU.Build.0 = Release|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release-Events|Any CPU.ActiveCfg = Release-Events|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release-Events|Any CPU.Build.0 = Release-Events|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release-PureECS|Any CPU.ActiveCfg = Release-PureECS|Any CPU
{FBF2AE5A-36BC-4047-8983-4280A9F0EA1C}.Release-PureECS|Any CPU.Build.0 = Release-PureECS|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug-Events|Any CPU.ActiveCfg = Debug-Events|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug-Events|Any CPU.Build.0 = Debug-Events|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug-PureECS|Any CPU.ActiveCfg = Debug-PureECS|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Debug-PureECS|Any CPU.Build.0 = Debug-PureECS|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release|Any CPU.Build.0 = Release|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release-Events|Any CPU.ActiveCfg = Release-Events|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release-Events|Any CPU.Build.0 = Release-Events|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release-PureECS|Any CPU.ActiveCfg = Release-PureECS|Any CPU
{ED70B997-588C-4CD3-88BA-8C7E99A0064B}.Release-PureECS|Any CPU.Build.0 = Release-PureECS|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
220 changes: 220 additions & 0 deletions scripts/Build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#!/bin/bash
#
# Script to build and publish nuget packages.
#
# See usage() for usage.

ME="$(basename "${BASH_SOURCE[0]}")"
NUGET_SOURCE=https://api.nuget.org/v3/index.json

#
# usage
#
usage() {
cat <<EOF
${ME} -- Script to build and publish a set of nuget packages.
Usage:
${ME} [--[no-]build] [--[no-]publish] [--test] [--api-key <key>]
The default behaviour is to build packages but not publish them.
When publishing packages, a nuget API key must be specified.
EOF
}

#
# main -- Build and publish nuget packages.
#
main() {

# Parse arguments.
BUILDING=True
PUBLISHING=
while [[ ! -z "$1" ]]; do
arg="$1"
shift
case "$arg" in
--test)
TESTING=True
;;
--build)
BUILDING=True
;;
--no-build)
BUILDING=
;;
--publish)
PUBLISHING=True
;;
--no-publish)
PUBLISHING=
;;
--api-key)
API_KEY="$1"
shift
;;
-h|--help|-?)
usage
exit 0
;;
*)
usage
error "Unknown argument: $arg"
;;
esac
done

if [[ ! -f "src/Arch/Arch.csproj" ]]; then
error "Must be run in repository root."
fi

if [[ ! -z "$PUBLISHING" && -z "$API_KEY" ]]; then
error "To publish, API_KEY must be specified via environment or --api-key."
fi

if [[ ! -z "$BUILDING" ]]; then
buildall
fi

if [[ ! -z "$PUBLISHING" ]]; then
publish
fi
}

#
# Hack the package name / id in the Arch cs project. This is the only way I have
# found to make the package name depend on a binary variant. Perhaps there is a
# better way...
#
hackcsproj() {
doit cp src/Arch/Arch.csproj src/Arch/Arch.csproj.bak
doit sed -i "s#<PackageId>Arch</PackageId>#<PackageId>Arch-$1</PackageId>#" src/Arch/Arch.csproj
doit sed -i "s#<Title>Arch</Title>#<Title>Arch-$1</Title>#" src/Arch/Arch.csproj
}

#
# Put the project file back how it was.
#
unhackcsproj() {
if [[ -f src/Arch/Arch.csproj.bak ]]; then
doit mv src/Arch/Arch.csproj.bak src/Arch/Arch.csproj
fi
}

#
# Display an error message and exit, ensuring that any change to the
# csproj file was reverted.
#
error() {
>&2 echo "ERROR" "$@"
unhackcsproj
exit 1
}

#
# Execute and print a command line.
#
# Note: do not pass secrets into this function!
#
doit() {
>&2 echo "$@"
if [[ -z "$TESTING" ]]; then
"$@" || error
fi
}

#
#
# build <config> [variant]
#
# Build one binary variant.
#
build() {
local config="$1"
if [[ -z "$config" ]]; then
error "Config not specified."
fi
local variant="$2"

# Determine preset to build, and suffix to append to the package name. For
# release packages we don't include 'Release' in the suffix, but for 'Debug'
# packages we do include 'Debug'.
local preset="$config"
local suffix=
if [[ "$config" == Debug ]]; then
suffix=Debug
fi
if [[ ! -z "$variant" ]]; then
preset="$config-$variant"
if [[ ! -z "$suffix" ]]; then
suffix="$suffix-"
fi
suffix="$suffix$variant"
fi

# Now hack the cs proj to append the suffix to the package name if
# necessary, then do the build.
if [[ ! -z "$suffix" ]]; then
hackcsproj "$suffix"
fi
doit dotnet build -c "$preset"
doit dotnet pack -c "$preset" src/Arch/Arch.csproj
if [[ ! -z "$suffix" ]]; then
unhackcsproj
fi
}

#
# buildall
#
# Build all variants.
#
buildall() {
find src -name "*.nupkg" -delete
doit dotnet clean
doit dotnet restore
for config in Debug Release; do
build "$config"
for variant in PureECS Events; do
build $config $variant
done
done
find src -name "*.nupkg"
}

#
# publish
#
# Publish built packages.
#
# API_KEY must be set.
#
publish() {
# Note: the slightly odd construct below allows us to loop through the
# output of 'find'.
# - -print0 ensures that the output of 'find' is null-delimited rather
# newline-delimited. This handles the rare case of newlines in the
# output.
# - 'IFS= read -r line' is used to read line-by-line from the input
# - '-d ''' makes 'read' null-delimited to match 'find'
# - The PIPESTATUS stuff catches errors from within the pipe -- otherwise
# if our code inside the loop failed, it would be silently ignored.
find src -name "*.nupkg" -print0 |
while IFS= read -r -d '' line; do

# Push each package, being careful not to print secrets to the
# output.
>&2 echo dotnet nuget push "$line" --api-key '***' --source "$NUGET_SOURCE"
if [[ -z "$TESTING" ]]; then
dotnet nuget push "$line" --api-key "$API_KEY" --source "$NUGET_SOURCE" || exit 1
fi

done
if [[ "${PIPESTATUS[@]}" != "0 0" ]]; then
exit 1
fi
}

main "$@"
22 changes: 22 additions & 0 deletions scripts/Test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

STATUS=0

main() {
test Debug
test Debug-Events
test Debug-PureECS
test Release
test Release-Events
test Release-PureECS
exit $STATUS
}

test() {
dotnet test --configuration "$1" --logger trx --results-directory "TestResults"
if [[ "$?" != 0 ]]; then
STATUS=1
fi
}

main "$@"
25 changes: 23 additions & 2 deletions src/Arch.Benchmarks/Arch.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Release-PureECS;Release-Events;Debug-PureECS;Debug-Events;</Configurations>
<!--<TreatWarningsAsErrors>true</TreatWarningsAsErrors>-->
</PropertyGroup>

Expand All @@ -31,8 +32,28 @@
<Using Include="BenchmarkDotNet.Validators" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>PURE_ECS</DefineConstants>
<PropertyGroup Condition="'$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug-PureECS'">
<DefineConstants>TRACE;PURE_ECS;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug-Events'">
<DefineConstants>TRACE;EVENTS;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release-Events'">
<DefineConstants>TRACE;EVENTS;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release-PureECS'">
<DefineConstants>TRACE;PURE_ECS</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Arch.Benchmarks/QueryBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Arch.Core;
using Arch.Core.Utils;
using Arch.Core.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Arch.Benchmarks;
Expand Down
Loading

0 comments on commit a76ff8b

Please sign in to comment.