From 123f1ce373e6772d64a7ef453a7b3e306d5d95c1 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sun, 3 Nov 2024 08:13:20 +0900 Subject: [PATCH 1/4] chore: use xvfb for acceptance test Signed-off-by: Hiroshi Miura --- build.gradle | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/build.gradle b/build.gradle index a900f60e94..a2dbeb3f9e 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { From f391c7e989e6d87287282a8c4b10987e793b7f56 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Mon, 4 Nov 2024 08:58:09 +0900 Subject: [PATCH 2/4] chore: restructure GitHub Actions - Separate gradle wrapper validator - Add acceptance test job - Run build check with headless - Add docs build check job Signed-off-by: Hiroshi Miura --- ...build-master.yml => acceptance-master.yml} | 8 ++-- .github/workflows/gradle-check-master.yml | 39 +++++++++++++++++++ .github/workflows/gradle-wrapper-validate.yml | 12 ++++++ .github/workflows/greetings-builds-master.yml | 24 ++++++++++++ .gitignore | 1 + 5 files changed, 79 insertions(+), 5 deletions(-) rename .github/workflows/{gradle-build-master.yml => acceptance-master.yml} (81%) create mode 100644 .github/workflows/gradle-check-master.yml create mode 100644 .github/workflows/gradle-wrapper-validate.yml create mode 100644 .github/workflows/greetings-builds-master.yml diff --git a/.github/workflows/gradle-build-master.yml b/.github/workflows/acceptance-master.yml similarity index 81% rename from .github/workflows/gradle-build-master.yml rename to .github/workflows/acceptance-master.yml index 3850caa14b..b44d75febd 100644 --- a/.github/workflows/gradle-build-master.yml +++ b/.github/workflows/acceptance-master.yml @@ -1,4 +1,4 @@ -name: Unit Tests, Quality checks, and Acceptance Tests +name: Acceptance Tests on: push: @@ -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 diff --git a/.github/workflows/gradle-check-master.yml b/.github/workflows/gradle-check-master.yml new file mode 100644 index 0000000000..6bbdad3e76 --- /dev/null +++ b/.github/workflows/gradle-check-master.yml @@ -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 }}` + }) diff --git a/.github/workflows/gradle-wrapper-validate.yml b/.github/workflows/gradle-wrapper-validate.yml new file mode 100644 index 0000000000..037783e95d --- /dev/null +++ b/.github/workflows/gradle-wrapper-validate.yml @@ -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 diff --git a/.github/workflows/greetings-builds-master.yml b/.github/workflows/greetings-builds-master.yml new file mode 100644 index 0000000000..65a37269af --- /dev/null +++ b/.github/workflows/greetings-builds-master.yml @@ -0,0 +1,24 @@ +name: Check javadoc, greetings and manuals + +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 manualsHtmls javadoc + run: ./gradlew -PenvIsCi=true firstSteps manualHtmls javadoc + id: gradle diff --git a/.gitignore b/.gitignore index aec3cfdcb2..e61a12e55c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ bin local.properties .idea +.fleet .run out From 5cc1aabcda16c28092a1f38c0c6be72adbc21826 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Mon, 4 Nov 2024 10:04:21 +0900 Subject: [PATCH 3/4] refactor: EditorController - The ctor to accept IMainWindow instead of MainWindow - Core.initializeGUIimpl to take IMainWindow, resolve TODO - TestCoreInitializer call Core.initializeGUIimpl, resolve FIXME Signed-off-by: Hiroshi Miura --- src/org/omegat/core/Core.java | 3 +-- src/org/omegat/gui/editor/EditorController.java | 6 +++--- test/fixtures/org/omegat/core/TestCoreInitializer.java | 7 +------ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/org/omegat/core/Core.java b/src/org/omegat/core/Core.java index 3b6f8f9913..e3ef6bc5d7 100644 --- a/src/org/omegat/core/Core.java +++ b/src/org/omegat/core/Core.java @@ -262,10 +262,9 @@ public static void initializeGUI(final Map 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(); diff --git a/src/org/omegat/gui/editor/EditorController.java b/src/org/omegat/gui/editor/EditorController.java index 27af65be09..6c42ed2331 100644 --- a/src/org/omegat/gui/editor/EditorController.java +++ b/src/org/omegat/gui/editor/EditorController.java @@ -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; @@ -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; @@ -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); diff --git a/test/fixtures/org/omegat/core/TestCoreInitializer.java b/test/fixtures/org/omegat/core/TestCoreInitializer.java index 5af7f61f64..28396a304b 100644 --- a/test/fixtures/org/omegat/core/TestCoreInitializer.java +++ b/test/fixtures/org/omegat/core/TestCoreInitializer.java @@ -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. @@ -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) { From 91210cb3b34e68a47927aea766b64b86feeea6db Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Mon, 4 Nov 2024 10:48:58 +0900 Subject: [PATCH 4/4] chore: split GitHub CIs greetings and manuals build - split manual build and greetings for speed up Signed-off-by: Hiroshi Miura --- .github/workflows/greetings-builds-master.yml | 6 ++--- .github/workflows/manuals-builds-master.yml | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/manuals-builds-master.yml diff --git a/.github/workflows/greetings-builds-master.yml b/.github/workflows/greetings-builds-master.yml index 65a37269af..1664972545 100644 --- a/.github/workflows/greetings-builds-master.yml +++ b/.github/workflows/greetings-builds-master.yml @@ -1,4 +1,4 @@ -name: Check javadoc, greetings and manuals +name: Chec greetings build on: push: @@ -19,6 +19,6 @@ jobs: - uses: gradle/actions/setup-gradle@v4 name: Setup Gradle id: setup-gradle - - name: Run gradle firstSteps manualsHtmls javadoc - run: ./gradlew -PenvIsCi=true firstSteps manualHtmls javadoc + - name: Run gradle firstSteps + run: ./gradlew -PenvIsCi=true firstSteps id: gradle diff --git a/.github/workflows/manuals-builds-master.yml b/.github/workflows/manuals-builds-master.yml new file mode 100644 index 0000000000..3bc29f5584 --- /dev/null +++ b/.github/workflows/manuals-builds-master.yml @@ -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