From ae33ae7de99e4e7993e7ff8272196186a941367f Mon Sep 17 00:00:00 2001 From: github-action Date: Wed, 20 Dec 2023 20:16:13 +0000 Subject: [PATCH] new update of dtcw --- dtcw | 5 +++-- dtcw.bat | 45 +++++++++++++++++++++++++++++---------------- dtcw.ps1 | 45 +++++++++++++++++++++++++++++---------------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/dtcw b/dtcw index bad7033..d417eac 100755 --- a/dtcw +++ b/dtcw @@ -12,7 +12,7 @@ set -o pipefail # See https://github.com/docToolchain/docToolchain/releases for available versions. # Set DTC_VERSION to "latest" to get the latest, yet unreleased version. -: "${DTC_VERSION:=3.1.2}" +: "${DTC_VERSION:=3.2.0}" # The 'generateSite' and 'copyThemes' tasks support DTC_SITETHEME, an URL of a theme. # export DTC_SITETHEME=https://....zip @@ -594,8 +594,9 @@ build_command() { local container_name=doctoolchain-${version} container_name+="-$(date '+%Y%m%d_%H%M%S')" pwd=$(has cygpath && cygpath -w "${PWD}" || echo "${PWD}") + docker_args="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) --name ${container_name} \ - -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 \ + -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} \ --entrypoint /bin/bash -v '${pwd}:/project' doctoolchain/doctoolchain:v${version}" cmd="docker ${docker_args} -c \"doctoolchain . ${*} ${DTC_OPTS} && exit\"" diff --git a/dtcw.bat b/dtcw.bat index ab2d476..5e3c651 100644 --- a/dtcw.bat +++ b/dtcw.bat @@ -18,7 +18,7 @@ $ErrorActionPreference = "Stop" # See https://github.com/docToolchain/docToolchain/releases for available versions. # Set DTC_VERSION to "latest" to get the latest, yet unreleased version. -$DTC_VERSION = "3.1.2" +$DTC_VERSION = "3.2.0" if ($env:DTC_VERSION) { $DTC_VERSION = $env:DTC_VERSION } #here you can specify the URL of a theme to use with generateSite-task @@ -399,26 +399,38 @@ function download_file($url, $file) { function assert_java_version_supported() { # Defines the order in which Java is searched. - $JAVA_CMD = "" - if (Get-Command java -ErrorAction SilentlyContinue) { - $JAVA_CMD = "java" - } - if ( $null -ne $env:JAVA_HOME -and $env:JAVA_HOME -ne "") { - $JAVA_CMD = "$env:JAVA_HOME/bin/java" - Write-Warning "here '$env:JAVA_HOME'" - } - if (Test-Path "$DTC_JAVA_HOME") { - Write-Host "local java JDK-17 found" - $javaHome = "$DTC_JAVA_HOME/jdk-17.0.7+7" - $JAVA_CMD = "$javaHome/bin/java" + $JAVA_CMD = $null + + if ( Test-Path "$DTC_JAVA_HOME") { + Write-Host "Check Java from $javaHome" + # Get the list of directories that start with 'jdk-' + $javaDirs = Get-ChildItem -Path $DTC_JAVA_HOME -Directory | Where-Object { $_.Name -like "jdk-*" } + # Select the first directory from the list + $selectedJavaDir = $javaDirs | Select-Object -First 1 + # Construct the complete Java path + $javaHome = Join-Path -Path $DTC_JAVA_HOME -ChildPath $selectedJavaDir.Name + + $JAVA_CMD = Get-Command "$javaHome\bin\java" -ErrorAction SilentlyContinue $dtc_opts = "$dtc_opts '-Dorg.gradle.java.home=$javaHome' " } - if ($JAVA_CMD -eq "") { + + if ( $null -eq $JAVA_CMD) { + Write-Host "Check Java from Path" + $JAVA_CMD = Get-Command java -ErrorAction SilentlyContinue + } + + if ( $null -eq $JAVA_CMD -and $null -ne $env:JAVA_HOME -and $env:JAVA_HOME -ne "") { + Write-Host "Check Java from $env:JAVA_HOME" + $JAVA_CMD = Get-Command "$env:JAVA_HOME\bin\java" -ErrorAction SilentlyContinue + } + + if ($null -eq $JAVA_CMD) { Write-Warning "unable to locate a Java Runtime" java_help_and_die } + # We got a Java version - $javaversion = ((Invoke-Expression -Command "$JAVA_CMD -version 2>&1" | Select-String -Pattern 'version').Line | Select-Object -First 1 ).Split('"')[1].Split(".")[0] + $javaversion = ($JAVA_CMD | Select-Object -ExpandProperty Version).Major Write-Output "Java Version $javaversion" @@ -553,9 +565,10 @@ function build_command($environment, $version, $_args) { } $container_name="doctoolchain-${version}-$(date -uFormat '+%Y%m%d_%H%M%S')" $docker_cmd = Get-Command docker + # TODO: DTC_PROJECT_BRANCH is not passed into the docker environment # See https://github.com/docToolchain/docToolchain/issues/1087 - $docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}" + $docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}" $cmd = "$docker_cmd ${docker_args} -c ""doctoolchain . $_args ${DTC_OPTS} && exit "" " } else { diff --git a/dtcw.ps1 b/dtcw.ps1 index 15c0a21..c1d4871 100644 --- a/dtcw.ps1 +++ b/dtcw.ps1 @@ -9,7 +9,7 @@ $ErrorActionPreference = "Stop" # See https://github.com/docToolchain/docToolchain/releases for available versions. # Set DTC_VERSION to "latest" to get the latest, yet unreleased version. -$DTC_VERSION = "3.1.2" +$DTC_VERSION = "3.2.0" if ($env:DTC_VERSION) { $DTC_VERSION = $env:DTC_VERSION } #here you can specify the URL of a theme to use with generateSite-task @@ -390,26 +390,38 @@ function download_file($url, $file) { function assert_java_version_supported() { # Defines the order in which Java is searched. - $JAVA_CMD = "" - if (Get-Command java -ErrorAction SilentlyContinue) { - $JAVA_CMD = "java" - } - if ( $null -ne $env:JAVA_HOME -and $env:JAVA_HOME -ne "") { - $JAVA_CMD = "$env:JAVA_HOME/bin/java" - Write-Warning "here '$env:JAVA_HOME'" - } - if (Test-Path "$DTC_JAVA_HOME") { - Write-Host "local java JDK-17 found" - $javaHome = "$DTC_JAVA_HOME/jdk-17.0.7+7" - $JAVA_CMD = "$javaHome/bin/java" + $JAVA_CMD = $null + + if ( Test-Path "$DTC_JAVA_HOME") { + Write-Host "Check Java from $javaHome" + # Get the list of directories that start with 'jdk-' + $javaDirs = Get-ChildItem -Path $DTC_JAVA_HOME -Directory | Where-Object { $_.Name -like "jdk-*" } + # Select the first directory from the list + $selectedJavaDir = $javaDirs | Select-Object -First 1 + # Construct the complete Java path + $javaHome = Join-Path -Path $DTC_JAVA_HOME -ChildPath $selectedJavaDir.Name + + $JAVA_CMD = Get-Command "$javaHome\bin\java" -ErrorAction SilentlyContinue $dtc_opts = "$dtc_opts '-Dorg.gradle.java.home=$javaHome' " } - if ($JAVA_CMD -eq "") { + + if ( $null -eq $JAVA_CMD) { + Write-Host "Check Java from Path" + $JAVA_CMD = Get-Command java -ErrorAction SilentlyContinue + } + + if ( $null -eq $JAVA_CMD -and $null -ne $env:JAVA_HOME -and $env:JAVA_HOME -ne "") { + Write-Host "Check Java from $env:JAVA_HOME" + $JAVA_CMD = Get-Command "$env:JAVA_HOME\bin\java" -ErrorAction SilentlyContinue + } + + if ($null -eq $JAVA_CMD) { Write-Warning "unable to locate a Java Runtime" java_help_and_die } + # We got a Java version - $javaversion = ((Invoke-Expression -Command "$JAVA_CMD -version 2>&1" | Select-String -Pattern 'version').Line | Select-Object -First 1 ).Split('"')[1].Split(".")[0] + $javaversion = ($JAVA_CMD | Select-Object -ExpandProperty Version).Major Write-Output "Java Version $javaversion" @@ -544,9 +556,10 @@ function build_command($environment, $version, $_args) { } $container_name="doctoolchain-${version}-$(date -uFormat '+%Y%m%d_%H%M%S')" $docker_cmd = Get-Command docker + # TODO: DTC_PROJECT_BRANCH is not passed into the docker environment # See https://github.com/docToolchain/docToolchain/issues/1087 - $docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}" + $docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}" $cmd = "$docker_cmd ${docker_args} -c ""doctoolchain . $_args ${DTC_OPTS} && exit "" " } else {