Skip to content

Commit

Permalink
Merge branch 'ci/github-parallel-samples-execution' into 'main'
Browse files Browse the repository at this point in the history
Run samples in parallel on GitHub Actions

See merge request Sharpmake/sharpmake!410
  • Loading branch information
jspelletier committed Jun 28, 2023
2 parents 538b402 + 07975eb commit f3e7505
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 178 deletions.
52 changes: 52 additions & 0 deletions .github/Get-SamplesMatrixJson.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<#
.SYNOPSIS
Gets the matrix strategy used to generate samples jobs on GitHub Actions.
.DESCRIPTION
Transform the content of SamplesDef.json into a GitHub Actions matrix strategy representation that can be used to generate samples job.
.OUTPUTS
System.String
Get-SamplesMatrixJson returns the samples job matrix strategy formatted as JSON.
#>

# Load samples definitions.
$samplesDef = Get-Content -Raw -Path "SamplesDef.json" | ConvertFrom-Json

# Transform into a list of samples matrix configurations.
$matrixInclude = foreach ($sample in $samplesDef.Samples)
{
if ($sample.CIs.Contains("github"))
{
foreach ($os in $sample.OSs)
{
foreach ($framework in $sample.Frameworks)
{
# Map os to GitLab runner label
$runsOn = switch ( $os )
{
'linux' { 'ubuntu-latest' }
'macos' { 'macos-latest' }
default { $os }
}

[pscustomobject]@{
name = $sample.Name
os = $runsOn
framework = $framework
configurations = $sample.Configurations -join ','
}
}
}
}
}

# Explicit matrix configurations with include only matrix strategy.
# See https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#example-adding-configurations.
$samplesMatrix = [pscustomobject]@{
include = $matrixInclude
}

# Output matrix object as Json.
# Enable dynamically specifying samples jobs by passing the produced Json as the matrix strategy.
$samplesMatrix | ConvertTo-Json
189 changes: 28 additions & 161 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,32 @@ jobs:
if: runner.os == 'Windows'
run: python functional_test.py --sharpmake_exe "Sharpmake.Application/bin/release/${{ matrix.framework }}/Sharpmake.Application.exe"

samples:
generate_samples_matrix:
needs: [builds]
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout the repo
uses: actions/[email protected]

- name: Generate samples matrix
id: set-matrix
shell: pwsh
run: |
$sampleMatrix = .\.github\Get-SamplesMatrixJson.ps1
echo $sampleMatrix
$eof = [Convert]::ToBase64String((Get-Random -InputObject (0..255) -Count 15 | ForEach-Object { [byte]$_ }))
echo "matrix<<$eof" >> $env:GITHUB_OUTPUT
echo $sampleMatrix >> $env:GITHUB_OUTPUT
echo "$eof" >> $env:GITHUB_OUTPUT
samples:
needs: [generate_samples_matrix]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019, windows-2022]
framework: [net6.0]
configuration: [debug, release]
matrix: ${{fromJSON(needs.generate_samples_matrix.outputs.matrix)}}
steps:
- name: Checkout the repo
uses: actions/[email protected]
Expand All @@ -81,167 +98,17 @@ jobs:
name: 'Sharpmake-${{ matrix.framework }}-${{ runner.os }}-${{ github.sha }}'
path: Sharpmake.Application/bin/Release/${{ matrix.framework }}

- name: CompileCommandDatabase ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.configuration == 'debug' # only has a debug config, so skip in release
shell: pwsh
run: | # TODO: ideally here we should try and compile the generated json file
.\RunSample.ps1 -sampleName "CompileCommandDatabase" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: ConfigureOrder ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.configuration == 'release'
shell: pwsh
run:
.\RunSample.ps1 -sampleName "ConfigureOrder" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}

- name: CPPCLI ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2019'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CPPCLI" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: CSharpHelloWorld old frameworks ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2019'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CSharpHelloWorld_old_frameworks" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: CSharpHelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2022'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CSharpHelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: CSharpImports ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CSharpImports" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: CSharpVsix ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CSharpVsix" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
# that one can't be run unfortunately

- name: CustomBuildStep ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CustomBuildStep" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: CSharpWCF ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "CSharpWCF" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
# that one can't be run unfortunately

- name: FastBuildSimpleExecutable ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "FastBuildSimpleExecutable" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }} -vsVersionSuffix ${env:VS_VERSION_SUFFIX}
# Temp disable after Github VM update which updated the NDK and broke it
# - name: HelloAndroid ${{ matrix.configuration }}
# if: runner.os == 'Windows'
# shell: pwsh
# run: |
# $env:JAVA_HOME = $env:JAVA_HOME_11_X64
# .\RunSample.ps1 -sampleName "HelloAndroid" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}

