Skip to content

Commit 1dd41ea

Browse files
committed
fix(nuke): launch actions on pr, fix build.cmd permissions
1 parent 05ff22f commit 1dd41ea

File tree

10 files changed

+154
-130
lines changed

10 files changed

+154
-130
lines changed

.github/workflows/DotNET-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ on:
2121
branches:
2222
- master
2323
- dev
24+
pull_request:
25+
branches:
26+
- master
27+
- dev
2428

2529
jobs:
2630
ubuntu-latest:
2731
name: ubuntu-latest
2832
runs-on: ubuntu-latest
2933
steps:
3034
- uses: actions/checkout@v3
35+
with:
36+
fetch-depth: 0
3137
- name: Cache .nuke/temp, ~/.nuget/packages
3238
uses: actions/cache@v3
3339
with:

.github/workflows/JS-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
runs-on: ubuntu-latest
3333
steps:
3434
- uses: actions/checkout@v3
35+
with:
36+
fetch-depth: 0
3537
- name: Cache .nuke/temp, ~/.nuget/packages
3638
uses: actions/cache@v3
3739
with:

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: CI/CD
33
on:
44
workflow_dispatch:
55

6-
push:
7-
branches: ['master', 'dev']
8-
pull_request:
9-
branches: ['master', 'dev']
6+
# push:
7+
# branches: ['master', 'dev']
8+
# pull_request:
9+
# branches: ['master', 'dev']
1010

1111
jobs:
1212
DotNET_Build:

.nuke/build.schema.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"Backend_Compile",
8585
"Backend_Reporter",
8686
"Backend_Restore",
87-
"Backend_Setup",
8887
"Backend_SonarScan_End",
8988
"Backend_SonarScan_Start",
9089
"Backend_Test",
@@ -123,7 +122,6 @@
123122
"Backend_Compile",
124123
"Backend_Reporter",
125124
"Backend_Restore",
126-
"Backend_Setup",
127125
"Backend_SonarScan_End",
128126
"Backend_SonarScan_Start",
129127
"Backend_Test",

build.cmd

100644100755
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
:; set -eo pipefail
2-
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3-
:; ${SCRIPT_DIR}/build.sh "$@"
4-
:; exit $?
5-
6-
@ECHO OFF
7-
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/build.sh "$@"
4+
:; exit $?
5+
6+
@ECHO OFF
7+
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

build.sh

100644100755
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
#!/usr/bin/env bash
2-
3-
bash --version 2>&1 | head -n 1
4-
5-
set -eo pipefail
6-
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7-
8-
###########################################################################
9-
# CONFIGURATION
10-
###########################################################################
11-
12-
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13-
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
14-
15-
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16-
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
17-
DOTNET_CHANNEL="Current"
18-
19-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21-
export DOTNET_MULTILEVEL_LOOKUP=0
22-
23-
###########################################################################
24-
# EXECUTION
25-
###########################################################################
26-
27-
function FirstJsonValue {
28-
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
29-
}
30-
31-
# If dotnet CLI is installed globally and it matches requested version, use for execution
32-
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
33-
export DOTNET_EXE="$(command -v dotnet)"
34-
else
35-
# Download install script
36-
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
37-
mkdir -p "$TEMP_DIRECTORY"
38-
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
39-
chmod +x "$DOTNET_INSTALL_FILE"
40-
41-
# If global.json exists, load expected version
42-
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
43-
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
44-
if [[ "$DOTNET_VERSION" == "" ]]; then
45-
unset DOTNET_VERSION
46-
fi
47-
fi
48-
49-
# Install by channel or version
50-
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
51-
if [[ -z ${DOTNET_VERSION+x} ]]; then
52-
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
53-
else
54-
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
55-
fi
56-
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
57-
fi
58-
59-
echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
60-
61-
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
62-
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
1+
#!/usr/bin/env bash
2+
3+
bash --version 2>&1 | head -n 1
4+
5+
set -eo pipefail
6+
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7+
8+
###########################################################################
9+
# CONFIGURATION
10+
###########################################################################
11+
12+
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13+
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
14+
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16+
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
17+
DOTNET_CHANNEL="Current"
18+
19+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
export DOTNET_MULTILEVEL_LOOKUP=0
22+
23+
###########################################################################
24+
# EXECUTION
25+
###########################################################################
26+
27+
function FirstJsonValue {
28+
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
29+
}
30+
31+
# If dotnet CLI is installed globally and it matches requested version, use for execution
32+
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
33+
export DOTNET_EXE="$(command -v dotnet)"
34+
else
35+
# Download install script
36+
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
37+
mkdir -p "$TEMP_DIRECTORY"
38+
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
39+
chmod +x "$DOTNET_INSTALL_FILE"
40+
41+
# If global.json exists, load expected version
42+
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
43+
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
44+
if [[ "$DOTNET_VERSION" == "" ]]; then
45+
unset DOTNET_VERSION
46+
fi
47+
fi
48+
49+
# Install by channel or version
50+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
51+
if [[ -z ${DOTNET_VERSION+x} ]]; then
52+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
53+
else
54+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
55+
fi
56+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
57+
fi
58+
59+
echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
60+
61+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
62+
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

