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