Skip to content

Commit

Permalink
Fix workflow to deal with different jar location
Browse files Browse the repository at this point in the history
The convert-tool build is done via a different build command
to run a single jar. Because the jar location is used to find the root
of the git project inside the tool (in order to find files needed for
the recipe conversion), this fails to compute the right folder.

This change introduces an env var that triggers a different computation
(since it's only needed for the github workflow, it was better than
adding a command line args -- also it seems like the parser API only
supports (key, value) pair type of arguments)

Bug: N/A
Test: N/A
Change-Id: I12b33be19dc92f04a17a14ec70d93bf4e5db5757
  • Loading branch information
ducrohet committed Jan 2, 2024
1 parent 7635452 commit 0e37d2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/convert-recipes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
echo "Working on branch $BRANCH in $BRANCH_DIR"
mkdir $BRANCH_DIR
cp -r .git "$BRANCH_DIR/.git"
java -jar convert-tool/app/build/libs/recipes-converter-all.jar \
STANDALONE_JAR=true java -jar convert-tool/app/build/libs/recipes-converter-all.jar \
convert --sourceAll recipes \
--destination "$BRANCH_DIR" \
--agpVersion "$AGP" --gradleVersion "$GRADLE" --overwrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fun main(args: Array<String>) {
"Convert one or more recipes from one state to the other (default mode is $RELEASE)"
) {
override fun execute() {
val branchRoot = computeGitHubRootFolder()
val branchRoot = computeGitRootFolder()

val finalSource = source
val finalSourceAll = sourceAll
Expand Down Expand Up @@ -135,7 +135,7 @@ fun main(args: Array<String>) {
validateNullArg(gradleVersion, "'gradleVersion' must not be provided for subcommand '$COMMAND_VALIDATE'")
validateNullArg(gradlePath, "'gradlePath' must not be provided for subcommand '$COMMAND_VALIDATE'")

val branchRoot = computeGitHubRootFolder()
val branchRoot = computeGitRootFolder()

// check the env var for the SDK exist
if (System.getenv("ANDROID_HOME") == null) {
Expand Down Expand Up @@ -200,7 +200,7 @@ fun main(args: Array<String>) {
?: printErrorAndTerminate("'repoLocation' must not be null with subcommand '$COMMAND_VALIDATE_CI'"),
gradlePath = gradlePath
?: printErrorAndTerminate("'gradlePath' must not be null with subcommand '$COMMAND_VALIDATE_CI'"),
branchRoot = computeGitHubRootFolder(),
branchRoot = computeGitRootFolder(),
)
validator.validate(
sourceAll = Path.of(
Expand All @@ -221,13 +221,27 @@ fun main(args: Array<String>) {
}
}

private fun computeGitHubRootFolder(): Path {
/**
* Compute the root of the git project, in order to find files needed by the conversion logic.
*
* The logic will vary based on where the tool's jar is located. On the github workflow, this run from
* a different path.
*/
private fun computeGitRootFolder(): Path {
val url = RecipeConverter::class.java.protectionDomain.codeSource.location
val path = Path.of(url.toURI())

// The path is going to be $ROOT/convert-tool/app/build/install/convert-tool/lib/recipes-converter.jar
// we want to return $ROOT
return path.resolve("../../../../../../../").normalize()
val standaloneJar = System.getenv("STANDALONE_JAR") != null

if (standaloneJar) {
// The path is going to be $ROOT/convert-tool/app/build/libs/recipes-converter.jar
// we want to return $ROOT
return path.resolve("../../../../../").normalize()
} else {
// The path is going to be $ROOT/convert-tool/app/build/install/convert-tool/lib/recipes-converter.jar
// we want to return $ROOT
return path.resolve("../../../../../../../").normalize()
}
}

private fun validateNullArg(arg: Any?, msg: String) {
Expand Down

0 comments on commit 0e37d2e

Please sign in to comment.