Skip to content

Commit

Permalink
Merge pull request #1172 from omegat-org/topic/miurahr/acceptance-tes…
Browse files Browse the repository at this point in the history
…t-xvfb

chore: use xvfb for acceptance test
  • Loading branch information
miurahr authored Nov 4, 2024
2 parents 97822ef + 91210cb commit d10eadc
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests, Quality checks, and Acceptance Tests
name: Acceptance Tests

on:
push:
Expand All @@ -18,13 +18,11 @@ jobs:
with:
java-version: 17
distribution: 'temurin'
- uses: gradle/wrapper-validation-action@v3
name: validate gradle wrapper
- uses: gradle/actions/setup-gradle@v4
name: Setup Gradle
id: setup-gradle
- name: Run gradle build
run: xvfb-run -a --server-args='-screen 0, 1024x768x24' ./gradlew -PenvIsCi --scan build
- name: Run acceptance test
run: ./gradlew -PenvIsCi=true --scan testAcceptance
id: gradle
- name: "Add Build Scan URL as PR comment"
uses: actions/github-script@v7
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/gradle-check-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Quality checks

on:
push:
branches:
- master
- releases/*
pull_request:

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
name: Setup Gradle
id: setup-gradle
- name: Run gradle build
run: ./gradlew -PenvIsCi=true -Pheadless=true --scan check
id: gradle
- name: "Add Build Scan URL as PR comment"
uses: actions/github-script@v7
if: github.event_name == 'pull_request' && failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `❌ ${{ github.workflow }} **failed**.
Please look a Gradle Scan page for details:
${{ steps.gradle.outputs.build-scan-url }}`
})
12 changes: 12 additions & 0 deletions .github/workflows/gradle-wrapper-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Validate gradle wrapper

on:
pull_request:

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v3
name: validate gradle wrapper
24 changes: 24 additions & 0 deletions .github/workflows/greetings-builds-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Chec greetings build

on:
push:
branches:
- master
- releases/*
pull_request:

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
name: Setup Gradle
id: setup-gradle
- name: Run gradle firstSteps
run: ./gradlew -PenvIsCi=true firstSteps
id: gradle
24 changes: 24 additions & 0 deletions .github/workflows/manuals-builds-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check manuals build

on:
push:
branches:
- master
- releases/*
pull_request:

jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
name: Setup Gradle
id: setup-gradle
- name: Run gradle manualsHtmls
run: ./gradlew -PenvIsCi=true manualHtmls
id: gradle
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bin
local.properties

.idea
.fleet
.run
out

Expand Down
53 changes: 53 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,60 @@ tasks.register('testOnJava21', Test) {
group = 'verification'
}

def startX(display) {
def outputStream = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "Xvfb :${display} -screen 0 1280x1024x24 >>/dev/null 2>&1 & echo \$!"
standardOutput = outputStream
}
def xvfbPid = outputStream.toString().trim()
println "Virtual X server is started with DISPLAY :${display} and PID: ${xvfbPid}"
return xvfbPid
}

def stopX(pid) {
println "Stopping virtual X server..."
def outputStream = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "kill ${pid} &"
standardOutput = outputStream
errorOutput = outputStream
}
}

def isCommandAvailable(command) {
def outputStream = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "command -v ${command}"
ignoreExitValue true
standardOutput = outputStream
errorOutput = outputStream
}.exitValue == 0
}

tasks.register('testAcceptance', Test) {
onlyIf {
isCommandAvailable('Xvfb')
}
def display = 99
doFirst {
if (display != null) {
def lockFile = new File("/tmp/.X${display}-lock")
if (!lockFile.exists()) {
ext.xvfbPid = startX(display)
environment 'DISPLAY', ":${display}"
}
}
}
doLast {
if (display != null) {
def pid = ext.has('xvfbPid') ? ext.xvfbPid : null
if (pid != null) {
stopX(pid)
}
}
}

description = 'Run Acceptance GUI test'
group = 'verification'
javaLauncher = javaToolchains.launcherFor {
Expand Down
3 changes: 1 addition & 2 deletions src/org/omegat/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ public static void initializeGUI(final Map<String, String> params) throws Except

/**
* initialize GUI body.
* TODO: this should accept IMainWindow.
* @throws Exception
*/
static void initializeGUIimpl(MainWindow me) throws Exception {
static void initializeGUIimpl(IMainWindow me) throws Exception {
MarkerController.init();
LanguageToolWrapper.init();

Expand Down
6 changes: 3 additions & 3 deletions src/org/omegat/gui/editor/EditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
import org.omegat.gui.main.BaseMainWindowMenu;
import org.omegat.gui.main.DockablePanel;
import org.omegat.gui.main.IMainMenu;
import org.omegat.gui.main.MainWindow;
import org.omegat.gui.main.IMainWindow;
import org.omegat.gui.main.MainWindowStatusBar;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.gui.notes.INotes;
Expand Down Expand Up @@ -183,7 +183,7 @@ enum ForceTranslation {
private String emptyProjectPaneTitle;
private JTextPane introPane;
private JTextPane emptyProjectPane;
protected final MainWindow mw;
protected final IMainWindow mw;

/** Currently displayed segments info. */
protected SegmentBuilder[] m_docSegList;
Expand Down Expand Up @@ -229,7 +229,7 @@ private enum SHOW_TYPE {
*/
private IProject.AllTranslations previousTranslations;

public EditorController(final MainWindow mainWindow) {
public EditorController(final IMainWindow mainWindow) {
this.mw = mainWindow;

segmentExportImport = new SegmentExportImport(this);
Expand Down
7 changes: 1 addition & 6 deletions test/fixtures/org/omegat/core/TestCoreInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.omegat.gui.glossary.IGlossaries;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.gui.main.IMainWindow;
import org.omegat.gui.main.MainWindow;

/**
* Core initializer for unit tests.
Expand All @@ -56,11 +55,7 @@ public static void initMainWindow(IMainWindow mainWindow) throws Exception {
if (mainWindow instanceof ConsoleWindow) {
return;
}

// FIXME: IMainWindow on GUI environment should be initialized
if (mainWindow instanceof MainWindow) {
Core.initializeGUIimpl((MainWindow) mainWindow);
}
Core.initializeGUIimpl(mainWindow);
}

public static void initGlossary(IGlossaries glossaries) {
Expand Down

0 comments on commit d10eadc

Please sign in to comment.