Skip to content

Commit

Permalink
[Workflow] Generate Ruby Types from Workflow (#5)
Browse files Browse the repository at this point in the history
* [workflows] attempting run on workflow

* [workflows] Adding ls

* [workflows] add branch to test

* [workflows] list builtin_types, cahnge default value for frontends to constant val

* [workflows] add sha512 to workflow

* [ruby] Fixed pathing issue on downloader

* [workflows] add release step to workflow

* [workflows] add files for release step

* [workflows] fix spelling

* [workflows] added output directory option for type-stub generator

* [workflows] remove branch from workflow

* move log to inside if

* scalafmt

* [workflows] rename moved files
  • Loading branch information
AndreiDreyer authored Apr 23, 2024
1 parent ea3bd58 commit decd75d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
/joern-inst
/workspace
src/main/resources/
builtin_types/
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
17 changes: 14 additions & 3 deletions src/main/scala/io/joern/typestubs/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
)
}
}
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit decd75d

Please sign in to comment.