fix: topology not always reverted back after reverting settings (#125) #418
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: CI | |
on: | |
pull_request: | |
branches: | |
- master | |
types: | |
- opened | |
- synchronize | |
- reopened | |
push: | |
branches: | |
- master | |
concurrency: | |
group: "${{ github.workflow }}-${{ github.ref }}" | |
cancel-in-progress: true | |
jobs: | |
setup_release: | |
name: Setup Release | |
outputs: | |
publish_release: ${{ steps.setup_release.outputs.publish_release }} | |
release_body: ${{ steps.setup_release.outputs.release_body }} | |
release_commit: ${{ steps.setup_release.outputs.release_commit }} | |
release_generate_release_notes: ${{ steps.setup_release.outputs.release_generate_release_notes }} | |
release_tag: ${{ steps.setup_release.outputs.release_tag }} | |
release_version: ${{ steps.setup_release.outputs.release_version }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Release | |
id: setup_release | |
uses: LizardByte/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
name: Build | |
needs: [setup_release] | |
runs-on: ${{ matrix.os }} | |
defaults: | |
run: | |
shell: ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Setup Dependencies Linux | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y \ | |
build-essential \ | |
cmake \ | |
ninja-build \ | |
nlohmann-json3-dev | |
- name: Setup Dependencies macOS | |
if: runner.os == 'macOS' | |
run: | | |
brew install \ | |
boost \ | |
cmake \ | |
doxygen \ | |
graphviz \ | |
nlohmann-json \ | |
ninja \ | |
node \ | |
- name: Setup Dependencies Windows | |
if: runner.os == 'Windows' | |
uses: msys2/setup-msys2@v2 | |
with: | |
msystem: ucrt64 | |
update: true | |
install: >- | |
doxygen | |
mingw-w64-ucrt-x86_64-binutils | |
mingw-w64-ucrt-x86_64-cmake | |
mingw-w64-ucrt-x86_64-graphviz | |
mingw-w64-ucrt-x86_64-ninja | |
mingw-w64-ucrt-x86_64-nodejs | |
mingw-w64-ucrt-x86_64-toolchain | |
mingw-w64-ucrt-x86_64-boost | |
mingw-w64-ucrt-x86_64-nlohmann-json | |
- name: Prepare tests | |
id: prepare-tests | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
# function to download and extract a zip file | |
function DownloadAndExtract { | |
param ( | |
[string]$Uri, | |
[string]$OutFile | |
) | |
$maxRetries = 5 | |
$retryCount = 0 | |
$success = $false | |
while (-not $success -and $retryCount -lt $maxRetries) { | |
$retryCount++ | |
Write-Host "Downloading $Uri to $OutFile, attempt $retryCount of $maxRetries" | |
try { | |
Invoke-WebRequest -Uri $Uri -OutFile $OutFile | |
$success = $true | |
} catch { | |
Write-Host "Attempt $retryCount of $maxRetries failed with error: $($_.Exception.Message). Retrying..." | |
Start-Sleep -Seconds 5 | |
} | |
} | |
if (-not $success) { | |
Write-Host "Failed to download the file after $maxRetries attempts." | |
exit 1 | |
} | |
# use .NET to get the base name of the file | |
$baseName = (Get-Item $OutFile).BaseName | |
# Extract the zip file | |
Expand-Archive -Path $OutFile -DestinationPath $baseName | |
} | |
# virtual display driver | |
DownloadAndExtract ` | |
-Uri "https://www.amyuni.com/downloads/usbmmidd_v2.zip" ` | |
-OutFile "usbmmidd_v2.zip" | |
# install | |
Set-Location -Path usbmmidd_v2/usbmmidd_v2 | |
./deviceinstaller64 install usbmmidd.inf usbmmidd | |
# create 2 virtual displays, using 3+ can crash the runner | |
# see: https://github.com/LizardByte/libdisplaydevice/pull/36 | |
for ($i = 1; $i -le 2; $i++) { | |
./deviceinstaller64 enableidd 1 | |
} | |
- name: Setup python | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Python Path | |
id: python-path | |
run: | | |
if [ "${{ runner.os }}" == "Windows" ]; then | |
# replace backslashes with double backslashes | |
python_path=$(echo "${{ steps.setup-python.outputs.python-path }}" | sed 's/\\/\\\\/g') | |
else | |
python_path="${{ steps.setup-python.outputs.python-path }}" | |
fi | |
# step output | |
echo "python-path=${python_path}" | |
echo "python-path=${python_path}" >> $GITHUB_OUTPUT | |
- name: Build | |
env: | |
BRANCH: ${{ github.head_ref || github.ref_name }} | |
BUILD_VERSION: ${{ needs.setup_release.outputs.release_tag }} | |
COMMIT: ${{ needs.setup_release.outputs.release_commit }} | |
run: | | |
mkdir -p build | |
if [ "${{ runner.os }}" = "Linux" ]; then | |
# Doxygen from Ubuntu is too old, need Doxygen >= 1.10 | |
DOCS=OFF | |
else | |
DOCS=ON | |
fi | |
cmake \ | |
-DBUILD_DOCS=${DOCS} \ | |
-DCMAKE_BUILD_TYPE:STRING=Debug \ | |
-B build \ | |
-G Ninja \ | |
-S . | |
ninja -C build | |
- name: Run tests | |
id: test | |
working-directory: build/tests | |
run: | | |
./test_libdisplaydevice --gtest_color=yes | |
- name: Generate gcov report | |
# any except canceled or skipped | |
if: always() && (steps.test.outcome == 'success' || steps.test.outcome == 'failure') | |
id: test_report | |
working-directory: build | |
run: | | |
${{ steps.python-path.outputs.python-path }} -m pip install gcovr | |
${{ steps.python-path.outputs.python-path }} -m gcovr . -r ../src \ | |
--exclude-noncode-lines \ | |
--exclude-throw-branches \ | |
--exclude-unreachable-branches \ | |
--verbose \ | |
--xml-pretty \ | |
-o coverage.xml | |
- name: Upload coverage artifact | |
if: >- | |
always() && | |
(steps.test_report.outcome == 'success') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-${{ matrix.os }} | |
path: build/coverage.xml | |
- name: Move Artifacts | |
run: | | |
mkdir -p artifacts | |
if ["${{ runner.os }}" == "Windows"]; then | |
mv -f ./build/tests/test_libdisplaydevice.exe artifacts/ | |
else | |
mv -f ./build/tests/test_libdisplaydevice artifacts/ | |
fi | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-${{ runner.os }} | |
path: artifacts/ | |
coverage: | |
if: >- | |
always() && | |
(needs.build.result == 'success' || needs.build.result == 'failure') && | |
startsWith(github.repository, 'LizardByte/') | |
name: Coverage-${{ matrix.flag }} | |
needs: build | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- build_os: ubuntu-latest | |
flag: Linux | |
- build_os: macos-latest | |
flag: macOS | |
- build_os: windows-latest | |
flag: Windows | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download coverage artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage-${{ matrix.build_os }} | |
path: _coverage | |
- name: Debug coverage file | |
run: | | |
cat _coverage/coverage.xml | |
- name: Upload coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
disable_search: true | |
fail_ci_if_error: true | |
files: ./_coverage/coverage.xml | |
flags: ${{ matrix.flag }} | |
token: ${{ secrets.CODECOV_TOKEN }} | |
verbose: true | |
release: | |
if: | |
always() && | |
needs.setup_release.outputs.publish_release == 'true' && | |
needs.build.result == 'success' && | |
startsWith(github.repository, 'LizardByte/') | |
name: Release | |
needs: [build, setup_release] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download build artifact (Windows) | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-Windows | |
path: build-Windows | |
- name: Download build artifact (Linux) | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-Linux | |
path: build-Linux | |
- name: Download build artifact (macOS) | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-macOS | |
path: build-macOS | |
- name: Move artifacts | |
run: | | |
mkdir -p artifacts | |
mv -f build-Windows/test_libdisplaydevice.exe artifacts/test_libdisplaydevice-Windows.exe | |
mv -f build-Linux/test_libdisplaydevice artifacts/test_libdisplaydevice-Linux | |
mv -f build-macOS/test_libdisplaydevice artifacts/test_libdisplaydevice-macOS | |
- name: Create/Update GitHub Release | |
if: ${{ needs.setup_release.outputs.publish_release == 'true' }} | |
uses: LizardByte/[email protected] | |
with: | |
allowUpdates: true | |
body: ${{ needs.setup_release.outputs.release_body }} | |
generateReleaseNotes: ${{ needs.setup_release.outputs.release_generate_release_notes }} | |
name: ${{ needs.setup_release.outputs.release_tag }} | |
prerelease: true | |
tag: ${{ needs.setup_release.outputs.release_tag }} | |
token: ${{ secrets.GH_BOT_TOKEN }} |