Skip to content

Commit

Permalink
adapt ci and rebuild scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
datYori committed Jun 12, 2024
1 parent ee2d1a2 commit 9b31c9d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 60 deletions.
57 changes: 1 addition & 56 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,10 @@ on:

env:
SBT_OPTS : -Dsbt.log.noformat=true -Xss2m -Xms1g
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }}

jobs:
build-custom-deps:
runs-on: self-hosted
container:
image: ghcr.io/raw-labs/raw-scala-runner:21.0.0-ol9-20230919_scala2.12.18_sbt1.9.6
options: --user 1001
credentials:
username: ${{ github.actor }}
password: ${{ secrets.READ_PACKAGES }}
steps:
- uses: actions/checkout@v4
- name: sdkman java setup
id: sdkman
run: |
export HOME="/home/sbtuser"
export SDKMAN_DIR="$HOME/.sdkman"
source $SDKMAN_DIR/bin/sdkman-init.sh
yes n | sdk install java 17.0.5-amzn || true
sdk use java 17.0.5-amzn
echo "$SDKMAN_DIR/candidates/java/current/bin" >> $GITHUB_PATH
- name: build custom deps
run: ./build.sh
working-directory: deps
- name: upload ivy build artifacts
uses: actions/upload-artifact@v4
with:
name: ivy
path: /home/sbtuser/.ivy2/local
retention-days: 1
- name: upload m2 build artifacts
uses: actions/upload-artifact@v4
with:
name: m2
path: /home/sbtuser/.m2/repository
retention-days: 1
code-checks:
needs: build-custom-deps
runs-on: self-hosted
container:
image: ghcr.io/raw-labs/raw-scala-runner:21.0.0-ol9-20230919_scala2.12.18_sbt1.9.6
Expand All @@ -66,16 +32,6 @@ jobs:
password: ${{ secrets.READ_PACKAGES }}
steps:
- uses: actions/checkout@v4
- name: download ivy build artifacts
uses: actions/download-artifact@v4
with:
name: ivy
path: /home/sbtuser/.ivy2/local
- name: download m2 build artifacts
uses: actions/download-artifact@v4
with:
name: m2
path: /home/sbtuser/.m2/repository
- name: sdkman java setup
id: sdkman
run: |
Expand All @@ -100,7 +56,6 @@ jobs:
sdk use java 21.0.1-graalce
sbt doc
tests:
needs: build-custom-deps
strategy:
fail-fast: false
matrix:
Expand All @@ -121,16 +76,6 @@ jobs:
password: ${{ secrets.READ_PACKAGES }}
steps:
- uses: actions/checkout@v4
- name: download ivy build artifacts
uses: actions/download-artifact@v4
with:
name: ivy
path: /home/sbtuser/.ivy2/local
- name: download m2 build artifacts
uses: actions/download-artifact@v4
with:
name: m2
path: /home/sbtuser/.m2/repository
- uses: oNaiPs/secrets-to-env-action@v1.5
with:
secrets: ${{ toJSON(secrets) }}
Expand Down
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import com.jsuereth.sbtpgp.PgpKeys.{publishSigned}
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"
ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local"
ThisBuild / sonatypeProfileName := "com.raw-labs"
ThisBuild / credentials += Credentials(
"GitHub Package Registry",
"maven.pkg.github.com",
"raw-labs",
sys.env.getOrElse("GITHUB_TOKEN", "")
)

ThisBuild/ resolvers += "Github RAW main repo" at "https://maven.pkg.github.com/raw-labs/raw"


val writeVersionToFile = taskKey[Unit]("Writes the project version to a file at the root.")

Expand Down
8 changes: 8 additions & 0 deletions deps/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
DEPS_HOME="$(cd "$(dirname "$0")"; pwd)"

cd "$DEPS_HOME"/kiama
./build.sh

cd "$DEPS_HOME"/others
./build.sh
1 change: 1 addition & 0 deletions deps/kiama/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ val commonSettings =
.setPreference(SpacesAroundMultiImports, false),

// Publishing
//TODO: handle properly existing version publish error
publishTo := Some("GitHub raw-labs Apache Maven Packages" at "https://maven.pkg.github.com/raw-labs/raw"),
publishMavenStyle := true,
Test/publishArtifact := true,
Expand Down
81 changes: 79 additions & 2 deletions deps/others/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,86 @@ def updatePom(pomFile: File, newVersion: String): Unit = {
}
}

// Task to patch dependencies
val patchAndInstallDependencies = taskKey[Unit]("Patch and Install dependencies")

