1
1
#! /usr/bin/env bash
2
2
# ##############################################################
3
- # This is the Cake bootstrapper script that is responsible for
4
- # downloading Cake and all specified tools from NuGet .
3
+ # This is a modern .NET build script that replaces the legacy
4
+ # Cake-based build system to avoid mono dependency on Linux .
5
5
# ##############################################################
6
6
7
+ set -eo pipefail
8
+
7
9
# Define directories.
8
10
SCRIPT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd )
9
- TOOLS_DIR=$SCRIPT_DIR /tools
10
- NUGET_EXE=$TOOLS_DIR /nuget.exe
11
- NUGET_OLD_EXE=$TOOLS_DIR /nuget_old.exe
12
- CAKE_EXE=$TOOLS_DIR /Cake/Cake.exe
11
+ SRC_DIR=$SCRIPT_DIR /src
12
+ SOLUTION_FILE=$SRC_DIR /AngleSharp.Diffing.sln
13
13
14
14
# Define default arguments.
15
- SCRIPT=" build.cake"
16
15
TARGET=" Default"
17
16
CONFIGURATION=" Release"
18
- VERBOSITY=" verbose"
19
- DRYRUN=
17
+ VERBOSITY=" minimal"
20
18
SHOW_VERSION=false
21
- SCRIPT_ARGUMENTS=()
22
19
23
20
# Parse arguments.
24
- for i in " $@ " ; do
21
+ while [[ $# -gt 0 ]] ; do
25
22
case $1 in
26
- -s|--script) SCRIPT=" $2 " ; shift ;;
27
- -t|--target) TARGET=" $2 " ; shift ;;
28
- -c|--configuration) CONFIGURATION=" $2 " ; shift ;;
29
- -v|--verbosity) VERBOSITY=" $2 " ; shift ;;
30
- -d|--dryrun) DRYRUN=" --dryrun" ;;
31
- --version) SHOW_VERSION=true ;;
32
- --) shift ; SCRIPT_ARGUMENTS+=(" $@ " ); break ;;
33
- * ) SCRIPT_ARGUMENTS+=(" $1 " ) ;;
23
+ -t|--target) TARGET=" $2 " ; shift 2 ;;
24
+ -c|--configuration) CONFIGURATION=" $2 " ; shift 2 ;;
25
+ -v|--verbosity) VERBOSITY=" $2 " ; shift 2 ;;
26
+ --version) SHOW_VERSION=true; shift ;;
27
+ --) shift ; break ;;
28
+ * ) shift ;;
34
29
esac
35
- shift
36
30
done
37
31
38
- # Make sure the tools folder exist.
39
- if [ ! -d $TOOLS_DIR ]; then
40
- mkdir $TOOLS_DIR
32
+ # Show dotnet version if requested
33
+ if $SHOW_VERSION ; then
34
+ dotnet --version
35
+ exit 0
41
36
fi
42
37
43
- # Make sure that packages.config exist.
44
- if [ ! -f $TOOLS_DIR /packages.config ]; then
45
- echo " Downloading packages.config..."
46
- curl -Lsfo $TOOLS_DIR /packages.config http://cakebuild.net/bootstrapper/packages
47
- if [ $? -ne 0 ]; then
48
- echo " An error occured while downloading packages.config."
49
- exit 1
50
- fi
51
- fi
38
+ echo " Building AngleSharp.Diffing with target '$TARGET ' and configuration '$CONFIGURATION '"
52
39
53
- # Download NuGet (v3.5.0) if it does not exist.
54
- if [ ! -f $NUGET_OLD_EXE ]; then
55
- echo " Downloading NuGet..."
56
- curl -Lsfo $NUGET_OLD_EXE https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe
57
- if [ $? -ne 0 ]; then
58
- echo " An error occured while downloading nuget.exe."
59
- exit 1
60
- fi
40
+ # Ensure we have dotnet CLI available
41
+ if ! command -v dotnet & > /dev/null; then
42
+ echo " Error: dotnet CLI is not installed or not in PATH"
43
+ exit 1
61
44
fi
62
45
63
- # Download NuGet (latest) if it does not exist.
64
- if [ ! -f $NUGET_EXE ]; then
65
- echo " Downloading NuGet..."
66
- curl -Lsfo $NUGET_EXE https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
67
- if [ $? -ne 0 ]; then
68
- echo " An error occured while downloading nuget.exe."
69
- exit 1
70
- fi
71
- fi
46
+ echo " Using .NET SDK version: $( dotnet --version) "
72
47
73
- # Restore tools from NuGet.
74
- pushd $TOOLS_DIR > /dev/null
75
- mono $NUGET_EXE install -ExcludeVersion
76
- if [ $? -ne 0 ]; then
77
- echo " Could not restore NuGet packages."
78
- exit 1
79
- fi
80
- popd > /dev/null
48
+ # Change to source directory
49
+ cd $SRC_DIR
81
50
82
- # Make sure that Cake has been installed.
83
- if [ ! -f $CAKE_EXE ]; then
84
- echo " Could not find Cake.exe at '$CAKE_EXE '."
85
- exit 1
86
- fi
51
+ # Build based on target
52
+ case $TARGET in
53
+ " Clean" )
54
+ echo " Cleaning build artifacts..."
55
+ dotnet clean $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
56
+ ;;
57
+ " Restore" |" Restore-Packages" )
58
+ echo " Restoring NuGet packages..."
59
+ dotnet restore $SOLUTION_FILE --verbosity $VERBOSITY
60
+ ;;
61
+ " Build" )
62
+ echo " Building solution..."
63
+ dotnet build $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
64
+ ;;
65
+ " Test" |" Run-Unit-Tests" )
66
+ echo " Running tests..."
67
+ dotnet test $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
68
+ ;;
69
+ " Package" |" Create-Package" )
70
+ echo " Building and creating packages..."
71
+ dotnet build $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
72
+ dotnet pack $SOLUTION_FILE --configuration $CONFIGURATION --no-build --verbosity $VERBOSITY
73
+ ;;
74
+ " Publish" |" Publish-Package" )
75
+ echo " Building, testing, and publishing packages..."
76
+ dotnet build $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
77
+ dotnet test $SOLUTION_FILE --configuration $CONFIGURATION --no-build --verbosity $VERBOSITY
78
+ dotnet pack $SOLUTION_FILE --configuration $CONFIGURATION --no-build --verbosity $VERBOSITY
79
+
80
+ # Publish to NuGet if API key is available
81
+ if [ ! -z " $NUGET_API_KEY " ]; then
82
+ echo " Publishing packages to NuGet..."
83
+ for nupkg in $( find . -name " *.nupkg" -not -path " */bin/Debug/*" ) ; do
84
+ echo " Publishing $nupkg "
85
+ dotnet nuget push " $nupkg " --api-key " $NUGET_API_KEY " --source https://api.nuget.org/v3/index.json --skip-duplicate
86
+ done
87
+ else
88
+ echo " NUGET_API_KEY not set, skipping NuGet publish"
89
+ fi
90
+ ;;
91
+ " Default" |* )
92
+ echo " Running default build (build + test + package)..."
93
+ dotnet build $SOLUTION_FILE --configuration $CONFIGURATION --verbosity $VERBOSITY
94
+ dotnet test $SOLUTION_FILE --configuration $CONFIGURATION --no-build --verbosity $VERBOSITY
95
+ dotnet pack $SOLUTION_FILE --configuration $CONFIGURATION --no-build --verbosity $VERBOSITY
96
+ ;;
97
+ esac
87
98
88
- # Start Cake
89
- if $SHOW_VERSION ; then
90
- exec mono $CAKE_EXE --version
91
- else
92
- exec mono $CAKE_EXE $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN " ${SCRIPT_ARGUMENTS[@]} "
93
- fi
99
+ echo " Build completed successfully!"
0 commit comments