* replace Imgur with GitHub Release Assets for screenshot hosting Fixes #3548 ## Problem Imgur API returns "Too Many Requests" errors (code 1025), blocking successfully tested applications from being merged. ## Solution Replace Imgur with GitHub Release Assets: - Screenshots are uploaded to a draft release named 'ci-screenshots' - Inline images displayed in PR comments - Works for PRs from external contributors using workflow_run trigger * sanitize filenames for artifact upload - Add step to sanitize screenshot filenames before upload - Remove invalid characters (: * ? < > |) from app names - Fixes error with apps like 'fre:ac' containing colons - Update publish workflow to handle flat file structure * ci: fix artifact path and publish release; guard workflow to upstream repo
157 lines
7.6 KiB
YAML
157 lines
7.6 KiB
YAML
name: Test
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
# Do not build PRs twice
|
|
- 'master'
|
|
paths:
|
|
- 'data/**'
|
|
pull_request:
|
|
paths:
|
|
- 'data/**'
|
|
|
|
env:
|
|
DISPLAY: :99
|
|
IS_PULLREQUEST: ${{ github.event_name == 'pull_request' }}
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-22.04
|
|
timeout-minutes: 10
|
|
permissions:
|
|
actions: write
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
# https://github.com/actions/checkout#Fetch-all-history-for-all-tags-and-branches
|
|
# According to the docs for checkout@v2, Only a single commit is fetched by default, but
|
|
# providing a fetch-depth of 0 should fetch all history.
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Configure APT Packages
|
|
uses: awalsh128/[email protected]
|
|
# This action handles caching APT packages, and leaves the option for package configuration scripts to be run if needed,
|
|
# saving a boat-load of time, if needed bump the action version.
|
|
with:
|
|
packages: sudo imagemagick libasound2-dev pulseaudio-utils alsa-utils alsa-oss libjack0 desktop-file-utils xmlstarlet xsel xterm xvfb icewm x11-utils x11-apps netpbm xdotool libgl1-mesa-dri libgl1-mesa-dev mesa-utils libosmesa6 libsdl1.2-dev libsdl2-2.0-0 fonts-wqy-microhei libfile-mimeinfo-perl
|
|
version: 1.0
|
|
# Bump me ^ if you have added any new packages
|
|
- name: Install dependencies
|
|
shell: bash
|
|
run: |
|
|
# set -e
|
|
sudo bash code/prep-dummy-soundcard.sh
|
|
# TODO Cache gem and npm packages
|
|
sudo gem install dupervisor -v 1.0.5 # To convert ini to yaml files
|
|
sudo npm install -g asar # to get pacakges.json from resources/app.asar for electron-builder applications
|
|
# npm install -g @alexlafroscia/yaml-merge # to merge yaml files
|
|
- name: Mark screenshot start (PR only)
|
|
if: github.event_name == 'pull_request'
|
|
run: |
|
|
touch .screenshots_start
|
|
- name: Main test
|
|
# shell: bash
|
|
run: |
|
|
# set -e
|
|
mkdir $HOME/.icewm/
|
|
echo "ShowTaskBar = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarAutoHide = 1" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowWorkspaces = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowAllWindows = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowClock = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowMailboxStatus = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowCPUStatus = 0" > $HOME/.icewm/preferences
|
|
echo "TaskBarShowWindowListMenu = 0" > $HOME/.icewm/preferences
|
|
# xpra start :99 # Cannot get screenshots to work
|
|
Xvfb :99 -screen 0 800x600x24 >/dev/null 2>&1 & # Need to set bit depth, otherwise get some black screenshots
|
|
# until xset -q; do echo "Waiting for X server to start..."; sleep 1; done # We are not immediately using it anyway
|
|
# Find out which files in data/ have been changed in the last commit
|
|
#set -x # Debug #379
|
|
FILES=$(git log -1 -p data/ | grep +++ | cut -d '/' -f 2-| sed -e 's|dev/null||g')
|
|
# Finds wrong files in PRs! # FILES=$(git log -1 --name-status --diff-filter=AR --pretty=format: -- data/ | awk '/^A/ || /^R/ {file=$2} END {print file}') # Most recent addition or renaming within the last commit
|
|
echo "Last changed files from the FILES variable:"
|
|
echo "$FILES" ; if [ -z "$FILES" ] ; then echo "Variable FILES is empty." && exit 1 ; fi
|
|
# Work on these files that have been changed in the last commit
|
|
if [ -n "$FILES" ]; then
|
|
for FILE in $FILES; do
|
|
echo "$FILE"
|
|
bash -e code/worker.sh $(readlink -f "$FILE") 2>&1 | tee log.txt
|
|
EXIT_CODE=${PIPESTATUS[0]} # bashism; get the return code of the leftmost element of the pipe
|
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
echo "worker.sh exited with a non-zero code: $EXIT_CODE"
|
|
exit $EXIT_CODE
|
|
fi
|
|
done
|
|
fi
|
|
# xpra stop :99
|
|
killall Xvfb
|
|
# bundle exec jekyll build # https://help.github.com/en/articles/viewing-jekyll-build-error-messages#configuring-a-third-party-service-to-display-jekyll-build-error-messages
|
|
- name: Prepare screenshots for upload
|
|
if: github.event_name == 'pull_request'
|
|
shell: bash
|
|
run: |
|
|
mkdir -p screenshots-upload
|
|
# only files modified during this run
|
|
while IFS= read -r screenshot; do
|
|
[ -f "$screenshot" ] || continue
|
|
appname=$(basename "$(dirname "$screenshot")")
|
|
# Sanitize filename: allow letters, digits, dot, underscore, hyphen
|
|
safe_name=$(echo "$appname" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9._-')
|
|
cp "$screenshot" "screenshots-upload/${safe_name}.png"
|
|
done < <(find database -type f -path '*/screenshot.png' -newer .screenshots_start -print)
|
|
ls -la screenshots-upload/ || true
|
|
- name: Upload screenshot artifact
|
|
if: github.event_name == 'pull_request'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: pr-screenshots
|
|
path: screenshots-upload/*.png
|
|
if-no-files-found: ignore
|
|
retention-days: 7
|
|
- name: Check log
|
|
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'probonopd'
|
|
shell: bash
|
|
run: |
|
|
cat log.txt | wc -l
|
|
grep -r "Running as root without --no-sandbox is not supported" log.txt && MESSAGE="Pending #2563 (\`Running as root without --no-sandbox is not supported\`)." && exit 1
|
|
grep -r "version \`GLIBC_.*' not found" && MESSAGE="This was compiled on a too new system and hence cannot run on all still-supported versions of Ubuntu." && exit 1
|
|
echo "${MESSAGE}"
|
|
COUNT=$(ls database/*/screenshot.png 2>/dev/null | wc -l)
|
|
if [[ "${COUNT}" -eq 0 ]]; then
|
|
echo "No screenshot file found."
|
|
exit 1
|
|
fi
|
|
echo "Found ${COUNT} screenshot file(s)."
|
|
# The following is disabled because it gives errors about missing permissions
|
|
# whenever a PR is made by anyone but the repo maintainer
|
|
# - name: Post Screenshot URL
|
|
# if: ${{ always() && github.event_name == 'pull_request' && github.run_status != 'cancelled' }}
|
|
# uses: actions/github-script@v6
|
|
# with:
|
|
# script: |
|
|
# const prNumber = context.payload.pull_request.number;
|
|
# const screenshotURL = process.env.SCREENSHOT_URL;
|
|
# if (screenshotURL) {
|
|
# const commentBody = `Seems like the test succeeded. Temporary screenshot URL: ${screenshotURL}`;
|
|
# await github.rest.issues.createComment({
|
|
# owner: context.repo.owner,
|
|
# repo: context.repo.repo,
|
|
# issue_number: prNumber,
|
|
# body: commentBody
|
|
# });
|
|
# } else {
|
|
# const runURL = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${{ github.run_id }}`;
|
|
# const commentBody = `The test was unable to make a screenshot. Most likely, the test did not succeed. Please check the [logs of the test run](${runURL}).`;
|
|
# await github.rest.issues.createComment({
|
|
# owner: context.repo.owner,
|
|
# repo: context.repo.repo,
|
|
# issue_number: prNumber,
|
|
# body: commentBody
|
|
# });
|
|
# core.setFailed("Unable to post screenshot");
|
|
# }
|