Skip to content

Commit

Permalink
Restructure project to subprojects and implement proper modular setup…
Browse files Browse the repository at this point in the history
…s and tests.
  • Loading branch information
LexManos committed Oct 24, 2023
1 parent 7b1a146 commit c6a5990
Show file tree
Hide file tree
Showing 106 changed files with 1,585 additions and 1,606 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/aggregate-jmh-results.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import groovy.json.JsonSlurper
import net.steppschuh.markdowngenerator.table.Table

import java.nio.file.Files
import java.nio.file.Path
import java.math.RoundingMode

@GrabResolver(name='jitpack.io', root='https://jitpack.io/')
@GrabResolver(name = 'central', root='https://repo1.maven.org/maven2/')
@Grapes([
@Grab('org.apache.groovy:groovy-json:4.0.13'),
@Grab('com.github.Steppschuh:Java-Markdown-Generator:1.3.2')
])

final versions = [] as SortedSet
final javas = [:] as TreeMap
final results = [:] as TreeMap

final resultsPath = Path.of('build/test_artifacts')
for (def dir : Files.list(Path.of('build/test_artifacts'))) {
def dirName = dir.fileName.toString()
def file = dir.resolve('jmh_results.json')
if (!dirName.startsWith('jmh-') || !Files.exists(file))
continue
(javaName,javaVersion) = dirName.substring('jmh-'.length()).split('-')
javas.computeIfAbsent(javaName, { [] }).add(javaVersion)
versions.add(javaVersion)

def json = new JsonSlurper().parse(file.toFile())
for (def bench : json) {
def byJava = results.computeIfAbsent(bench.benchmark, { [:] })
def byVersion = byJava.computeIfAbsent(javaName, { [:] })

def result = bench.primaryMetric.score.setScale(3, RoundingMode.CEILING)
if (!bench.primaryMetric.scoreError.equals('NaN'))
result += ' ± ' + bench.primaryMetric.scoreError.setScale(3, RoundingMode.CEILING)
//result += bench.primaryMetric.scoreUnit

byVersion.put(javaVersion, result)
}
}
def output = ""
results.forEach { bench, byJava ->
final table = new Table.Builder()
.withAlignments(Table.ALIGN_RIGHT, Table.ALIGN_RIGHT)
.addRow((['Vendor'] + versions).toArray())

javas.forEach { javaName, javaVersions ->
def row = [javaName]
if (!byJava.containsKey(javaName)) {
versions.forEach { javaVersion ->
row.add(javaVersions.contains(javaVersion) ? "MISSING" : "")
}
} else {
def byVersion = byJava.get(javaName)
versions.forEach { javaVersion ->
if (javaVersions.contains(javaVersion)) {
row.add(byVersion.containsKey(javaVersion) ? byVersion.get(javaVersion) : "MISSING")
} else {
row.add("")
}
}
}
table.addRow(row.toArray())
}

output += '### `' + bench + '` results\n' +
table.build() + '\n' +
'\n'
}

new File('jmh_results.md').text = output
131 changes: 131 additions & 0 deletions .github/workflows/aggregate-junit-tests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import groovy.xml.DOMBuilder
import groovy.xml.dom.DOMCategory

import java.nio.file.Files
import java.nio.file.Path
import java.math.RoundingMode

@GrabResolver(name='jitpack.io', root='https://jitpack.io/')
@GrabResolver(name = 'central', root='https://repo1.maven.org/maven2/')
@Grapes([
//@Grab('org.codehaus.groovy:groovy-xml:3.0.19')
@Grab('org.apache.groovy:groovy-json:4.0.13')
])

final javas = [:] as TreeMap
final results = [:] as TreeMap

for (def dir : Files.list(Path.of('build/test_artifacts'))) {
def javaName = dir.fileName.toString()
if (!javaName.startsWith('test-results-'))
continue

(javaName,javaVersion) = javaName.substring('test-results-'.length()).split('-')
javas.computeIfAbsent(javaName, { [] as SortedSet }).add(javaVersion)

for (def file : Files.list(dir)) {
def fileName = file.fileName.toString()
if (!fileName.startsWith('TEST-') || !fileName.endsWith('.xml'))
continue

def data = DOMBuilder.parse(new StringReader(file.toFile().text)).documentElement
use(DOMCategory) {
def byTest = results.computeIfAbsent(data['@name'], { [:] })
for (def testcase : data.testcase) {
def byJava = byTest.computeIfAbsent(testcase['@name'], { [:] })
def byVersion = byJava.computeIfAbsent(javaName, { [:] })
byVersion.put(javaVersion, testcase.failure.isEmpty())
}
}
}
}