build/Build.Backend.Tests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
partial class Build : NukeBuild
99
{
10-
[PathExecutable("dotnet-coverage")]
10+
[PackageExecutable(
11+
packageId: "dotnet-coverage",
12+
packageExecutable: "dotnet-coverage.dll"
13+
)]
1114
readonly Tool DotnetCoverage;
1215

1316
Target Backend_Test => _ => _
1417
.DependsOn(Backend_Compile)
1518
.Requires(() => DockerTasks.DockerInfo(new DockerInfoSettings()).Any())
19+
.Description("Runs dotnet test")
1620
.Executes(() =>
1721
{
1822
DotNetTest(s => s
@@ -23,8 +27,9 @@ partial class Build : NukeBuild
2327
Target Backend_Test_Ci => _ => _
2428
.DependsOn(Backend_Compile)
2529
.Requires(() => DockerTasks.DockerInfo(new DockerInfoSettings()).Any())
30+
.Description("Runs dotnet-coverage collect, with coverlet coverage")
2631
.Executes(() =>
2732
{
28-
DotnetCoverage("dotnet-coverage collect -f xml -o \"coverage.xml\" dotnet test --no-build --logger \"trx;LogFileName=test-results.trx\"");
33+
DotnetCoverage?.Invoke(@"collect -f xml -o ""coverage.xml"" dotnet test --no-build --diag --logger ""trx;LogFileName=test-results.trx""");
2934
});
3035
}

build/Build.CI.GithubActions.cs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
using Nuke.Common;
22
using Nuke.Common.CI.GitHubActions;
33
using Nuke.Common.Tooling;
4-
using Nuke.Common.Tools.Docker;
5-
using Nuke.Common.Tools.DotNet;
64
using Nuke.Common.Tools.SonarScanner;
75
using System.Collections.Generic;
86

7+
/**
8+
* Interesting ref to make the build script executable on server:
9+
* https://blog.dangl.me/archive/executing-nuke-build-scripts-on-linux-machines-with-correct-file-permissions/
10+
* https://stackoverflow.com/a/40979016/15129749
11+
*/
912
[GitHubActions("DotNET-build",
1013
GitHubActionsImage.UbuntuLatest,
1114
AutoGenerate = true,
1215
EnableGitHubToken = true,
16+
FetchDepth = 0,
1317
ImportSecrets = new[] { nameof(DockerhubUsername), nameof(DockerhubPassword), nameof(SonarToken) },
1418
InvokedTargets = new[] { nameof(Backend_Reporter) },
15-
OnPushBranches = new[] { "master", "dev" }
19+
OnPushBranches = new[] { "master", "dev" },
20+
OnPullRequestBranches = new[] { "master", "dev" }
1621
)]
1722
[GitHubActions("JS-build",
1823
GitHubActionsImage.UbuntuLatest,
1924
AutoGenerate = true,
2025
EnableGitHubToken = true,
26+
FetchDepth = 0,
2127
ImportSecrets = new[] { nameof(SonarTokenUi) },
2228
InvokedTargets = new[] { nameof(Frontend_Reporter) },
2329
OnPushBranches = new[] { "master", "dev" },
2430
OnPullRequestBranches = new[] { "master", "dev" }
2531
)]
2632
partial class Build : NukeBuild
2733
{
28-
[PathExecutable("dotnet-sonarscanner")]
29-
readonly Tool SonarScanner;
34+
//[PackageExecutable(
35+
// packageId: "dotnet-sonarscanner",
36+
// packageExecutable: "SonarScanner.MSBuild.dll",
37+
// // Must be set for tools shipping multiple versions
38+
// Framework = "net5.0"
39+
//)]
40+
//readonly Tool SonarScanner;
3041

3142
[Parameter][Secret] readonly string DockerhubUsername;
3243
[Parameter][Secret] readonly string DockerhubPassword;
@@ -36,54 +47,51 @@ partial class Build : NukeBuild
3647
public bool OnGithubActionRun = GitHubActions.Instance != null &&
3748
!string.IsNullOrWhiteSpace(GitHubActions.Instance.RunId.ToString());
3849

39-
Target Backend_Setup => _ => _
40-
.OnlyWhenStatic(() => OnGithubActionRun)
41-
.Executes(() =>
42-
{
43-
DotNetTasks.DotNetToolInstall(new DotNetToolInstallSettings()
44-
.SetPackageName("dotnet-sonarscanner")
45-
.SetGlobal(true)
46-
);
47-
DotNetTasks.DotNetToolInstall(new DotNetToolInstallSettings()
48-
.SetPackageName("dotnet-coverage")
49-
.SetGlobal(true)
50-
);
51-
});
52-
5350
Target Docker_Setup => _ => _
54-
.DependsOn(Backend_Setup)
5551
.OnlyWhenStatic(() => OnGithubActionRun)
5652
.Executes(() =>
5753
{
58-
DockerTasks.DockerLogin(new DockerLoginSettings()
59-
.SetUsername(DockerhubUsername)
60-
.SetPassword(DockerhubPassword));
54+
//DockerTasks.DockerLogin(new DockerLoginSettings()
55+
// .SetUsername(DockerhubUsername)
56+
// .SetPassword(DockerhubPassword));
6157
});
6258

6359
Target Backend_SonarScan_Start => _ => _
6460
.DependsOn(Backend_Restore)
6561
.OnlyWhenStatic(() => OnGithubActionRun)
6662
.Executes(() =>
6763
{
68-
SonarScanner(@$"dotnet sonarscanner begin \
69-
/k:""followynne_serilog-ui\"" \
70-
/o:""followynne"" \
71-
/d:sonar.login=""{SonarToken}"" \
72-
/d:sonar.host.url=""https://sonarcloud.io"" \
73-
/d:sonar.sources=src/ \
74-
/d:sonar.exclusions=src/Serilog.Ui.Web/assets/**/*,src/Serilog.Ui.Web/wwwroot/**/*,src/Serilog.Ui.Web/node_modules/**/*,src/Serilog.Ui.Web/*.js,src/Serilog.Ui.Web/*.json \
75-
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml",
76-
environmentVariables: new Dictionary<string, string> { ["GITHUB_TOKEN"] = GitHubActions.Instance.Token, ["SONAR_TOKEN"] = SonarToken });
64+
SonarScannerTasks.SonarScannerBegin(new SonarScannerBeginSettings()
65+
.SetFramework("net5.0")
66+
.SetProjectKey("followynne_serilog-ui")
67+
.SetOrganization("followynne")
68+
.SetLogin(SonarToken)
69+
.SetServer("https://sonarcloud.io")
70+
.SetVisualStudioCoveragePaths("coverage.xml")
71+
.SetSourceInclusions("src/")
72+
.SetExcludeTestProjects(true)
73+
.SetSourceExclusions(
74+
"src/Serilog.Ui.Web/assets/**/*",
75+
"src/Serilog.Ui.Web/wwwroot/**/*",
76+
"src/Serilog.Ui.Web/node_modules/**/*",
77+
"src/Serilog.Ui.Web/*.js",
78+
"src/Serilog.Ui.Web/*.json")
79+
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
80+
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken)
81+
);
7782
});
7883

7984
Target Backend_SonarScan_End => _ => _
80-
.DependsOn(Backend_Test_Ci)
81-
.OnlyWhenStatic(() => OnGithubActionRun)
82-
.Executes(() =>
83-
{
84-
SonarScanner($"dotnet sonarscanner end /d:sonar.login=\"{SonarToken}\"",
85-
environmentVariables: new Dictionary<string, string> { ["GITHUB_TOKEN"] = GitHubActions.Instance.Token, ["SONAR_TOKEN"] = SonarToken });
86-
});
85+
.DependsOn(Backend_Test_Ci)
86+
.OnlyWhenStatic(() => OnGithubActionRun)
87+
.Executes(() =>
88+
{
89+
SonarScannerTasks.SonarScannerEnd(new SonarScannerEndSettings()
90+
.SetFramework("net5.0")
91+
.SetLogin(SonarToken)
92+
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
93+
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken));
94+
});
8795

8896
Target Frontend_SonarScan => _ => _
8997
.DependsOn(Frontend_Tests_Ci)

build/Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ partial class Build : NukeBuild
2323
/// - JetBrains Rider https://nuke.build/rider
2424
/// - Microsoft VisualStudio https://nuke.build/visualstudio
2525
/// - Microsoft VSCode https://nuke.build/vscode
26-
public static int Main() => Execute<Build>(x => x.Backend_Test);
26+
public static int Main() => Execute<Build>(x => x.Backend_Test, p => p.Frontend_Tests);
2727

2828
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
2929
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

0 commit comments

Comments
 (0)