Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CADC-13816] Implement linting and style checks #724

Merged
merged 13 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

56 changes: 56 additions & 0 deletions .github/workflows/ci.testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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: build/reports/jacoco/test/jacocoTestReport.xml
if-no-files-found: error
retention-days: 1
overwrite: true

codecov:
runs-on: ubuntu-latest
needs: tests
steps:
-
name: Download coverage artifacts
uses: actions/[email protected]
with:
name: skaha-unittests-coverage
path: jacocoTestReport.xml
-
name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: jacocoTestReport.xml
flags: skaha-unittests-coverage
name: skaha-unittests-coverage
fail_ci_if_error: 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
33 changes: 2 additions & 31 deletions skaha/opencadc.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
configurations {
checkstyleDep
intTestImplementation.extendsFrom testImplementation
shinybrar marked this conversation as resolved.
Show resolved Hide resolved
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 = []
}

sourceSets {
test {
resources.srcDirs += 'src/test/resources'
Expand All @@ -30,25 +16,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 +30,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
Loading