Skip to content

Commit 6d0d8c2

Browse files
committed
OPENNLP-1688 - Add GH action to test binaries (*nix + win) in GH actions
1 parent 297dc9b commit 6d0d8c2

File tree

3 files changed

+297
-0
lines changed

3 files changed

+297
-0
lines changed

.github/workflows/shell-tests.yml

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
name: Shell Tests CI
17+
18+
on:
19+
push:
20+
branches:
21+
- main
22+
pull_request:
23+
24+
jobs:
25+
test-unix-shell-ubuntu:
26+
name: Test on Ubuntu
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
# Note: bats-core/bats-action@3.0.0 is not allowed to be used (needs an INFRA issue)
34+
- name: Install Bats (Testing Framework)
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y bats
38+
39+
- name: Set up JDK 17
40+
uses: actions/setup-java@v4
41+
with:
42+
distribution: temurin
43+
java-version: 17
44+
45+
- name: Build with Maven
46+
run: mvn -V clean install --no-transfer-progress -Pci -DskipTests=true
47+
48+
- name: Find and Extract OpenNLP Distribution
49+
run: |
50+
# Find the first non-src .tar.gz file in the target directory
51+
TAR_FILE=$(find opennlp-distr/target -maxdepth 1 -type f -name "*.tar.gz" ! -name "*-src*.tar.gz" | head -n 1)
52+
53+
# Ensure we found a file
54+
if [ -z "$TAR_FILE" ]; then
55+
echo "Error: No matching tar.gz file found in opennlp-distr/target"
56+
exit 1
57+
fi
58+
59+
# Extract the tar.gz file
60+
tar -xzf "$TAR_FILE" -C $HOME
61+
62+
# Get the directory name of the extracted content
63+
EXTRACTED_DIR=$(tar -tf "$TAR_FILE" | head -n 1 | cut -f1 -d"/")
64+
65+
# Set OPENNLP_HOME dynamically
66+
echo "OPENNLP_HOME=$HOME/$EXTRACTED_DIR" >> $GITHUB_ENV
67+
echo "$HOME/$EXTRACTED_DIR/bin" >> $GITHUB_PATH
68+
69+
- name: Verify Extraction
70+
run: |
71+
echo "OPENNLP_HOME: $OPENNLP_HOME"
72+
ls -l $OPENNLP_HOME/bin
73+
74+
- name: Run Bats Tests
75+
run: |
76+
bats ./opennlp-distr/src/test/sh
77+
env:
78+
JAVA_HOME: ${{ env.JAVA_HOME }}
79+
OPENNLP_HOME: ${{ env.OPENNLP_HOME }}
80+
81+
test-unix-shell-macos:
82+
name: Test on macOS
83+
runs-on: macos-latest
84+
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v4
88+
89+
- name: Install Bats (Testing Framework)
90+
run: |
91+
brew update
92+
brew install bats-core
93+
94+
- name: Set up JDK 17
95+
uses: actions/setup-java@v4
96+
with:
97+
distribution: temurin
98+
java-version: 17
99+
100+
- name: Build with Maven
101+
run: mvn -V clean install --no-transfer-progress -Pci -DskipTests=true
102+
103+
- name: Find and Extract OpenNLP Distribution
104+
run: |
105+
TAR_FILE=$(find opennlp-distr/target -maxdepth 1 -type f -name "*.tar.gz" ! -name "*-src*.tar.gz" | head -n 1)
106+
if [ -z "$TAR_FILE" ]; then
107+
echo "Error: No matching tar.gz file found in opennlp-distr/target"
108+
exit 1
109+
fi
110+
tar -xzf "$TAR_FILE" -C $HOME
111+
EXTRACTED_DIR=$(tar -tf "$TAR_FILE" | head -n 1 | cut -f1 -d"/")
112+
echo "OPENNLP_HOME=$HOME/$EXTRACTED_DIR" >> $GITHUB_ENV
113+
echo "$HOME/$EXTRACTED_DIR/bin" >> $GITHUB_PATH
114+
115+
- name: Verify Extraction
116+
run: |
117+
echo "OPENNLP_HOME: $OPENNLP_HOME"
118+
ls -l $OPENNLP_HOME/bin
119+
120+
- name: Run Bats Tests
121+
run: |
122+
bats ./opennlp-distr/src/test/sh
123+
env:
124+
JAVA_HOME: ${{ env.JAVA_HOME }}
125+
OPENNLP_HOME: ${{ env.OPENNLP_HOME }}
126+
127+
test-windows-shell:
128+
name: Test on Windows
129+
runs-on: windows-latest
130+
131+
steps:
132+
- name: Checkout code
133+
uses: actions/checkout@v4
134+
135+
- name: Install Pester
136+
run: |
137+
Install-Module -Name Pester -Force -Scope CurrentUser
138+
Import-Module Pester
139+
shell: pwsh
140+
141+
- name: Set up JDK 17
142+
uses: actions/setup-java@v4
143+
with:
144+
distribution: temurin
145+
java-version: 17
146+
147+
- name: Build with Maven
148+
run: mvn -V clean install --no-transfer-progress -Pci -DskipTests=true
149+
150+
- name: Run Pester Tests # (one step to avoid environment issues on Windows)
151+
run: |
152+
# Find the first non-src .tar.gz file in the target directory
153+
$TAR_FILE = Get-ChildItem -Path opennlp-distr/target -Filter "*.tar.gz" | Where-Object { $_.Name -notlike "*-src*" } | Select-Object -First 1
154+
155+
# Ensure we found a file
156+
if (-not $TAR_FILE) {
157+
Write-Error "Error: No matching tar.gz file found in opennlp-distr/target"
158+
exit 1
159+
}
160+
161+
# Extract the tar.gz file to the current directory
162+
$Destination = "$(pwd)"
163+
tar -xzf $TAR_FILE.FullName -C $Destination
164+
165+
# Get the directory name of the extracted content (excluding the tar path)
166+
$EXTRACTED_DIR = (tar -tf $TAR_FILE.FullName | Select-Object -First 1).Split('/')[0]
167+
168+
# Set OPENNLP_HOME dynamically in the environment
169+
$OPENNLP_HOME_PATH = "$Destination\$EXTRACTED_DIR"
170+
Write-Host "OPENNLP_HOME=$OPENNLP_HOME_PATH" # Debugging
171+
172+
# Ensure OPENNLP_HOME is recognized in the current session
173+
$env:OPENNLP_HOME = $OPENNLP_HOME_PATH
174+
$env:PATH = "$env:OPENNLP_HOME\bin;$env:PATH"
175+
176+
Invoke-Pester -Script "./opennlp-distr/src/test/ps/test_opennlp.Tests.ps1" -Output Detailed
177+
shell: pwsh
178+
env:
179+
JAVA_HOME: ${{ env.JAVA_HOME }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
Describe "opennlp.bat Tests" {
17+
18+
# Setup before all tests
19+
BeforeAll {
20+
# Ensure OPENNLP_HOME is added to PATH
21+
if (-not $env:OPENNLP_HOME) {
22+
Throw "OPENNLP_HOME environment variable is not set."
23+
}
24+
25+
# Add the OPENNLP_HOME\bin directory to the PATH so opennlp.bat can be found
26+
$env:PATH = "$env:OPENNLP_HOME\bin;$env:PATH"
27+
}
28+
29+
# Test if opennlp.bat is accessible and executable
30+
It "opennlp.bat exists and is executable" {
31+
$batFile = Join-Path $env:OPENNLP_HOME "bin\opennlp.bat"
32+
33+
# Ensure the .bat file exists
34+
$batFile | Should -Exist
35+
36+
# Check if the bat file runs by executing it with a help flag
37+
$result = & $batFile -h
38+
39+
# Validate the result isn't null or empty
40+
$result | Should -Not -BeNullOrEmpty
41+
}
42+
43+
# Test the output of SimpleTokenizer
44+
It "SimpleTokenizer produces correct output" {
45+
$input = "Hello, friends"
46+
$expected_output = "Hello , friends"
47+
48+
# Run the opennlp.bat with SimpleTokenizer, using input redirection via echo
49+
$output = echo $input | & "$env:OPENNLP_HOME\bin\opennlp.bat" SimpleTokenizer
50+
51+
# Debugging: Log the output
52+
Write-Host "Output: $output"
53+
54+
# Validate the command executed successfully
55+
$output | Should -Not -BeNullOrEmpty
56+
57+
# Check if the expected output is in the result
58+
$output | Should -Contain $expected_output
59+
}
60+
61+
# Cleanup after tests
62+
AfterAll {
63+
# Remove OPENNLP_HOME from PATH after tests are done
64+
Remove-Item Env:\PATH -ErrorAction SilentlyContinue
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bats
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Setup the environment before running the tests
19+
setup() {
20+
PATH="$OPENNLP_HOME/bin:$PATH"
21+
}
22+
23+
# Test to check if the binary is accessible
24+
@test "Binary 'opennlp' exists and is executable" {
25+
run command -v opennlp
26+
[ "$status" -eq 0 ]
27+
[ -x "$output" ]
28+
}
29+
30+
# Test to validate the output of the SimpleTokenizer
31+
@test "SimpleTokenizer produces correct output" {
32+
input="Hello, friends"
33+
expected_output="Hello , friends"
34+
35+
# Run the command and capture output
36+
run echo "$input" | opennlp SimpleTokenizer
37+
38+
# Debugging: Log the status and output
39+
echo "Status: $status"
40+
echo "Output: $output"
41+
42+
# Validate the command executed successfully
43+
[ "$status" -eq 0 ] || echo "Error: opennlp SimpleTokenizer failed"
44+
45+
# Validate the output matches the expected result
46+
[ "${output}" = "$expected_output" ] || echo "Unexpected output: ${output}"
47+
}
48+
49+
# Teardown the environment after running the tests
50+
teardown() {
51+
unset OPENNLP_HOME
52+
}

0 commit comments

Comments
 (0)