Skip to content
Snippets Groups Projects
nshm.gradle 3.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • apply plugin: "de.undercouch.download"
    
    
    buildscript {
      repositories {
        mavenCentral()
      }
      dependencies {
        classpath "org.yaml:snakeyaml:1.33"
      }
    }
    
    import org.yaml.snakeyaml.Yaml
    
    
    ext {
      nshmDir = "nshms";
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      envMemory = System.getenv("CI_RUNNER_MEMORY")
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      xmx = envMemory ? envMemory : "16g"
    
      // Download and unzip NSHM
    
      downloadNshm = {nshm ->
        def repo = nshm.repo
    
        def tag = nshm.tag
    
        def year = nshm.year
    
    
        def zipName = "${repo}-${tag}.zip";
        def zipFile = new File(nshmDir, zipName)
    
        def nshmFile = file("${nshmDir}/${repo}-${year}")
    
        if (nshmFile.exists()) {
          delete nshmFile
        }
    
          src "https://code.usgs.gov/ghsc/nshmp/nshms/${repo}/-/archive/${tag}/${zipName}"
          dest zipFile
    
          from zipTree(zipFile)
    
        file("${nshmDir}/${repo}-${tag}").renameTo(nshmFile)
    
          delete zipFile
    
    
      // Returns a NSHM from nshms.yml array
      findNshm = {repo, year ->
        def yaml = new Yaml()
        def nshmConfig = new Yaml().load(new File("${projectDir}/nshms.yml").newInputStream())
        def nshm = nshmConfig.nshms.find{nshm -> nshm.repo == repo && nshm.year == year}
    
        if (nshm == null) {
          throw new Exception("NSHM ${repo} ${year} not found.")
        }
    
        return nshm
      }
    
    
    task cleanNshm(type: Delete) {
      delete nshmDir
    
    clean.dependsOn cleanNshm
    
    // Download all NSHMs
    task nshms() {
      dependsOn cleanNshm
      def yaml = new Yaml()
      def nshmConfig = new Yaml().load(new File("${projectDir}/nshms.yml").newInputStream())
    
      doLast {
        for (nshm in nshmConfig.nshms) {
          // Download NSHM
          downloadNshm(nshm)
        }
      }
    }
    
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    // Test Alaska 2007 NSHM
    task testAlaska2007(type: Test) {
      description = "Test Alaska 2007 NSHM"
      group = "verification"
    
      doFirst {
        downloadNshm(findNshm("nshm-alaska", 2007))
      }
    
      testLogging {
        exceptionFormat "full"
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      systemProperties(System.getProperties())
    
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
      useJUnitPlatform()
      jvmArgs(
          "-Xms2g",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          "-Xmx${xmx}",
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
          )
    
      filter {
        includeTestsMatching "gov.usgs.earthquake.nshmp.model.NshmTests.testAlaska2007"
      }
    }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    // Test Alaska 2023 NSHM
    task testAlaska2023(type: Test) {
      description = "Test Alaska 2023 NSHM"
      group = "verification"
    
        downloadNshm(findNshm("nshm-alaska", 2023))
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
      testLogging {
        exceptionFormat "full"
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      systemProperties(System.getProperties())
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      useJUnitPlatform()
      jvmArgs(
          "-Xms2g",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          "-Xmx${xmx}",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          )
    
      filter {
        includeTestsMatching "gov.usgs.earthquake.nshmp.model.NshmTests.testAlaska2023"
      }
    }
    
    // Test CONUS 2018 NSHM
    task testConus2018(type: Test) {
      description = "Test CONUS 2018 NSHM"
      group = "verification"
    
        downloadNshm(findNshm("nshm-conus", 2018))
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
      testLogging {
        exceptionFormat "full"
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      systemProperties(System.getProperties())
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      useJUnitPlatform()
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      jvmArgs(
          "-Xms${xmx}",
          "-Xmx${xmx}",
          )
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
      filter {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        includeTestsMatching "gov.usgs.earthquake.nshmp.model.NshmTests.testConus2018"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      }
    }
    
    // Test CONUS 2023 NSHM
    task testConus2023(type: Test) {
      description = "Test CONUS 2023 NSHM"
      group = "verification"
    
        downloadNshm(findNshm("nshm-conus", 2023))
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
      testLogging {
        exceptionFormat "full"
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      systemProperties(System.getProperties())
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      useJUnitPlatform()
      jvmArgs(
          "-Xms2g",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          "-Xmx${xmx}",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          )
    
      filter {
        includeTestsMatching "gov.usgs.earthquake.nshmp.model.NshmTests.testConus2023"
      }
    }
    
    // Test Hawaii 2021 NSHM
    task testHawaii2021(type: Test) {
      description = "Test Hawaii 2021 NSHM"
      group = "verification"
    
        downloadNshm(findNshm("nshm-hawaii", 2021))
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
      testLogging {
        exceptionFormat "full"
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      systemProperties(System.getProperties())
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      useJUnitPlatform()
      jvmArgs(
          "-Xms2g",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          "-Xmx${xmx}",
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          )
    
      filter {
        includeTestsMatching "gov.usgs.earthquake.nshmp.model.NshmTests.testHawaii2021"
      }
    }