Skip to content

Commit 04556cf

Browse files
Add basic CI
Fix #1
1 parent a24e5ce commit 04556cf

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

.github/workflows/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-plugins:
7+
name: Linux x64_64
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Run test script
14+
run: ./tests/test-plugins.sh

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ The `demo` plugin is a very simple, minimal working example plugin. Please feel
3838
Only plugins with free software licenses (recognized by the OSI) are accepted into this repository. It is highly recommended to use the MIT license (the same license linuxdeploy and all official plugins use), but it's not mandatory. However, if your plugin uses a non-permissive license (e.g., a copyleft one), it might be rejected, depending on how it works.
3939

4040

41+
## Testing
42+
43+
Basic tests are available under `tests`. Plugins that require specific environment variables must have a `.test.env` file in their directory, containing all prerequisite.
44+
45+
4146
## Licensing
4247

4348
All plugin scripts reside in subdirectories of this repository, along with a README. If there is no LICENSE file next to the plugin script, the license in `LICENSE.txt` in the root directory of the repository applies.

gdb/.test.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
touch "$appdir/AppRun.wrapped"
2+
LINUXDEPLOY_PLUGIN_GDB_SRC="$(mktemp --directory)"

tests/test-plugins.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#! /bin/bash
2+
3+
repodir="$(git rev-parse --show-toplevel)"
4+
appdir="$(mktemp --directory)"
5+
count=0
6+
failed=0
7+
8+
run_valid_command() {
9+
((count++))
10+
if out="$("$@" 2>&1 )"; then
11+
echo -e "[\033[1;32m OK \033[0m]"
12+
else
13+
echo -e "[\033[1;31mFAILED\033[0m]"
14+
((failed++))
15+
echo "$out"
16+
fi
17+
}
18+
19+
run_invalid_command() {
20+
((count++))
21+
if out="$("$@" 2>&1 )"; then
22+
echo -e "[\033[1;31mFAILED\033[0m]"
23+
((failed++))
24+
echo "$out"
25+
else
26+
echo -e "[\033[1;32m OK \033[0m]"
27+
fi
28+
}
29+
30+
echo -e "\033[1mTesting $0...\033[0m"
31+
printf "%-60s" " - lint script"
32+
run_valid_command shellcheck "$(readlink -f "$0")"
33+
echo
34+
35+
while IFS= read -r -d '' plugin; do
36+
name="$(basename "$plugin")"
37+
echo -e "\033[1mTesting plugin $name...\033[0m"
38+
39+
printf "%-60s" " - lint plugin"
40+
run_valid_command shellcheck "$plugin"
41+
42+
printf "%-60s" " - run with wrong usage"
43+
run_invalid_command bash "$plugin"
44+
45+
printf "%-60s" " - run with --plugin-api-version"
46+
run_valid_command bash "$plugin" --plugin-api-version
47+
48+
printf "%-60s" " - run with --appdir"
49+
env="$(dirname "$plugin")/.test.env"
50+
if [ -f "$env" ]; then
51+
# shellcheck disable=SC1090
52+
(set -o allexport; source "$env"; run_valid_command bash "$plugin" --appdir "$appdir")
53+
else
54+
run_valid_command bash "$plugin" --appdir "$appdir"
55+
fi
56+
57+
hook="$appdir/apprun-hooks/$name"
58+
if [ -f "$hook" ]; then
59+
printf "%-60s" " - lint apprun-hook"
60+
run_valid_command shellcheck -s sh "$hook"
61+
fi
62+
63+
echo
64+
done < <(find "$repodir" -name 'linuxdeploy-plugin-*.sh' -print0)
65+
66+
if [ "$failed" -eq 0 ]; then
67+
echo -e "\033[1;32mAll $count tests passed with success!\033[0m"
68+
else
69+
echo -e "\033[1;31mError: $failed tests failed.\033[0m"
70+
fi
71+
exit "$failed"

0 commit comments

Comments
 (0)