Skip to content

Commit

Permalink
Merge pull request #724 from shinybrar/main
Browse files Browse the repository at this point in the history
[CADC-13816] Implement linting and style checks
  • Loading branch information
at88mph authored Nov 8, 2024
2 parents 401f512 + 3488c58 commit f94016c
Show file tree
Hide file tree
Showing 43 changed files with 1,079 additions and 879 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "CI: Linting"

on:
pull_request:
branches: [main]
push:
branches: [main]
schedule:
- cron: '0 0 * * *'

jobs:
spotless:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup Java
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'

- name: Run Spotless
run: |
cd skaha
./gradlew clean spotlessCheck
63 changes: 63 additions & 0 deletions .github/workflows/ci.testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "CI: Testing"

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup Java
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'

- name: Run Tests
run: |
cd skaha
./gradlew clean check
-
name: Upload coverage artifacts
uses: actions/[email protected]
with:
name: skaha-unittests-coverage
path: skaha/build/reports/jacoco/test/jacocoTestReport.xml
if-no-files-found: error
retention-days: 1
overwrite: true

codecov:
runs-on: ubuntu-latest
needs: tests
permissions:
id-token: write
steps:
-
name: Download coverage artifacts
uses: actions/[email protected]
with:
name: skaha-unittests-coverage
-
name: List Downloaded Artifacts
run: |
echo "Downloaded artifacts:"
ls -lah $GITHUB_WORKSPACE
-
name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: jacocoTestReport.xml
flags: skaha-unittests-coverage
name: skaha-unittests-coverage
fail_ci_if_error: true
verbose: true
16 changes: 4 additions & 12 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"

on:
Expand All @@ -17,7 +6,10 @@ on:
pull_request:
branches: [ "main" ]
schedule:
- cron: '34 9 * * 1'
- cron: '0 0 * * *'

# Declare default permissions as read only.
permissions: read-all

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '37 23 * * 3'
- cron: '0 0 * * *'
push:
branches: [ "main" ]

Expand Down
37 changes: 35 additions & 2 deletions skaha/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
plugins {
id 'war'
id 'maven-publish'
id 'checkstyle'
id 'com.diffplug.spotless' version '6.25.0'
id 'java'
id 'jacoco'
}