def output = new StringBuilder("<html><body>")
output.append("""
<html>
<style>
.tooltip-text {
visibility: hidden;
position: absolute;
z-index: 1;
width: 100px;
color: white;
font-size: 12px;
background-color: #192733;
border-radius: 10px;
padding: 10px 15px 10px 15px;
top: -40px;
left: -50%;
}
.hover-text:hover .tooltip-text {
visibility: visible;
}
.success {
background-color: #008000;
}
.failure {
background-color: #b60808;
}
.hover-text {
font-size: 16px;
position: relative;
display: inline;
font-family: monospace;
text-align: center;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding-left: 3px;
padding-right: 3px;
}
.result {
font-size: 0px;
}
</style>
<body>
""")
results.forEach{ suite, byTest ->
output.append("<h1>${suite}</h1>\n")
output.append("<table>\n")
output.append(" <thead>\n")
output.append(" <th>Test</th>\n")
javas.keySet().forEach{ javaName ->
output.append(" <th>${javaName}</th>\n")
}
output.append(" </thead>\n")
output.append(" <tbody>\n")
byTest.forEach{ testName, byJava ->
output.append(" <tr>\n")
output.append(" <td>${testName}</td>\n")
javas.forEach{ javaName, versions ->
output.append(" <td class=\"result\">\n")
def byVersion = byJava.get(javaName)
versions.forEach { ver ->
if (byVersion.containsKey(ver) && byVersion.get(ver)) {
output.append(" <span class=\"hover-text success\">O<span class=\"tooltip-text success\" id=\"failure\">${javaName} v${ver}</span></span>\n")
} else {
output.append(" <span class=\"hover-text failure\">X<span class=\"tooltip-text failure\">${javaName} v${ver}</span></span>\n")
}
}
output.append(" </td>\n")
}
output.append(" </tr>\n")
}
output.append(" </tbody>\n")
output.append("</table>\n")

}
output += "</body></html>"


new File('test_results.html').text = output
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish

on:
push:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@main
with:
java: 17
gradle_tasks: "publish"
artifact_name: "modlauncher"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
PROMOTE_ARTIFACT_WEBHOOK: ${{ secrets.PROMOTE_ARTIFACT_WEBHOOK }}
PROMOTE_ARTIFACT_USERNAME: ${{ secrets.PROMOTE_ARTIFACT_USERNAME }}
PROMOTE_ARTIFACT_PASSWORD: ${{ secrets.PROMOTE_ARTIFACT_PASSWORD }}
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
109 changes: 109 additions & 0 deletions .github/workflows/test_jvms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Test JVMs and publish Jmh results

on:
push:
branches:
- main
workflow_dispatch:
pull_request:
types: [opened, synchronize]

jobs:
testjdks:
if: ${{ env.ACT }} # Only run when testing locally
name: Test JDK ${{ matrix.jdk }} version ${{ matrix.jvm_version }}
runs-on: ubuntu-latest
strategy:
max-parallel: 10
fail-fast: false
matrix:
jvm_version: [ 16, 17, 18, 19, 20, 21 ]
jdk: [ Adoptium, Amazon, Azul, BellSoft, Graal_VM, IBM, Oracle, Microsoft, SAP ]
exclude: # Cases where the Distro doesn't have a version
- jdk: Graal_VM
jvm_version: 18
- jdk: IBM
jvm_version: 21
- jdk: SAP
jvm_version: 21
- jdk: Microsoft
jvm_version: 18
- jdk: Microsoft
jvm_version: 19
- jdk: Microsoft
jvm_version: 20
steps:
- name: Checkout repository
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
cache-disabled: true
generate-job-summary: false

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Run Jmh
run: ./gradlew --console=plain --continue :ml-jmh:jmh -PjavaVendor=${{ matrix.jdk }} -PjavaVersion=${{ matrix.jvm_version }}

- name: Upload JMH Results
uses: actions/upload-artifact@v3
with:
name: jmh-${{ matrix.jdk }}-${{ matrix.jvm_version }}
path: build/jmh_results.json

# It's faster to just run the tests locally.
#- name: Run Tests
# run: ./gradlew --console=plain --continue :ml-test:test -PjavaVendor=${{ matrix.jdk }} -PjavaVersion=${{ matrix.jvm_version }}
#
#- name: Upload Test Reports
# uses: actions/upload-artifact@v3
# with:
# name: test-reports-${{ matrix.jdk }}-${{ matrix.jvm_version }}
# path: build/reports/
#
#- name: Upload Test Results
# uses: actions/upload-artifact@v3
# with:
# name: test-results-${{ matrix.jdk }}-${{ matrix.jvm_version }}
# path: build/test-results/

upload_results:
name: Upload Jmh results
needs: [testjdks]
runs-on: ubuntu-latest
if: ${{ env.ACT }} # Only run when testing locally
steps:
- name: Setup Groovy
uses: wtfjoke/setup-groovy@v1
with:
groovy-version: '4.x'

- name: Checkout repository
uses: actions/checkout@main

- name: Downloads results
uses: actions/download-artifact@v3
id: download
with:
path: build/test_artifacts

- name: Collect JMH results
run: groovy .github/workflows/aggregate-jmh-results.groovy

#- name: Collect JUnit results
# run: groovy .github/workflows/aggregate-junit-tests.groovy

- name: Upload Final Results
uses: actions/upload-artifact@v3
with:
name: aggregate-results
path: jmh_results.md
#path: |
# jmh_results.md
# test_results.html

Loading

0 comments on commit c6a5990

Please sign in to comment.