- name: HelloClangCl ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "HelloClangCl" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }} -vsVersionSuffix ${env:VS_VERSION_SUFFIX}
- name: HelloEvents ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "HelloEvents" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }} -vsVersionSuffix ${env:VS_VERSION_SUFFIX}
- name: HelloLinux ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Linux'
shell: pwsh
run: |
docker build -f samples/HelloLinux/Dockerfile -t sharpmake-hellolinux --build-arg CONFIGURATION=${{ matrix.configuration }} --build-arg FRAMEWORK=${{ matrix.framework }} .
docker run --rm sharpmake-hellolinux
- name: HelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "HelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: HelloXCode ${{ matrix.configuration }} ${{ matrix.os }}
shell: pwsh
if: runner.os == 'macOS'
run: |
.\RunSample.ps1 -sampleName "HelloXCode" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: NetCore/DotNetCoreFrameworkHelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2022'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "NetCore-DotNetCoreFrameworkHelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: NetCore/DotNetFrameworkHelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "NetCore-DotNetFrameworkHelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: NetCore/DotNetFrameworkHelloWorld_OldFrameworks ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2019'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "NetCore-DotNetFrameworkHelloWorld_OldFrameworks" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: NetCore/DotNetMultiFrameworksHelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "NetCore-DotNetMultiFrameworksHelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: NetCore/DotNetOSMultiFrameworksHelloWorld ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.os == 'windows-2022'
run: |
.\RunSample.ps1 -sampleName "NetCore-DotNetOSMultiFrameworksHelloWorld" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: PackageReferences ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "PackageReferences" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: Install Qt
if: runner.os == 'Windows'
uses: jurplel/[email protected]

- name: QTFileCustomBuild ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows'
shell: pwsh
run: | # TODO: there's a retail config, compile it as well or remove it
.\RunSample.ps1 -sampleName "QTFileCustomBuild" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: SimpleExeLibDependency ${{ matrix.configuration }} ${{ matrix.os }}
if: runner.os == 'Windows' && matrix.configuration == 'debug'
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "SimpleExeLibDependency" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }}
- name: vcpkg ${{matrix.configuration}} ${{ matrix.os }}
if: runner.os == 'Windows'
- name: Run sample ${{ matrix.name }} ${{ matrix.os }} ${{ matrix.framework }} ${{ matrix.configuration }}
shell: pwsh
run: |
.\RunSample.ps1 -sampleName "vcpkg" -configuration ${{ matrix.configuration }} -framework ${{ matrix.framework }} -os ${{ matrix.os }} -vsVersionSuffix ${env:VS_VERSION_SUFFIX}
foreach ($configuration in '${{ matrix.configurations }}'.Split(','))
{
.\RunSample.ps1 -sampleName "${{ matrix.name }}" -configuration $configuration -framework ${{ matrix.framework }} -os ${{ matrix.os }} -vsVersionSuffix ${env:VS_VERSION_SUFFIX}
}
- name: Store MSBuild binary logs
if: ${{ failure() && runner.os == 'Windows' }}
uses: actions/upload-artifact@v3
with:
name: sharpmake-samples-msbuild-logs-${{ matrix.framework }}-${{ runner.os }}-${{ github.sha }}-${{ matrix.configuration }}
name: sharpmake-sample-msbuild-logs-${{ matrix.name }}-${{ matrix.framework }}-${{ runner.os }}-${{ github.sha }}-${{ matrix.configuration }}
path: samples/**/*.binlog
31 changes: 23 additions & 8 deletions .gitlab/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,29 @@ functional_test:
HelloLinux:
extends: .linux_sample_test
script:
- docker build -f samples/HelloLinux/Dockerfile -t sharpmake-hellolinux --build-arg CONFIGURATION=$configuration --build-arg FRAMEWORK=$framework .
- docker run --rm sharpmake-hellolinux
# Install Powershell on Alpine (https://learn.microsoft.com/en-us/powershell/scripting/install/install-alpine?view=powershell-7.2)
- apk add --no-cache
ca-certificates
less
ncurses-terminfo-base
krb5-libs
libgcc
libintl
libssl1.1
libstdc++
tzdata
userspace-rcu
zlib
icu-libs
curl
- apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust
- curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.2.11/powershell-7.2.11-linux-alpine-x64.tar.gz -o /tmp/powershell.tar.gz
- mkdir -p /opt/microsoft/powershell/7
- tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
- chmod +x /opt/microsoft/powershell/7/pwsh
- ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
# Run HelloLinux sample
- pwsh ./RunSample.ps1 -sampleName HelloLinux -configuration $configuration

#############
# MacOs Sample tests
Expand Down Expand Up @@ -308,14 +329,8 @@ PackageReferences:

QTFileCustomBuild:
extends: .windows_sample_test
variables:
Qt_BaseDir: "$CI_PROJECT_DIR\\Qt"
Qt5_Dir: "$Qt_BaseDir\\5.15.2\\msvc2019_64" # Needed by sample to build Qt paths.
before_script:
- choco install python3 --version 3.10.6 --side-by-side -y --no-progress
- py -m pip install aqtinstall
- py -m aqt install-qt windows desktop 5.15.2 win64_msvc2019_64 --archives qtbase qttools --outputdir ${env:Qt_BaseDir}
- $Env:PATH = "${env:Qt5_Dir}\bin;" + $Env:PATH # Needed by sample executable to locate Qt DLLs.
script:
- pwsh RunSample.ps1 -sampleName "QTFileCustomBuild" -configuration $configuration -framework $framework -os $os

Expand Down
4 changes: 4 additions & 0 deletions RunSample.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ param ([string] $sampleName, [string] $configuration, [string] $framework, [stri
class SampleDef
{
[string] $Name
[string[]] $CIs
[string[]] $OSs
[string[]] $Frameworks
[string[]] $Configurations
[string] $TestFolder = ""
[string[]] $Commands
}
Expand Down
Loading

0 comments on commit f3e7505

Please sign in to comment.