repositories {
Expand Down Expand Up @@ -49,7 +51,38 @@ dependencies {

runtimeOnly 'org.opencadc:cadc-registry:[1.3.5,)'

testImplementation 'junit:junit:[4.0,)'
testImplementation 'junit:junit:[4.13,)'
testImplementation 'org.json:json:20231013'
testImplementation 'org.mockito:mockito-core:5.12.0'
}

spotless {
java {
// Use the default importOrder configuration
importOrder()
// Remove unused imports
removeUnusedImports()
// Google Java Format, Android Open Source Project style which uses 4 spaces for indentation
palantirJavaFormat()
// Format annotations on a single line
formatAnnotations()
}
yaml {
target '**/*.yaml, **/*.yml, ../.github/workflows/*.yml'
}
format 'misc', {
target '**/*.gradle'
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}

check.dependsOn jacocoTestReport
35 changes: 4 additions & 31 deletions skaha/opencadc.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
configurations {
checkstyleDep
intTestImplementation.extendsFrom testImplementation
// Configuration for integration tests
intTestRuntime.extendsFrom testRuntime
}

dependencies {
testImplementation 'com.puppycrawl.tools:checkstyle:8.2'
checkstyleDep 'org.opencadc:cadc-quality:[1.0,)'
}

checkstyle {
ignoreFailures = false
config = resources.text.fromArchiveEntry(configurations.checkstyleDep, 'cadc_checkstyle.xml')
toolVersion = '8.2'
sourceSets = []
intTestImplementation.extendsFrom testImplementation
}

sourceSets {
Expand All @@ -30,25 +18,11 @@ sourceSets {
}
}

// Temporary work around for issue https://github.com/gradle/gradle/issues/881 -
// gradle not displaying fail build status when warnings reported -->

tasks.withType(Checkstyle).each { checkstyleTask ->
checkstyleTask.doLast {
reports.all { report ->
def outputFile = report.destination
if (outputFile.exists() && outputFile.text.contains("<error ")) {
throw new GradleException("There were checkstyle warnings! For more info check $outputFile")
}
}
}
}

tasks.withType(Test) {
// reset the report destinations so that intTests go to their own page
//reports.html.destination = file("${reporting.baseDir}/${name}")
reports.html.destination = file(reporting.baseDir.getAbsolutePath() + '/' + name)

// Assign all Java system properties from
// the command line to the tests
systemProperties System.properties
Expand All @@ -58,15 +32,14 @@ task intTest(type: Test) {
// set the configuration context
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath

// run the tests always
outputs.upToDateWhen { false }
}

test {
testLogging {
events "PASSED", "FAILED", "SKIPPED"
// "STARTED",
// "STARTED",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class DesktopAppLifecycleTest {
public DesktopAppLifecycleTest() {
try {
RegistryClient regClient = new RegistryClient();
final URL sessionServiceURL = regClient.getServiceURL(SessionUtil.getSkahaServiceID(), Standards.PROC_SESSIONS_10, AuthMethod.TOKEN);
final URL sessionServiceURL = regClient.getServiceURL(
SessionUtil.getSkahaServiceID(), Standards.PROC_SESSIONS_10, AuthMethod.TOKEN);
sessionURL = new URL(sessionServiceURL.toString() + "/session");
log.info("sessions URL: " + sessionURL);

Expand All @@ -118,21 +119,27 @@ public void testCreateDeleteDesktopApp() throws Exception {
SessionUtil.initializeCleanup(this.sessionURL);

// create desktop session
final String desktopSessionID = SessionUtil.createSession(this.sessionURL, "inttest" + SessionAction.SESSION_TYPE_DESKTOP,
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP).getId(),
SessionAction.SESSION_TYPE_DESKTOP);

final Session desktopSession = SessionUtil.waitForSession(this.sessionURL, desktopSessionID, Session.STATUS_RUNNING);
SessionUtil.verifySession(desktopSession, SessionAction.SESSION_TYPE_DESKTOP, "inttest" + SessionAction.SESSION_TYPE_DESKTOP);
final String desktopSessionID = SessionUtil.createSession(
this.sessionURL,
"inttest" + SessionAction.SESSION_TYPE_DESKTOP,
SessionUtil.getImageOfType(SessionAction.SESSION_TYPE_DESKTOP)
.getId(),
SessionAction.SESSION_TYPE_DESKTOP);

final Session desktopSession =
SessionUtil.waitForSession(this.sessionURL, desktopSessionID, Session.STATUS_RUNNING);
SessionUtil.verifySession(
desktopSession, SessionAction.SESSION_TYPE_DESKTOP, "inttest" + SessionAction.SESSION_TYPE_DESKTOP);

final URL desktopAppURL = new URL(this.sessionURL.toString() + "/" + desktopSession.getId() + "/app");
log.info("desktop-app URL: " + desktopAppURL);

// create a terminal desktop-app
String desktopAppID = SessionUtil.createDesktopAppSession(SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(),
desktopAppURL);
String desktopAppID = SessionUtil.createDesktopAppSession(
SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(), desktopAppURL);

Session appSession = SessionUtil.waitForDesktopApplicationSession(desktopAppURL, desktopAppID, Session.STATUS_RUNNING);
Session appSession =
SessionUtil.waitForDesktopApplicationSession(desktopAppURL, desktopAppID, Session.STATUS_RUNNING);

Assert.assertNotNull("no desktop app", desktopAppID);
Assert.assertEquals("Wrong app session ID", appSession.getAppId(), desktopAppID);
Expand All @@ -150,9 +157,10 @@ public void testCreateDeleteDesktopApp() throws Exception {
// create desktop-app specifying resources
int cores = 1;
int ram = 4;
desktopAppID = SessionUtil.createDesktopAppSession(SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(),
desktopAppURL, cores, ram);
appSession = SessionUtil.waitForDesktopApplicationSession(desktopAppURL, desktopAppID, Session.STATUS_RUNNING);
desktopAppID = SessionUtil.createDesktopAppSession(
SessionUtil.getDesktopAppImageOfType("/skaha/terminal").getId(), desktopAppURL, cores, ram);
appSession =
SessionUtil.waitForDesktopApplicationSession(desktopAppURL, desktopAppID, Session.STATUS_RUNNING);

Assert.assertEquals("wrong number of cores", cores, Integer.parseInt(appSession.getRequestedCPUCores()));
Assert.assertEquals("wrong amount of ram", ram + "G", appSession.getRequestedRAM());
Expand Down
Loading

0 comments on commit f94016c

Please sign in to comment.