patchAndInstallDependencies := {
val log = streams.value.log
val updateReport = update.value

updateReport.configurations.flatMap(_.modules).distinct.foreach { module =>
val groupID = module.module.organization
val artifactID = module.module.name
val version = module.module.revision
val scalaVersionSuffixPattern = "_2\\.\\d{1,2}".r
val normalizedArtifactId = scalaVersionSuffixPattern.replaceFirstIn(artifactID, "")
if (moduleNames.contains(normalizedArtifactId)) {
log.info(s"Found module $artifactID:$version")
module.artifacts.find(_._1.extension == "jar").foreach { case (_, jarFile) =>
try {
val pomPath = jarFile.getAbsolutePath.replace(".jar", ".pom")
val pomFile = new File(pomPath)
if (!pomFile.exists()) {
log.error(s"Expected POM file does not exist for $artifactID:$version at $pomPath")
} else {
log.info(s"Found POM file for $artifactID:$version at $pomPath")

val newName = jarFile.getName.replace(".jar", "-rawlabs.jar")
val newJarFile = new File(jarFile.getParent, newName)
Files.copy(jarFile.toPath, newJarFile.toPath, StandardCopyOption.REPLACE_EXISTING)
log.info(s"Patched JAR file created: $newName")

// Handling the manifest
val manifest = new File("manifest.txt")
val bw = new BufferedWriter(new FileWriter(manifest))
try {
bw.write(s"Automatic-Module-Name: ${moduleNames(normalizedArtifactId)}\n")
} finally {
bw.close()
}

// Update the JAR file with the new manifest
val patchCommand = s"jar --update --file ${newJarFile.getAbsolutePath} --manifest=manifest.txt"
val patchExitCode = patchCommand.!
if (patchExitCode == 0) {
log.info(s"JAR file $newName patched successfully with new manifest.")
} else {
log.error(s"Failed to patch JAR file $newName with new manifest.")
}

// Update and publish the POM file
updatePom(pomFile, version)
val copiedPomFile = new File(pomFile.getParent, s"$artifactID-$version-rawlabs.pom")
Files.copy(pomFile.toPath, copiedPomFile.toPath, StandardCopyOption.REPLACE_EXISTING)
log.info(s"Updated POM file for $artifactID with version $version-rawlabs")
val publishCommand = s"""mvn install:install-file
|-Dfile=${newJarFile.getAbsolutePath}
|-DpomFile=${copiedPomFile.getAbsolutePath}
|-DgroupId=$groupID
|-DartifactId=$artifactID
|-Dversion=$version-rawlabs
|-Dpackaging=jar
|-DrepositoryId=githubraw
|-Durl=https://maven.pkg.github.com/raw-labs/raw""".stripMargin.replaceAll("\n", " ")
val publishExitCode = publishCommand.!
if (publishExitCode == 0) {
log.info(s"Published patched JAR $newName with updated POM $artifactID-$version-rawlabs.")
} else {
log.error(s"Failed to run $publishCommand")
log.error(s"Failed to publish JAR $newName and POM $artifactID-$version-rawlabs.")
}
}
} catch {
case e: Exception =>
log.error(s"Error during the patching process for $artifactID:$version: ${e.getMessage}")
}
}
}
}
}


//TODO: handle publishing existing version maven error
val patchAndPublishDependencies = taskKey[Unit]("Patch dependencies")
val patchAndPublishDependencies = taskKey[Unit]("Patch and Publish dependencies")

patchAndPublishDependencies := {
val log = streams.value.log
Expand Down
13 changes: 13 additions & 0 deletions deps/others/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
SCRIPT_HOME="$(cd "$(dirname "$0")"; pwd)"
[ "$CI" == "true" ] && { export HOME=/home/sbtuser; }
. ~/.sdkman/bin/sdkman-init.sh
# reset shell env for later stages
[ "$JAVA_OPTS" == "-XX:+UseG1GC" ] && { unset JAVA_OPTS; }

yes n | sdk install java 17.0.5-amzn || true
sdk use java 17.0.5-amzn

cd "$SCRIPT_HOME"
sbt patchAndInstallDependencies

3 changes: 1 addition & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ object Dependencies {
val antlr4Runtime = "org.antlr" % "antlr4-runtime" % "4.12.0"

// from snapi-frontend
val kiamaVersion = IO.read(new File("./deps/kiama/version")).trim
val kiama = "org.bitbucket.inkytonik.kiama" %% "kiama" % kiamaVersion
val kiama = "org.bitbucket.inkytonik.kiama" %% "kiama" % "2.5.1-rawlabs"

val aws =
"software.amazon.awssdk" % "s3" % "2.20.69" exclude ("commons-logging", "commons-logging") // spring.jcl is the correct replacement for this one.
Expand Down

0 comments on commit 9b31c9d

Please sign in to comment.