test: add screenshots (#86)

Co-authored-by: Thomas Van Laere <4990509+thomvanl@users.noreply.github.com>
This commit is contained in:
David LaneandThomas Van Laere authored and GitHub committed 2026-03-22 22:22:24 -04:00
1 parent 7ce2adc9b7
commit 7936cb35ae
13 files changed
+1395 -107

No files matched your search

+95 -9
View File
@@ -29,9 +29,11 @@ jobs:
shell: "bash"
- os: ubuntu-latest
appindicator: "libayatana-appindicator3-dev"
appindicator_type: "ayatana"
shell: "bash"
- os: ubuntu-latest
appindicator: "libappindicator3-dev"
appindicator_type: "legacy"
shell: "bash"
- os: windows-latest
shell: "msys2 {0}"
@@ -49,11 +51,19 @@ jobs:
build-essential \
cmake \
${{ matrix.appindicator }} \
imagemagick \
libglib2.0-dev \
libnotify-dev \
ninja-build \
xvfb
- name: Setup virtual desktop
if: runner.os == 'Linux'
uses: LizardByte/actions/actions/virtual_desktop@70bb8d394d1c92f6113aeec6ae9cc959a5763d15 # v2026.227.200013
with:
appindicator-version: ${{ matrix.appindicator_type }}
environment: mate
- name: Setup Dependencies macOS
if: runner.os == 'macOS'
run: |
@@ -62,9 +72,45 @@ jobs:
cmake \
doxygen \
graphviz \
imagemagick \
ninja \
node
- name: Fix macOS screen recording permissions
if: runner.os == 'macOS'
run: |
set -euo pipefail
configure_system_tccdb() {
local values=$1
local dbPath="/Library/Application Support/com.apple.TCC/TCC.db"
local sqlQuery="INSERT OR IGNORE INTO access VALUES($values);"
sudo sqlite3 "$dbPath" "$sqlQuery"
}
configure_user_tccdb() {
local values=$1
local dbPath="$HOME/Library/Application Support/com.apple.TCC/TCC.db"
local sqlQuery="INSERT OR IGNORE INTO access VALUES($values);"
sqlite3 "$dbPath" "$sqlQuery"
}
systemValuesArray=(
"'kTCCServiceScreenCapture','/bin/bash',1,2,0,1,NULL,NULL,NULL,'UNUSED',NULL,0,1599831148"
)
for values in "${systemValuesArray[@]}"; do
configure_system_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
done
userValuesArray=(
"'kTCCServiceScreenCapture','/bin/bash',1,2,0,1,NULL,NULL,NULL,'UNUSED',NULL,0,1583997993"
)
for values in "${userValuesArray[@]}"; do
configure_user_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
done
echo "macOS TCC permissions configured."
- name: Setup Dependencies Windows
if: runner.os == 'Windows'
uses: msys2/setup-msys2@4f806de0a5a7294ffabaff804b38a9b435a73bda # v2.30.0
@@ -76,6 +122,7 @@ jobs:
mingw-w64-ucrt-x86_64-binutils
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-graphviz
mingw-w64-ucrt-x86_64-imagemagick
mingw-w64-ucrt-x86_64-ninja
mingw-w64-ucrt-x86_64-nodejs
mingw-w64-ucrt-x86_64-toolchain
@@ -98,7 +145,7 @@ jobs:
# step output
echo "python-path=${python_path}"
echo "python-path=${python_path}" >> $GITHUB_OUTPUT
echo "python-path=${python_path}" >> "${GITHUB_OUTPUT}"
- name: Build
run: |
@@ -119,18 +166,57 @@ jobs:
-S .
ninja -C build
- name: Init tray icon (Windows)
if: runner.os == 'Windows'
working-directory: build/tests
run: ./test_tray --gtest_color=yes --gtest_filter=TrayTest.TestTrayInit
- name: Configure Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
echo "::group::Enable all tray icons"
Invoke-WebRequest `
-Uri "https://raw.githubusercontent.com/paulmann/windows-show-all-tray-icons/main/Enable-AllTrayIcons.ps1" `
-OutFile "Enable-AllTrayIcons.ps1"
.\Enable-AllTrayIcons.ps1 -Action Enable -Force # Enable with comprehensive method (resets ALL icon settings)
echo "::endgroup::"
echo "::group::Disable Do Not Disturb"
Add-Type -AssemblyName System.Windows.Forms
Start-Process "ms-settings:notifications"
Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
[System.Windows.Forms.SendKeys]::SendWait(" ")
echo "::endgroup::"
echo "::group::Minimize all windows"
$shell = New-Object -ComObject Shell.Application
$shell.MinimizeAll()
echo "::endgroup::"
echo "::group::Set Date - Hack for Quiet Time"
$newDate = (Get-Date).AddHours(2)
Set-Date -Date $newDate
echo "::endgroup::"
- name: Run tests
id: test
# TODO: tests randomly hang on Linux, https://github.com/LizardByte/tray/issues/45
timeout-minutes: 1
timeout-minutes: 3
working-directory: build/tests
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
export DISPLAY=:1
Xvfb ${DISPLAY} -screen 0 1024x768x24 &
fi
run: ./test_tray --gtest_color=yes --gtest_output=xml:test_results.xml
./test_tray --gtest_color=yes --gtest_output=xml:test_results.xml
- name: Upload screenshots
if: >-
always() &&
(steps.test.outcome == 'success' || steps.test.outcome == 'failure')
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: tray-screenshots-${{ runner.os }}${{ matrix.appindicator && format('-{0}', matrix.appindicator) || '' }}
path: build/tests/screenshots
if-no-files-found: error
- name: Generate gcov report
id: test_report
@@ -159,7 +245,7 @@ jobs:
if [ -n "${{ matrix.appindicator }}" ]; then
flags="${flags},${{ matrix.appindicator }}"
fi
echo "flags=${flags}" >> $GITHUB_OUTPUT
echo "flags=${flags}" >> "${GITHUB_OUTPUT}"
- name: Upload coverage
# any except canceled or skipped
+258
View File
@@ -0,0 +1,258 @@
---
name: Publish Screenshots
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
actions: read
contents: write
pull-requests: write
jobs:
publish:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}
path: run-screenshots
pattern: tray-screenshots-*
- name: Prepare Matrix Screenshot Directories
run: |
mkdir -p prepared
shopt -s nullglob
for artifact_dir in run-screenshots/tray-screenshots-*; do
[ -d "${artifact_dir}" ] || continue
matrix_name="${artifact_dir##*/tray-screenshots-}"
mkdir -p "prepared/${matrix_name}"
cp -R "${artifact_dir}/." "prepared/${matrix_name}/"
done
if [ -z "$(find prepared -mindepth 1 -print -quit)" ]; then
echo "No screenshots were downloaded from CI artifacts."
exit 1
fi
echo "Prepared screenshot files:"
find prepared -type f | sort
- name: Determine Context
id: context
env:
WORKFLOW_EVENT: ${{ github.event.workflow_run.event }}
WORKFLOW_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
event_name="${WORKFLOW_EVENT}"
head_branch="${WORKFLOW_HEAD_BRANCH}"
pr_number="$(jq -r '.workflow_run.pull_requests[0].number // empty' "${GITHUB_EVENT_PATH}")"
if [ -n "${pr_number}" ] && ! [[ "${pr_number}" =~ ^[0-9]+$ ]]; then
echo "Invalid pr_number value: ${pr_number}"
exit 1
fi
is_pr=false
if [ "${event_name}" = "pull_request" ] && [ -n "${pr_number}" ]; then
is_pr=true
fi
is_master_push=false
if [ "${event_name}" = "push" ] && [ "${head_branch}" = "master" ]; then
is_master_push=true
fi
{
echo "event_name=${event_name}"
echo "head_branch=${head_branch}"
echo "is_pr=${is_pr}"
echo "pr_number=${pr_number}"
echo "is_master_push=${is_master_push}"
} >> "${GITHUB_OUTPUT}"
- name: Checkout Screenshots Branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: screenshots
path: screenshots-repo
- name: Sync Screenshot Content
id: sync
if: steps.context.outputs.is_master_push == 'true' || steps.context.outputs.is_pr == 'true'
env:
PR_NUMBER: ${{ steps.context.outputs.pr_number }}
run: |
target_dir=""
if [ "${{ steps.context.outputs.is_master_push }}" = "true" ]; then
target_dir="screenshots-repo/baseline"
elif [ "${{ steps.context.outputs.is_pr }}" = "true" ]; then
if ! [[ "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then
echo "Invalid PR number: ${PR_NUMBER}"
exit 1
fi
target_dir="screenshots-repo/pull-requests/PR-${PR_NUMBER}"
else
echo "Unsupported workflow context for screenshot sync."
exit 1
fi
mkdir -p "${target_dir}"
# Mirror the prepared set and delete files removed from CI output.
rsync -a --delete prepared/ "${target_dir}/"
echo "target_dir=${target_dir}" >> "${GITHUB_OUTPUT}"
- name: Build PR Screenshot Comparison Comment
if: steps.context.outputs.is_pr == 'true'
env:
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.context.outputs.pr_number }}
BASELINE_ROOT: screenshots-repo/baseline
PR_ROOT: prepared
run: |
raw_base="https://raw.githubusercontent.com/${REPOSITORY}/screenshots"
baseline_root="${BASELINE_ROOT}"
pr_root="${PR_ROOT}"
{
echo "## Screenshot Comparison"
echo
printf "PR #%s screenshots vs \`screenshots\` baseline.\n\n" "${PR_NUMBER}"
} > pr-comment.md
tmp_baseline="$(mktemp)"
tmp_pr="$(mktemp)"
tmp_matrices="$(mktemp)"
if [ -d "${baseline_root}" ]; then
find "${baseline_root}" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' >> "${tmp_matrices}"
fi
if [ -d "${pr_root}" ]; then
find "${pr_root}" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' >> "${tmp_matrices}"
fi
if [ ! -s "${tmp_matrices}" ]; then
echo "No matrix screenshots were found in baseline or PR artifacts." >> pr-comment.md
rm -f "${tmp_baseline}" "${tmp_pr}" "${tmp_matrices}"
exit 0
fi
while IFS= read -r matrix; do
[ -n "${matrix}" ] || continue
baseline_matrix="${baseline_root}/${matrix}"
pr_matrix="${pr_root}/${matrix}"
: > "${tmp_baseline}"
: > "${tmp_pr}"
if [ -d "${baseline_matrix}" ]; then
(
cd "${baseline_matrix}"
find . -type f | sed 's#^\./##' | LC_ALL=C sort
) > "${tmp_baseline}"
fi
if [ -d "${pr_matrix}" ]; then
(
cd "${pr_matrix}"
find . -type f | sed 's#^\./##' | LC_ALL=C sort
) > "${tmp_pr}"
fi
{
printf "### Matrix: \`%s\`\n\n" "${matrix}"
echo "| Image | Baseline | PR |"
echo "| --- | --- | --- |"
} >> pr-comment.md
tmp_all="$(mktemp)"
cat "${tmp_baseline}" "${tmp_pr}" | LC_ALL=C sort -u > "${tmp_all}"
if [ ! -s "${tmp_all}" ]; then
echo "| _(none)_ | | |" >> pr-comment.md
echo >> pr-comment.md
rm -f "${tmp_all}"
continue
fi
while IFS= read -r rel_file; do
[ -n "${rel_file}" ] || continue
baseline_cell=""
if grep -Fxq "${rel_file}" "${tmp_baseline}"; then
baseline_cell="<img src=\"${raw_base}/baseline/${matrix}/${rel_file}\" width=\"320\" />"
fi
pr_cell=""
if grep -Fxq "${rel_file}" "${tmp_pr}"; then
pr_cell="<img src=\"${raw_base}/pull-requests/PR-${PR_NUMBER}/${matrix}/${rel_file}\" width=\"320\" />"
fi
printf "| \`%s\` | %s | %s |\n" "${rel_file}" "${baseline_cell}" "${pr_cell}" >> pr-comment.md
done < "${tmp_all}"
echo >> pr-comment.md
rm -f "${tmp_all}"
done < <(LC_ALL=C sort -u "${tmp_matrices}")
rm -f "${tmp_baseline}" "${tmp_pr}" "${tmp_matrices}"
echo "Generated pr-comment.md"
- name: Commit and Push Screenshot Changes
id: push
if: steps.context.outputs.is_master_push == 'true' || steps.context.outputs.is_pr == 'true'
env:
PR_NUMBER: ${{ steps.context.outputs.pr_number }}
WORKFLOW_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
cd screenshots-repo
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
commit_message=""
if [ "${{ steps.context.outputs.is_master_push }}" = "true" ]; then
git add -A baseline
commit_message="chore: update screenshots (${WORKFLOW_HEAD_SHA})"
elif [ "${{ steps.context.outputs.is_pr }}" = "true" ]; then
if ! [[ "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then
echo "Invalid PR number: ${PR_NUMBER}"
exit 1
fi
git add -A "pull-requests/PR-${PR_NUMBER}"
commit_message="chore: update PR-${PR_NUMBER} screenshots (${WORKFLOW_HEAD_SHA})"
else
echo "Unsupported workflow context for commit/push."
exit 1
fi
if git diff --cached --quiet; then
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
git commit -m "${commit_message}"
git push origin screenshots
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
- name: Post PR Comparison Comment
if: steps.context.outputs.is_pr == 'true'
uses: mshick/add-pr-comment@ffd016c7e151d97d69d21a843022fd4cd5b96fe5 # v3.9.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue: ${{ steps.context.outputs.pr_number }}
message-path: pr-comment.md
message-id: screenshot-comparison
refresh-message-position: true