Skip to content

Commit

Permalink
* changed archiving to Apache Commons Compress (fixed reading all byt…
Browse files Browse the repository at this point in the history
…es out of memory bug)

* fixed log deletion on Windows
* added max heap to sh and bat
* added release notes and tag version to Github workflows
* added version to instrument.yml
  • Loading branch information
MarioRivis committed Sep 9, 2021
1 parent abea5bc commit 3afded6
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 65 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Extract Semver
id: semver_parser
run: |
semver=${TAG#"refs/tags/v"}
semver=${semver%"-voyager"}
echo ::set-output name=semver::$semver
env:
TAG: ${{ github.ref }}

- name: Fill Version
run: |
tag=${{ steps.semver_parser.outputs.semver }}
sed -i "s/\$tag_version/$tag/" pom.xml
- name: Build
run: mvn package

- name: Prepare Assets
run: |
mkdir voyager
Expand All @@ -27,25 +43,21 @@ jobs:
cp bin/voyager.bat voyager/voyager.bat
cp -r instruments voyager/instruments
cp dx-voyager/target/dx-voyager.jar voyager/dx-voyager.jar
- name: Create Archive
run: zip -r dx-voyager.zip voyager

- name: Prepare Release Notes
run: touch ${{ github.workspace }}/releaseNotes/v${{ steps.semver_parser.outputs.semver }}.md

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
release_name: dx-voyager ${{ github.ref }}
draft: false
name: Voyager ${{ steps.semver_parser.outputs.semver }}
body_path: ${{ github.workspace }}/releaseNotes/v${{ steps.semver_parser.outputs.semver }}.md
body: ""
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dx-voyager.zip
asset_name: dx-voyager.zip
asset_content_type: application/zip
draft: false
fail_on_unmatched_files: true
files: dx-voyager.zip
7 changes: 6 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.dxworks.voyager</groupId>
<artifactId>parent</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -59,6 +59,11 @@
<artifactId>jackson-annotations</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
<artifactId>semver4j</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.dxworks.voyager.api.instruments.config

import com.vdurmont.semver4j.Semver
import org.dxworks.voyager.api.utils.fieldMissingOrNull

class InstrumentConfiguration(
name: String? = null,
version: String? = null,
commands: List<Command>? = null,
environment: Map<String, String?>? = null,
parameters: Map<String, String?>? = null,
run: InstrumentRunStrategy? = null,
val results: List<ResultsDir>? = null
val results: List<ResultsDir>? = null,
val id: String? = name, //usually the repo name,
) {
val name: String = name ?: run {
throw IllegalStateException(fieldMissingOrNull("name", "instrument configuration"))
}
val version: Semver by lazy {
version?.let { Semver(it, Semver.SemverType.LOOSE) } ?: run {
throw IllegalStateException(fieldMissingOrNull("version", "instrument configuration"))
}
}
val commands: List<Command> = commands ?: emptyList()
val environment: Map<String, String?> = environment ?: emptyMap()
val parameters: Map<String, String?> = parameters ?: emptyMap()
Expand Down
2 changes: 1 addition & 1 deletion bin/voyager.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -jar dx-voyager.jar %*
java -Xmx8g -jar dx-voyager.jar %*
2 changes: 1 addition & 1 deletion bin/voyager.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -jar dx-voyager.jar "$@"
java -Xmx8g -jar dx-voyager.jar "$@"
16 changes: 8 additions & 8 deletions dx-voyager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.dxworks.voyager</groupId>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dx-voyager</artifactId>

<properties>
<version>1.4.1</version>
<version>$tag_version</version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<main.class>org.dxworks.voyager.MainKt</main.class>
Expand Down Expand Up @@ -46,11 +46,6 @@
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
<artifactId>semver4j</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -65,7 +60,12 @@
<dependency>
<groupId>org.dxworks.voyager</groupId>
<artifactId>api</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion dx-voyager/src/main/kotlin/org/dxworks/voyager/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun main(args: Array<String>) {
log.info(if (instrumentResults.isEmpty()) "Nothing to package" else "Packaging results")

val reports = Path.of(".").toFile()
.listFiles(FileFilter { FileSystems.getDefault().getPathMatcher("glob:**.log").matches(it.toPath()) })
.listFiles(FileFilter { FileSystems.getDefault().getPathMatcher("glob:**/*.log").matches(it.toPath()) })
?: emptyArray()

val containerContent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ResultsContainer(private val containerName: String) {
val entries = instrumentResults.flatMap { it.results }
val files = entries + reports.map { FileAndAlias(it, it.name) }
beforeZip(files)
Zipper().zipFiles(files, containerName)
return files
return Zipper().zipFiles(files, containerName)
}
}
65 changes: 32 additions & 33 deletions dx-voyager/src/main/kotlin/org/dxworks/voyager/zip/Zipper.kt
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
package org.dxworks.voyager.zip

import org.apache.commons.compress.archivers.ArchiveOutputStream
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.compress.utils.IOUtils
import org.dxworks.voyager.results.FileAndAlias
import org.dxworks.voyager.utils.logger
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import java.io.IOException


class Zipper {
companion object {
private val log = logger<Zipper>()
}

fun zipFiles(files: List<FileAndAlias>, zipPath: String) {
val fos = FileOutputStream(zipPath)
val zipOut = ZipOutputStream(fos)
files.forEach {
zipFile(it.file, it.alias, zipOut)
fun zipFiles(files: List<FileAndAlias>, zipPath: String): List<FileAndAlias> {
return ZipArchiveOutputStream(FileOutputStream(zipPath)).use { archive ->
files.filter {
zipFile(it.file, it.alias, archive)
}
}
zipOut.close()
fos.close()
}

private fun zipFile(fileToZip: File, fileName: String, zipOut: ZipOutputStream) {
if (fileToZip.isDirectory) {
zipOut.putNextEntry(
ZipEntry(
if (fileName.endsWith("/")) {
fileName
} else {
"$fileName/"
}
)
)
zipOut.closeEntry()

fileToZip.listFiles()?.forEach {
zipFile(it, fileName + "/" + it.name, zipOut)
}

return
private fun zipFile(file: File, fileName: String, archive: ArchiveOutputStream): Boolean {
if (file.isDirectory) {
return file.listFiles()?.all {
zipFile(it, fileName + "/" + it.name, archive)
} ?: true
}
if (!fileToZip.exists()) {
log.warn("File ${fileToZip.path} does not exist")
if (!file.exists()) {
log.warn("File ${file.path} does not exist")
return false
} else {
val zipEntry = ZipEntry(fileName)
zipOut.putNextEntry(zipEntry)
val bytes = fileToZip.readBytes()
zipOut.write(bytes, 0, bytes.size)
val entry = ZipArchiveEntry(file, fileName)
return try {
FileInputStream(file).use { fis ->
archive.putArchiveEntry(entry)
IOUtils.copy(fis, archive)
archive.closeArchiveEntry()
}
true
} catch (e: IOException) {
log.error("Could not zip file ${file.absolutePath}", e)
false
}
}
}
}

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.dxworks.voyager</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<modules>
<module>api</module>
<module>dx-voyager</module>
Expand Down
5 changes: 5 additions & 0 deletions releaseNotes/v1.5.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* changed archiving to Apache Commons Compress (fixed reading all bytes out of memory bug)
* fixed log deletion on Windows
* added max heap to sh and bat
* added release notes and tag version to Github workflows
* added version to instrument.yml

0 comments on commit 3afded6

Please sign in to comment.