-
Notifications
You must be signed in to change notification settings - Fork 1
197 lines (172 loc) · 7.67 KB
/
build.yml
File metadata and controls
197 lines (172 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Build and Test MainRepo1
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # Allows manual triggering
env:
# Main repository directory:
# Placeholder: ${{ env.REPO_DIR }}
REPO_DIR: IGLibCore
# Main source project directory:
# Placeholder: ${{ env.SOURCE_DIR }}
SOURCE_DIR: IGLibCore/src/IGLib.Core
# Whether failed tests are ignored (should normally be false):
# Placeholder: ${{ env.IGNORE_TEST_ERRORS }}
IGNORE_TEST_ERRORS: false
jobs:
build-and-test:
runs-on: windows-latest # use Windows for .NET Framework support
# runs-on: ubuntu-latest # runs on GitHub-hosted Ubuntu
strategy:
matrix:
dotnet-version: [ '10.0' ]
steps:
# CHECKOUT Main Repository
- name: Clone Main Repository
uses: actions/checkout@v4
with:
repository: ajgorhoe/IGLib.modules.${{ env.REPO_DIR }}
path: ${{ env.REPO_DIR }}
ref: main
# Important: set fetch-depth 0 to avoid shallow clones (needed
# for GitVersion):
fetch-depth: 0
# Temporary token created automatically for the main repo (owner of the workflow)
token: ${{ secrets.GITHUB_TOKEN }}
# CONFIGURE GIT to use access token for owned repos
- name: CONFIGURE GIT credentials for private repos
shell: pwsh
run: |
# # Option 1 - via configuration file
# # Because Git may have different idea of the location of home
# # directory (and of config. file .git-credentials) than PowerShell,
# # we explicitly define where the location of config. is.
# if ($IsWindows) {
# $credPath = "$env:USERPROFILE\.git-credentials"
# } else {
# $credPath = "$HOME/.git-credentials"
# }
# git config --global credential.helper "store --file=$credPath"
# " https://x-access-token:${{ secrets.PAT_ACTIONS_IGLIB_READONLY }}@github.com" | Out-File -FilePath $credPath -Encoding ascii
# git config --global credential.useHttpPath true
# # Option 2 - Inject credentials directly into Git’s configuration for the current session:
git config --global url."https://x-access-token:${{ secrets.PAT_ACTIONS_IGLIB_READONLY }}@github.com/".insteadOf "https://github.com/"
# CLONE DEPENDENCY repositories:
- name: CLONE DEPENDENCY repos
shell: pwsh
continue-on-error: false
# Important: set --depth 0 to avoid shallow clones (needed
# for GitVersion)
run: |
echo "Cloning dependencies via repo's own script (UpdateDependencyReposExtended.ps1)`n`n..."
./${{ env.REPO_DIR }}/scripts/UpdateDependencyReposExtended.ps1
# CHECKOUT IGLibScripting
- name: Clone IGLibScripting
uses: actions/checkout@v4
with:
repository: ajgorhoe/IGLib.modules.IGLibScripting
path: IGLibScripting
ref: main
# Use automatically generated token (private repo, same owner)
token: ${{ secrets.PAT_ACTIONS_IGLIB_READONLY }}
# CLONE IGLibScripting
- name: Clone IGLibScripting Dependency
shell: pwsh
# Important: set --depth 0 to avoid shallow clones (needed
# for GitVersion)
run: |
git clone https://${{ secrets.PAT_ACTIONS_IGLIB_READONLY }}@github.com/ajgorhoe/IGLib.modules.IGLibScripting `
IGLibScripting1
# Print out tree view of the base directory, in order to verify that
# all checkouts were performed correctly. Tune the depth and including
# hidden files to get the information needed.
- name: CHECK DIRECTORY STRUCTURE
shell: pwsh
run: |
Write-Host "`n`nChecking directory structure...`n"
Write-Host "Current directory: $(Get-Location)`n"
Write-Host "Directory Contents:`n"
${{ env.REPO_DIR }}/scripts/ShowDirectoryTree.ps1 -Path . -MaxDepth 2 -IncludeHidden
${{ env.REPO_DIR }}/scripts/ShowDirectoryTree.ps1 -Path ./_external -MaxDepth 2 -IncludeHidden
- name: SET UP .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
# INSTALL global DOTNET TOOLS
- name: INSTALL global DOTNET TOOLS (GitVersion)
run: |
dotnet tool install --global GitVersion.Tool
- name: Setup MSBuild for .NET Framework
uses: microsoft/setup-msbuild@v1 # Needed for .NET Framework builds
# RUN PRE-BUILD SCRIPT (PowerShell)
- name: Run Pre-Build PowerShell Script
run: pwsh -File ${{ env.REPO_DIR }}/scripts/PrintEnv.ps1
# Verify .NET SDK version and global tools to insure everything we need is installed:
- name: VERIFY .NET SDK and global tools
shell: pwsh
run: |
Write-Host "Checking .NET SDK version..."
dotnet --version
Write-Host "Listing global dotnet tools..."
dotnet tool list --global
# Verify that GitVersion works properly & printing the calculated version of the current commit:
# Remark: malfunctioning of GitVersion (likely due to misconfiguration) is often a cause for
# subsequent build to fail.
- name: CHECK GitVersion
shell: pwsh
run: |
Write-Host "Verifying GitVersion and printing version of the current commit..."
cd ${{ env.REPO_DIR }}
Write-Host "Directory for getting the version:`n $($(Get-Location).Path)"
Write-Host "Running: 'dotnet gitversion /showvariable FullSemVer'"
Write-Host "Repository VERSION returned by GitVersion:"
dotnet gitversion /showvariable FullSemVer
# RESTORE DEPENDENCIES
- name: Restore NuGet packages
shell: pwsh
run: |
Write-Host "Restoring NuGet packages for ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx ... `n"
dotnet restore ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx
# BUILD Main Project & Test Project in Release Mode
- name: Build Solution
shell: pwsh
run: |
Write-Host "Building solution: ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx ... `n"
dotnet build ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx --configuration Release --no-restore
# RUN TESTS & COLLECT RESULTS
- name: Run Tests
id: teststep
# shell: pwsh
# Remark: we use the solution instead of projects.
shell: pwsh
continue-on-error: true # ToDo: set to false later!
run: |
Write-Host "Running tests for ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx ... `n"
dotnet test ${{ env.REPO_DIR }}/${{ env.REPO_DIR }}.slnx --configuration Release --logger trx --results-directory TestResults
# ${{ env.IGNORE_TEST_ERRORS }}
- name: Upload test results
if: always() # runs even if previous step failed
uses: actions/upload-artifact@v4
with:
# Name of the uploaded artifact (arbitrary):
name: TestResults
# Path (relative to the workspace) of the file(s) or folder(s) to
# upload as artifact:
path: ./TestResults
# Report tests failure
- name: Report tests failure
if: steps.teststep.outcome == 'failure'
run: echo "⚠️ Some tests failed, but the pipeline will continue."
# UPLOAD BUILD OUTPUT (DLLs, EXEs, etc.)
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: BuildArtifacts
path: ${{ env.SOURCE_DIR }}/bin/Release/
# RUN a TEST SCRIPT (PowerShell)
- name: Run Post-Build PowerShell Script
run: pwsh -File ${{ env.REPO_DIR }}/scripts/PrintEnv.ps1