Skip to content

Commit 1e96e60

Browse files
Copilotegil
andcommitted
Update build.sh to use modern dotnet CLI instead of deprecated Cake/mono
Co-authored-by: egil <[email protected]>
1 parent f6d5aeb commit 1e96e60

File tree

2 files changed

+81
-135
lines changed

2 files changed

+81
-135
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,29 @@ on: [push, pull_request]
55
env:
66
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
8-
DOCS_PATH: ${{ secrets.DOCS_PATH }}
9-
DOCS_BRANCH: ${{ secrets.DOCS_BRANCH }}
108

119
jobs:
12-
can_document:
13-
runs-on: ubuntu-latest
14-
outputs:
15-
value: ${{ steps.check_job.outputs.value }}
16-
steps:
17-
- name: Checks whether documentation can be built
18-
id: check_job
19-
run: |
20-
echo "value: ${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}"
21-
echo "value=${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}" >> "${GITHUB_OUTPUT}"
22-
23-
documentation:
24-
needs: [can_document]
25-
runs-on: ubuntu-latest
26-
if: needs.can_document.outputs.value == 'true'
27-
28-
steps:
29-
- uses: actions/checkout@v4
30-
31-
- name: Use Node.js
32-
uses: actions/setup-node@v4
33-
with:
34-
node-version: "14.x"
35-
registry-url: 'https://registry.npmjs.org'
36-
37-
- name: Install Dependencies
38-
run: |
39-
cd $DOCS_PATH
40-
npm install
41-
42-
- name: Deploy Doclet
43-
run: |
44-
cd $DOCS_PATH
45-
npx pilet publish --fresh --url https://feed.piral.cloud/api/v1/pilet/anglesharp --api-key ${{ secrets.PIRAL_FEED_KEY }}
46-
4710
linux:
4811
runs-on: ubuntu-latest
4912

5013
steps:
5114
- uses: actions/checkout@v4
5215

53-
- name: Setup dotnet
54-
uses: actions/setup-dotnet@v4
55-
with:
56-
dotnet-version: |
57-
6.0.x
58-
7.0.x
59-
8.0.x
60-
6116
- name: Build
62-
run: dotnet build src/AngleSharp.Diffing.sln --configuration Release
63-
64-
- name: Test
65-
run: dotnet test src/AngleSharp.Diffing.sln --configuration Release --no-build
17+
run: ./build.sh
6618

6719
windows:
6820
runs-on: windows-latest
6921

7022
steps:
7123
- uses: actions/checkout@v4
7224

73-
- name: Setup dotnet
74-
uses: actions/setup-dotnet@v4
75-
with:
76-
dotnet-version: |
77-
6.0.x
78-
7.0.x
79-
8.0.x
80-
8125
- name: Build
82-
run: dotnet build src/AngleSharp.Diffing.sln --configuration Release
83-
84-
- name: Test
85-
run: dotnet test src/AngleSharp.Diffing.sln --configuration Release --no-build
86-
87-
- name: Publish to NuGet
88-
if: github.ref == 'refs/heads/main'
8926
run: |
90-
if ($env:NUGET_API_KEY) {
91-
dotnet pack src/AngleSharp.Diffing.sln --configuration Release --no-build --output nupkgs
92-
dotnet nuget push "nupkgs/*.nupkg" --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
27+
if ($env:GITHUB_REF -eq "refs/heads/master") {
28+
.\build.ps1 -Target Publish
29+
} elseif ($env:GITHUB_REF -eq "refs/heads/devel") {
30+
.\build.ps1 -Target PrePublish
31+
} else {
32+
.\build.ps1
9333
}

build.sh

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,99 @@
11
#!/usr/bin/env bash
22
###############################################################
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.
55
###############################################################
66

7+
set -eo pipefail
8+
79
# Define directories.
810
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
1313

1414
# Define default arguments.
15-
SCRIPT="build.cake"
1615
TARGET="Default"
1716
CONFIGURATION="Release"
18-
VERBOSITY="verbose"
19-
DRYRUN=
17+
VERBOSITY="minimal"
2018
SHOW_VERSION=false
21-
SCRIPT_ARGUMENTS=()
2219

2320
# Parse arguments.
24-
for i in "$@"; do
21+
while [[ $# -gt 0 ]]; do
2522
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 ;;
3429
esac
35-
shift
3630
done
3731

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
4136
fi
4237

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'"
5239

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
6144
fi
6245

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)"
7247

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
8150

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
8798

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

Comments
 (0)