mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 09:02:50 +00:00
Merge pull request #306 from gradle/dd/user-home
Use java to determine user.home dir
This commit is contained in:
commit
306a7e4bb2
9 changed files with 140 additions and 33 deletions
5
.github/workflows/ci-full-check.yml
vendored
5
.github/workflows/ci-full-check.yml
vendored
|
@ -48,6 +48,11 @@ jobs:
|
|||
with:
|
||||
cache-key-prefix: ${{github.run_number}}-
|
||||
|
||||
restore-containerized-gradle-home:
|
||||
uses: ./.github/workflows/integ-test-restore-containerized-gradle-home.yml
|
||||
with:
|
||||
cache-key-prefix: ${{github.run_number}}-
|
||||
|
||||
restore-gradle-home:
|
||||
uses: ./.github/workflows/integ-test-restore-gradle-home.yml
|
||||
with:
|
||||
|
|
7
.github/workflows/ci-quick-check.yml
vendored
7
.github/workflows/ci-quick-check.yml
vendored
|
@ -55,11 +55,16 @@ jobs:
|
|||
runner-os: '["ubuntu-latest"]'
|
||||
download-dist: true
|
||||
|
||||
restore-containerized-gradle-home:
|
||||
needs: build-distribution
|
||||
uses: ./.github/workflows/integ-test-restore-containerized-gradle-home.yml
|
||||
with:
|
||||
download-dist: true
|
||||
|
||||
restore-custom-gradle-home:
|
||||
needs: build-distribution
|
||||
uses: ./.github/workflows/integ-test-restore-custom-gradle-home.yml
|
||||
with:
|
||||
runner-os: '["ubuntu-latest"]'
|
||||
download-dist: true
|
||||
|
||||
restore-gradle-home:
|
||||
|
|
60
.github/workflows/integ-test-restore-containerized-gradle-home.yml
vendored
Normal file
60
.github/workflows/integ-test-restore-containerized-gradle-home.yml
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
name: Test restore custom Gradle Home
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
cache-key-prefix:
|
||||
type: string
|
||||
download-dist:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
env:
|
||||
DOWNLOAD_DIST: ${{ inputs.download-dist }}
|
||||
GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: restore-custom-gradle-home-${{ inputs.cache-key-prefix }}
|
||||
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
|
||||
|
||||
jobs:
|
||||
seed-build:
|
||||
runs-on: ubuntu-latest
|
||||
container: fedora:latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
- name: Download distribution if required
|
||||
uses: ./.github/actions/download-dist
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 11
|
||||
distribution: temurin
|
||||
- name: Setup Gradle
|
||||
uses: ./
|
||||
with:
|
||||
cache-read-only: false # For testing, allow writing cache entries on non-default branches
|
||||
- name: Build using Gradle wrapper
|
||||
working-directory: .github/workflow-samples/groovy-dsl
|
||||
run: ./gradlew test
|
||||
|
||||
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
||||
dependencies-cache:
|
||||
needs: seed-build
|
||||
runs-on: ubuntu-latest
|
||||
container: fedora:latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
- name: Download distribution if required
|
||||
uses: ./.github/actions/download-dist
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 11
|
||||
distribution: temurin
|
||||
- name: Setup Gradle
|
||||
uses: ./
|
||||
with:
|
||||
cache-read-only: true
|
||||
- name: Execute Gradle build with --offline
|
||||
working-directory: .github/workflow-samples/groovy-dsl
|
||||
run: ./gradlew test --offline
|
|
@ -5,9 +5,6 @@ on:
|
|||
inputs:
|
||||
cache-key-prefix:
|
||||
type: string
|
||||
runner-os:
|
||||
type: string
|
||||
default: '["ubuntu-latest", "windows-latest", "macos-latest"]'
|
||||
download-dist:
|
||||
type: boolean
|
||||
default: false
|
||||
|
@ -19,10 +16,7 @@ env:
|
|||
|
||||
jobs:
|
||||
seed-build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: ${{fromJSON(inputs.runner-os)}}
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set Gradle User Home
|
||||
run: |
|
||||
|
@ -43,10 +37,7 @@ jobs:
|
|||
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
||||
dependencies-cache:
|
||||
needs: seed-build
|
||||
strategy:
|
||||
matrix:
|
||||
os: ${{fromJSON(inputs.runner-os)}}
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set Gradle User Home
|
||||
run: |
|
||||
|
@ -67,10 +58,7 @@ jobs:
|
|||
# Test that the gradle-user-home cache will cache and restore local build-cache
|
||||
build-cache:
|
||||
needs: seed-build
|
||||
strategy:
|
||||
matrix:
|
||||
os: ${{fromJSON(inputs.runner-os)}}
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set Gradle User Home
|
||||
run: |
|
||||
|
|
28
dist/main/index.js
vendored
28
dist/main/index.js
vendored
|
@ -66383,7 +66383,7 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME';
|
|||
const CACHE_LISTENER = 'CACHE_LISTENER';
|
||||
function setup(buildRootDirectory) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const gradleUserHome = determineGradleUserHome(buildRootDirectory);
|
||||
const gradleUserHome = yield determineGradleUserHome(buildRootDirectory);
|
||||
if (process.env[GRADLE_SETUP_VAR]) {
|
||||
core.info('Gradle setup only performed on first gradle-build-action step in workflow.');
|
||||
return;
|
||||
|
@ -66416,11 +66416,27 @@ function complete() {
|
|||
}
|
||||
exports.complete = complete;
|
||||
function determineGradleUserHome(rootDir) {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome);
|
||||
}
|
||||
return path.resolve(os.homedir(), '.gradle');
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome);
|
||||
}
|
||||
return path.resolve(yield determineUserHome(), '.gradle');
|
||||
});
|
||||
}
|
||||
function determineUserHome() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const output = yield exec.getExecOutput('java', ['-XshowSettings:properties', '-version'], { silent: true });
|
||||
const regex = /user\.home = (\S*)/i;
|
||||
const found = output.stderr.match(regex);
|
||||
if (found == null || found.length <= 1) {
|
||||
core.info('Could not determine user.home from java -version output. Using os.homedir().');
|
||||
return os.homedir();
|
||||
}
|
||||
const userHome = found[1];
|
||||
core.debug(`Determined user.home from java -version output: '${userHome}'`);
|
||||
return userHome;
|
||||
});
|
||||
}
|
||||
function getUniqueGradleHomes(buildResults) {
|
||||
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
|
||||
|
|
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
28
dist/post/index.js
vendored
28
dist/post/index.js
vendored
|
@ -65067,7 +65067,7 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME';
|
|||
const CACHE_LISTENER = 'CACHE_LISTENER';
|
||||
function setup(buildRootDirectory) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const gradleUserHome = determineGradleUserHome(buildRootDirectory);
|
||||
const gradleUserHome = yield determineGradleUserHome(buildRootDirectory);
|
||||
if (process.env[GRADLE_SETUP_VAR]) {
|
||||
core.info('Gradle setup only performed on first gradle-build-action step in workflow.');
|
||||
return;
|
||||
|
@ -65100,11 +65100,27 @@ function complete() {
|
|||
}
|
||||
exports.complete = complete;
|
||||
function determineGradleUserHome(rootDir) {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome);
|
||||
}
|
||||
return path.resolve(os.homedir(), '.gradle');
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME'];
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome);
|
||||
}
|
||||
return path.resolve(yield determineUserHome(), '.gradle');
|
||||
});
|
||||
}
|
||||
function determineUserHome() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const output = yield exec.getExecOutput('java', ['-XshowSettings:properties', '-version'], { silent: true });
|
||||
const regex = /user\.home = (\S*)/i;
|
||||
const found = output.stderr.match(regex);
|
||||
if (found == null || found.length <= 1) {
|
||||
core.info('Could not determine user.home from java -version output. Using os.homedir().');
|
||||
return os.homedir();
|
||||
}
|
||||
const userHome = found[1];
|
||||
core.debug(`Determined user.home from java -version output: '${userHome}'`);
|
||||
return userHome;
|
||||
});
|
||||
}
|
||||
function getUniqueGradleHomes(buildResults) {
|
||||
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir);
|
||||
|
|
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,7 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
|||
const CACHE_LISTENER = 'CACHE_LISTENER'
|
||||
|
||||
export async function setup(buildRootDirectory: string): Promise<void> {
|
||||
const gradleUserHome = determineGradleUserHome(buildRootDirectory)
|
||||
const gradleUserHome = await determineGradleUserHome(buildRootDirectory)
|
||||
|
||||
// Bypass setup on all but first action step in workflow.
|
||||
if (process.env[GRADLE_SETUP_VAR]) {
|
||||
|
@ -55,13 +55,30 @@ export async function complete(): Promise<void> {
|
|||
writeJobSummary(buildResults, cacheListener)
|
||||
}
|
||||
|
||||
function determineGradleUserHome(rootDir: string): string {
|
||||
async function determineGradleUserHome(rootDir: string): Promise<string> {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME']
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome)
|
||||
}
|
||||
|
||||
return path.resolve(os.homedir(), '.gradle')
|
||||
return path.resolve(await determineUserHome(), '.gradle')
|
||||
}
|
||||
|
||||
/**
|
||||
* Different values can be returned by os.homedir() in Javascript and System.getProperty('user.home') in Java.
|
||||
* In order to determine the correct Gradle User Home, we ask Java for the user home instead of using os.homedir().
|
||||
*/
|
||||
async function determineUserHome(): Promise<string> {
|
||||
const output = await exec.getExecOutput('java', ['-XshowSettings:properties', '-version'], {silent: true})
|
||||
const regex = /user\.home = (\S*)/i
|
||||
const found = output.stderr.match(regex)
|
||||
if (found == null || found.length <= 1) {
|
||||
core.info('Could not determine user.home from java -version output. Using os.homedir().')
|
||||
return os.homedir()
|
||||
}
|
||||
const userHome = found[1]
|
||||
core.debug(`Determined user.home from java -version output: '${userHome}'`)
|
||||
return userHome
|
||||
}
|
||||
|
||||
function getUniqueGradleHomes(buildResults: BuildResult[]): string[] {
|
||||
|
|
Loading…
Reference in a new issue