diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d53f040 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: release +on: + push: + branches: [master, main] + tags: ["*"] + paths-ignore: ['**.md'] + workflow_dispatch: #allows manual trigger + +concurrency: production + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + - name: Get next release version (dry run) + id: taggerDryRun + uses: anothrNick/github-tag-action@1.61.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DRY_RUN: true + - name: echo new tag + run: | + export NEXT_VERSION=${{ steps.taggerDryRun.outputs.new_tag }} + echo "The next tag version will be: $NEXT_VERSION" + - name: echo tag + run: | + echo "The current tag is: ${{ steps.taggerDryRun.outputs.tag }}" + - name: Compile + run: sbt clean stage + - name: Generate Ruby Types + run: ./standalone --withLanguageFrontend RUBYSRC + - name: Checksum + run: sha512sum builtin_types/ruby_builtin_types.zip > builtin_types/ruby_builtin_types.zip.sha512 + - name: Rename + run: | + mv builtin_types/ruby_builtin_types.zip rubysrc_builtin_types.zip + mv builtin_types/ruby_builtin_types.zip.sha512 rubysrc_builtin_types.zip.sha512 + - name: Show SHA512 + run: cat rubysrc_builtin_types.zip.sha512 + - name: Set next release version + id: taggerFinal + uses: anothrNick/github-tag-action@1.61.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + - name: Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.taggerDryRun.outputs.new_tag }} + files: | + rubysrc_builtin_types.zip + rubysrc_builtin_types.zip.sha512 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6bb73fa..67c594f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target/ /joern-inst /workspace src/main/resources/ +builtin_types/ diff --git a/project/plugins.sbt b/project/plugins.sbt index 769be48..70d1090 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,3 +4,4 @@ addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.7") addSbtPlugin("io.shiftleft" % "sbt-overflowdb" % "2.104") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1") +addSbtPlugin("io.shiftleft" % "sbt-ci-release-early" % "2.0.19") diff --git a/src/main/scala/io/joern/typestubs/Main.scala b/src/main/scala/io/joern/typestubs/Main.scala index 5401728..409ee49 100644 --- a/src/main/scala/io/joern/typestubs/Main.scala +++ b/src/main/scala/io/joern/typestubs/Main.scala @@ -8,7 +8,11 @@ object OutputFormat extends Enumeration { val json, mpk, zip = Value } -final case class Config(format: OutputFormat.Value = OutputFormat.zip, languageFrontend: String = "all") { +final case class Config( + format: OutputFormat.Value = OutputFormat.zip, + languageFrontend: String = Frontend.ALL, + outputDirectory: String = "./builtin_types" +) { def withFormat(value: OutputFormat.Value): Config = { copy(format = value) @@ -17,6 +21,10 @@ final case class Config(format: OutputFormat.Value = OutputFormat.zip, languageF def withLanguageFrontend(value: String): Config = { copy(languageFrontend = value) } + + def withOutputDirectory(value: String): Config = { + copy(outputDirectory = value) + } } private object Frontend { @@ -45,7 +53,10 @@ private object Frontend { failure(s"Only available languages are: [${availableFrontendLanguages.mkString(", ")}]") } .text(s"The Frontend Language to generate builtin types for, defaults to `all`: [${availableFrontendLanguages - .mkString(",")}]".stripMargin) + .mkString(",")}]".stripMargin), + opt[String]("output") + .action((x, c) => c.withOutputDirectory(x)) + .text("Directory for type-stubs output") ) } } @@ -70,7 +81,7 @@ object Main { def run(config: Config): Unit = { if config.languageFrontend == Frontend.ALL || config.languageFrontend == Languages.RUBYSRC then - val rubyScraper = BuiltinPackageDownloader(format = config.format) + val rubyScraper = BuiltinPackageDownloader(outputDir = config.outputDirectory, format = config.format) rubyScraper.run() } } diff --git a/src/main/scala/io/joern/typestubs/ruby/BuiltinPackageDownloader.scala b/src/main/scala/io/joern/typestubs/ruby/BuiltinPackageDownloader.scala index c968d38..4143b8a 100644 --- a/src/main/scala/io/joern/typestubs/ruby/BuiltinPackageDownloader.scala +++ b/src/main/scala/io/joern/typestubs/ruby/BuiltinPackageDownloader.scala @@ -43,7 +43,7 @@ case class RubyType(name: String, methods: List[RubyMethod], fields: List[RubyFi * @param rubyVersion * \- Ruby version to fetch dependencies for */ -class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) { +class BuiltinPackageDownloader(outputDir: String, format: OutputFormat.Value = OutputFormat.zip) { private val logger: Logger = LoggerFactory.getLogger(this.getClass) private val CLASS = "class" @@ -52,7 +52,7 @@ class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) { private val browser = JsoupBrowser() private val baseUrl = s"https://ruby-doc.org/3.3.0" - private val baseDir = "src/main/resources/ruby/builtin_types/" + private val baseDir = s"$outputDir/ruby_builtin_types" // Below unicode value calculated with: println("\\u" + Integer.toHexString('→' | 0x10000).substring(1)) // taken from: https://stackoverflow.com/questions/2220366/get-unicode-value-of-a-character @@ -137,9 +137,10 @@ class BuiltinPackageDownloader(format: OutputFormat.Value = OutputFormat.zip) { typesFile.writeByteArray(upack.writeToByteArray(msg)) } - logger.debug("[Ruby]: Zipping builtin-type dir") - dir.zipTo(destination = File(s"${baseDir}.zip")) - dir.delete() + if format == OutputFormat.zip then + logger.debug("[Ruby]: Zipping builtin-type dir") + dir.zipTo(destination = File(s"${baseDir}.zip")) + dir.delete() } /** Write RubyTypes to JSON files for debugging a readable format