-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
156 lines (138 loc) · 5.8 KB
/
Copy pathaction.yml
File metadata and controls
156 lines (138 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: 'Run package tests'
description: 'Run package tests'
inputs:
coverage:
description: 'Boolean that determines whether GAP is instructed to collect code coverage via the `--cover` argument'
required: false
default: 'true'
testfile:
description: 'Name of the GAP file to be read for executing the package tests (overrides TestFile in PackageInfo.g)'
required: false
default: ''
mode:
description: 'Value that determines which packages are loaded before the package is tested. The possible values are ''default'', ''onlyneeded'' or ''loadall''. The option ''default'' loads GAP with default set of package; ''onlyneeded'' loads only the needed dependencies of the package being tested; ''loadall'' executes LoadAllPackages() before the package being tested.'
required: false
default: 'default'
warnings-as-errors:
description: 'Boolean that determines whether any warnings produced whilst loading the package will be treated as errors'
required: false
default: 'true'
pre-gap:
description: 'Prefix for the ''GAP'' shell variable used by this action to launch GAP (e.g. setting this to ''valgrind --trace-children=yes --leak-check=full'' will run GAP through valgrind)'
required: false
default: ''
runs:
using: "composite"
steps:
- name: "Validate input"
shell: bash
run: |
validate_boolean() {
local input=$1
local option_name=$2
if ! [[ "$input" =~ ^(true|false)$ ]]; then
echo "::error::Invalid value for option $option_name. Expected 'true' or 'false', but found '$input'"
exit 1;
fi
}
validate_mode () {
if ! [[ "${{ inputs.mode }}" =~ ^(default|onlyneeded|loadall)$ ]]; then
echo "::error::Invalid value for option mode. Expected 'default', 'onlyneeded' or 'loadall' but found '${{ inputs.mode }}'"
exit 1;
fi
}
validate_mode
validate_boolean "${{ inputs.coverage }}" coverage
validate_boolean "${{ inputs.warnings-as-errors }}" warnings-as-errors
- name: "Run tests"
shell: bash
run: |
set -ex
GAPROOT=${GAPROOT-$HOME/gap}
# set up a custom GAP root containing only this package, so that
# we can force GAP to load the correct version of this package
# (we already did that in build_pkg.sh, but we do it again here,
# to allow the occasional instance where a package wants to also
# run the tests of others packages, by invoking this script multiple
# times in different directories)
mkdir -p /tmp/gaproot/pkg/
ln -f -s $PWD /tmp/gaproot/pkg/
# start GAP with custom GAP root, to ensure correct package version is loaded
GAP="$GAPROOT/gap -l /tmp/gaproot; --quitonbreak"
# Prepend pre-gap prefix, if it exists
if [[ ! -z "${{ inputs.pre-gap }}" ]]; then
GAP="${{ inputs.pre-gap }} $GAP"
fi
if [ "${{ inputs.mode }}" = "onlyneeded" ]; then
GAP="$GAP -A"
fi
# Unless explicitly turned off by setting the `coverage` input to `false`
# we collect coverage data
if ${{ inputs.coverage }}; then
mkdir -p coverage
GAP="$GAP --cover coverage/$(mktemp XXXXXX).coverage"
fi
cat > __TEST_RUNNER__.g <<EOF
GAP_TESTFILE:="${{ inputs.testfile }}";
Read("PackageInfo.g");
info := GAPInfo.PackageInfoCurrent;
if IsEmpty(GAP_TESTFILE) then
GAP_TESTFILE := info.TestFile;
elif not IsExistingFile(GAP_TESTFILE) then
Exec("echo \"::error::Provided testfile '${{ inputs.testfile }}' does not exist\"");
FORCE_QUIT_GAP(1);
fi;
SetInfoLevel(InfoPackageLoading, PACKAGE_DEBUG);
SetPackagePath(info.PackageName, "/tmp/gaproot/pkg/$(basename $PWD)");
# Capture the output of loading
output := "";
output_stream := OutputTextString(output, true);
SetPrintFormattingStatus(output_stream, false);
OutputLogTo(output_stream);
# Load the package with debug info
if "${{ inputs.mode }}" = "onlyneeded" then
check_load := LoadPackage(info.PackageName : OnlyNeeded);
elif "${{ inputs.mode }}" = "loadall" then
check_load := LoadPackage(info.PackageName);
LoadAllPackages();
else
check_load := LoadPackage(info.PackageName);
fi;
if check_load <> true then
Exec("echo \"::error::Package could not be loaded\"");
FORCE_QUIT_GAP(1);
fi;
OutputLogTo();
CloseStream(output_stream);
# Treat warnings as errors if specified
ignored_prefixes := ["#I HAP "];
if ${{ inputs.warnings-as-errors }} then
pos := PositionSublist(output, "warning");
while pos <> fail do
warning := true;
for prefix in ignored_prefixes do
l := Length(prefix);
if pos > l and output{[pos-l .. pos-1]} = prefix then
warning := false;
break;
fi;
od;
if warning then
Exec("echo \"::error::Warnings were found when loading the package\"");
FORCE_QUIT_GAP(1);
fi;
pos := PositionSublist(output, "warning", pos + 1);
od;
fi;
SetInfoLevel(InfoPackageLoading, PACKAGE_ERROR);
Print("Now running tests from ", GAP_TESTFILE, "\n");
if EndsWith(GAP_TESTFILE, ".tst") then
QUIT_GAP(Test(GAP_TESTFILE, rec(compareFunction := "uptowhitespace")));
else
Read(GAP_TESTFILE);
Exec("echo \"::error::Package TestFile did not exit GAP\"");
FORCE_QUIT_GAP(1);
fi;
EOF
$GAP __TEST_RUNNER__.g
rm __TEST_RUNNER__.g