mirror of
https://github.com/arkenfox/user.js.git
synced 2025-05-17 06:07:10 +02:00
Add test targets and improvements to workflow.
This commit is contained in:
parent
72a23ad3fb
commit
e9d35dfd2c
1 changed files with 106 additions and 68 deletions
174
.github/workflows/test.yml
vendored
174
.github/workflows/test.yml
vendored
|
@ -1,83 +1,121 @@
|
||||||
name: Test
|
# Limitations of GitHub Actions:
|
||||||
|
# Fedora: https://github.com/actions/runner-images/issues/10802
|
||||||
on: pull_request
|
# on.pull_request.paths: https://github.com/actions/runner/issues/2324
|
||||||
|
# jobs.<job_id>.continue-on-error: https://github.com/orgs/community/discussions/15452
|
||||||
|
# etc: https://fusectore.dev/2022/09/25/github-actions-pitfalls.html
|
||||||
|
name: Portability Testing
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '!**'
|
||||||
|
- '.github/workflows/test.yml'
|
||||||
|
- 'updater.sh'
|
||||||
|
- 'prefsCleaner.sh'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
sh:
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: sh {0}
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest] # TODO Add macos-latest and windows-latest
|
script: [ updater.sh, prefsCleaner.sh ]
|
||||||
shell: [bash, busybox, dash, ksh, mksh, yash, zsh] # TODO Add ksh88, osh, pbosh, posh
|
shell: [ bash, busybox, dash, ksh, mksh, posh, yash, zsh ]
|
||||||
|
os: [ ubuntu-latest ]
|
||||||
|
include:
|
||||||
|
- script: updater.sh
|
||||||
|
shell: bash
|
||||||
|
os: macos-latest
|
||||||
|
- script: prefsCleaner.sh
|
||||||
|
shell: bash
|
||||||
|
os: macos-latest
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install esoteric shell
|
- name: Install POSIX compliant shell from the Ubuntu repositories
|
||||||
if: ${{ contains(fromJSON('["busybox", "ksh", "mksh", "yash", "zsh"]'), matrix.shell) }}
|
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
|
||||||
|
timeout-minutes: 5
|
||||||
run: |
|
run: |
|
||||||
sudo apt update -y
|
sudo apt update -y &&
|
||||||
sudo apt install ${{ matrix.shell }} -y
|
sudo apt install -y ${{ matrix.shell }} ||
|
||||||
- name: Set shell
|
exit
|
||||||
if: ${{ matrix.os == 'ubuntu-latest' }}
|
- name: Point `/bin/sh` at the newly installed shell
|
||||||
run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh
|
if: ${{ runner.os == 'Linux' }}
|
||||||
- name: Check exit status definitions
|
run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh || exit
|
||||||
|
- name: Test dot sourcing and obtain exit status definitions
|
||||||
|
timeout-minutes: 1
|
||||||
run: |
|
run: |
|
||||||
. ./updater.sh 2>/dev/null
|
case ${{ matrix.shell }} in
|
||||||
|
busybox)
|
||||||
while IFS='=' read -r name code; do
|
shell='busybox ash'
|
||||||
# "When reporting the exit status with the special parameter '?',
|
;;
|
||||||
# the shell shall report the full eight bits of exit status available."
|
*)
|
||||||
# ―https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02
|
shell=${{ matrix.shell }}
|
||||||
# "exit [n]: If n is specified, but its value is not between 0 and 255
|
;;
|
||||||
# inclusively, the exit status is undefined."
|
esac &&
|
||||||
# ―https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21
|
eval "$shell" <<'EOF'
|
||||||
[ "$code" -ge 0 ] && [ "$code" -le 255 ] || {
|
case ${{ matrix.shell }} in
|
||||||
printf '%s %s\n' 'Undefined exit status in the definition:' \
|
zsh)
|
||||||
"$name=$code." >&2
|
emulate sh
|
||||||
exit 70 # Internal software error.
|
;;
|
||||||
}
|
esac
|
||||||
done <<EOF
|
. ./${{ matrix.script }}
|
||||||
$(exit_status_definitions)
|
[ "$?" -eq "$_EX_OK" ] ||
|
||||||
|
echo '::error file=${{ matrix.script }}::Dot sourcing failed'
|
||||||
|
exit_status_definitions | tr -d ' ' >>"$GITHUB_ENV"
|
||||||
EOF
|
EOF
|
||||||
- name: Tests setup
|
[ "$?" -eq 0 ] || exit
|
||||||
|
- name: Test the `-h` option
|
||||||
|
timeout-minutes: 1
|
||||||
|
run: ./${{ matrix.script }} -h
|
||||||
|
- name: Test passing an unsupported option to the script
|
||||||
|
timeout-minutes: 1
|
||||||
run: |
|
run: |
|
||||||
set +e
|
./${{ matrix.script }} -9
|
||||||
. ./updater.sh && exit_status_definitions >> $GITHUB_ENV
|
[ "$?" -eq "$_EX_USAGE" ]
|
||||||
- name: Check that running as root returns EX_USAGE
|
- name: Test nonexistent profiles.ini
|
||||||
run: sudo ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; }
|
timeout-minutes: 1
|
||||||
- name: Check that passing a wrong option returns EX_USAGE
|
|
||||||
run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; }
|
|
||||||
- name: Check that --help returns EX_OK and not EX__BASE
|
|
||||||
run: ./updater.sh -h > /dev/null
|
|
||||||
- name: Check that if the profile doesn't have at least d-wx permissions, returns EX_UNAVAILABLE
|
|
||||||
run: |
|
run: |
|
||||||
unxable_temp_dir=$(mktemp -d)
|
(HOME=/nosuchdir ./${{ matrix.script }} -sl)
|
||||||
chmod 444 $unxable_temp_dir
|
[ "$?" -eq "$_EX_NOINPUT" ]
|
||||||
./updater.sh -p $unxable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; }
|
- name: Test profile directory missing write or search permissions
|
||||||
unwable_temp_dir=$(mktemp -d)
|
timeout-minutes: 1
|
||||||
chmod 111 $unwable_temp_dir
|
|
||||||
./updater.sh -p $unwable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; }
|
|
||||||
exit 0
|
|
||||||
- name: Check that if the profiles.ini doesn't exist, returns EX_NOINPUT
|
|
||||||
run: |
|
run: |
|
||||||
temp_dir=$(mktemp -d)
|
unwritable_dir=$(mktemp -d) &&
|
||||||
chmod 777 $temp_dir
|
chmod a-w "$unwritable_dir" &&
|
||||||
./updater.sh -l > /dev/null 2>&1 || { [ "$?" -ne $_EX_NOINPUT ] && exit 1; }
|
./${{ matrix.script }} -sp "$unwritable_dir"
|
||||||
exit 0
|
unwritable_status=$?
|
||||||
- name: Check that if the profile requires root privileges, returns EX_CONFIG
|
unsearchable_dir=$(mktemp -d) &&
|
||||||
|
chmod a-x "$unsearchable_dir" &&
|
||||||
|
./${{ matrix.script }} -sp "$unsearchable_dir"
|
||||||
|
unsearchable_status=$?
|
||||||
|
[ "$unwritable_status" -eq "$_EX_UNAVAILABLE" ] &&
|
||||||
|
{
|
||||||
|
[ "$unsearchable_status" -eq "$_EX_UNAVAILABLE" ] ||
|
||||||
|
[ "$unsearchable_status" -eq "$_EX_FAIL" ] # readlinkf failed.
|
||||||
|
}
|
||||||
|
- name: Test running as root
|
||||||
|
timeout-minutes: 1
|
||||||
run: |
|
run: |
|
||||||
temp_dir=$(mktemp -d)
|
sudo ./${{ matrix.script }}
|
||||||
sudo chmod 777 $temp_dir
|
[ "$?" -eq "$_EX_USAGE" ]
|
||||||
sudo touch $temp_dir/user.js
|
- name: Test profile directory containing certain root owned files
|
||||||
./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_CONFIG ] && exit 1; }
|
if: ${{ matrix.script == 'updater.sh' }}
|
||||||
exit 0
|
timeout-minutes: 1
|
||||||
- name: Check that the profile contains something after execution
|
|
||||||
run: |
|
run: |
|
||||||
temp_dir=$(mktemp -d)
|
temp_dir=$(mktemp -d) &&
|
||||||
echo "temp_dir=$temp_dir" >> $GITHUB_ENV
|
sudo touch "$temp_dir/user.js" &&
|
||||||
touch $temp_dir/user.js
|
./${{ matrix.script }} -p "$temp_dir"
|
||||||
yes | ./updater.sh -p $temp_dir
|
[ "$?" -eq "$_EX_CONFIG" ]
|
||||||
[ -s $temp_dir/user.js ] || exit 1
|
- name: Test noninteractive run
|
||||||
- name: Check that the profile contains the most recent user.js after execution
|
timeout-minutes: 3
|
||||||
run: |
|
run: |
|
||||||
wget -qO user.js https://raw.githubusercontent.com/arkenfox/user.js/refs/heads/master/user.js
|
temp_dir=$(mktemp -d) &&
|
||||||
diff user.js $temp_dir/user.js
|
cp ./${{ matrix.script }} ./user.js "$temp_dir" && (
|
||||||
|
cd "$temp_dir" &&
|
||||||
|
ln -s 127.0.0.2:999 .parentlock &&
|
||||||
|
ln -s 127.0.0.2:999 lock &&
|
||||||
|
echo 'user_pref("app.installation.timestamp", "0");' >prefs.js &&
|
||||||
|
# yes | tr -d '\n' | ./${{ matrix.script }} -ds hangs on macOS.
|
||||||
|
printf '%s' 'yyyyyyyyy' | ./${{ matrix.script }} -ds
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue