Skip to content

Commit

Permalink
Add settings.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Jan 4, 2024
1 parent 531ce9b commit 162b662
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/cache-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ export class GradleStateCache {
}

init(): void {
// Copy init-scripts to Gradle User Home
const actionCacheDir = path.resolve(this.gradleUserHome, '.gradle-build-action')
fs.mkdirSync(actionCacheDir, {recursive: true})

const initScriptsDir = path.resolve(this.gradleUserHome, 'init.d')
fs.mkdirSync(initScriptsDir, {recursive: true})

this.initializeGradleUserHome(this.gradleUserHome, initScriptsDir)
this.initializeGradleUserHome()

// Export the GRADLE_ENCRYPTION_KEY variable if provided
const encryptionKey = params.getCacheEncryptionKey()
Expand Down Expand Up @@ -188,8 +181,14 @@ export class GradleStateCache {
return path.resolve(this.gradleUserHome, rawPath)
}

private initializeGradleUserHome(gradleUserHome: string, initScriptsDir: string): void {
// Copy init scripts from src/resources
private initializeGradleUserHome(): void {
// Create a directory for storing action metadata
const actionCacheDir = path.resolve(this.gradleUserHome, '.gradle-build-action')
fs.mkdirSync(actionCacheDir, {recursive: true})

// Copy init scripts from src/resources to Gradle UserHome
const initScriptsDir = path.resolve(this.gradleUserHome, 'init.d')
fs.mkdirSync(initScriptsDir, {recursive: true})
const initScriptFilenames = [
'gradle-build-action.build-result-capture.init.gradle',
'gradle-build-action.build-result-capture-service.plugin.groovy',
Expand All @@ -202,6 +201,15 @@ export class GradleStateCache {
const initScriptPath = path.resolve(initScriptsDir, initScriptFilename)
fs.writeFileSync(initScriptPath, initScriptContent)
}

// Copy the toolchains.xml file to `~/.m2`
const m2dir = path.resolve('~/.m2')
fs.mkdirSync(m2dir, {recursive: true})
core.info(`Created m2 directory ${m2dir}`)

const toolchainXmlTarget = path.resolve(m2dir, 'toolchains.xml')
const toolchainContent = this.readInitScriptAsString('toolchains.xml')
fs.writeFileSync(toolchainXmlTarget, toolchainContent)
}

private readInitScriptAsString(resource: string): string {
Expand Down
44 changes: 44 additions & 0 deletions src/resources/init-scripts/toolchains.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- JDK Toolchains installed by default on GitHub-hosted runners -->
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>8</version>
<vendor>Eclipse Temurin</vendor>
</provides>
<configuration>
<jdkHome>JAVA_HOME_8_X64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
<vendor>Eclipse Temurin</vendor>
</provides>
<configuration>
<jdkHome>JAVA_HOME_11_X64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>17</version>
<vendor>Eclipse Temurin</vendor>
</provides>
<configuration>
<jdkHome>JAVA_HOME_17_X64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>21</version>
<vendor>Eclipse Temurin</vendor>
</provides>
<configuration>
<jdkHome>JAVA_HOME_21_X64</jdkHome>
</configuration>
</toolchain>
</toolchains>

0 comments on commit 162b662

Please sign in to comment.