mirror of
https://github.com/gradle/actions
synced 2024-11-23 18:02:13 +00:00
Merge pull request #19 from eskatos/eskatos/june
Automatically cache wrapper installation
This commit is contained in:
commit
b995a7b937
33 changed files with 5119 additions and 2310 deletions
3
.eslintignore
Normal file
3
.eslintignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
52
.eslintrc.json
Normal file
52
.eslintrc.json
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
25
.github/workflows/checkin.yml
vendored
25
.github/workflows/checkin.yml
vendored
|
@ -1,25 +0,0 @@
|
|||
name: "PR Checks"
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
check_pr:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: "npm ci"
|
||||
run: npm ci
|
||||
|
||||
- name: "npm run build"
|
||||
run: npm run build
|
||||
|
||||
- name: "npm run test"
|
||||
run: npm run test
|
||||
|
||||
- name: "check for uncommitted changes"
|
||||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||
run: |
|
||||
git diff --exit-code --stat -- . ':!node_modules' \
|
||||
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
|
||||
"and check in all changes" \
|
||||
&& exit 1)
|
35
.github/workflows/dev.yml
vendored
Normal file
35
.github/workflows/dev.yml
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
name: dev
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: |
|
||||
npm install
|
||||
npm run all
|
||||
- name: Test wrapper
|
||||
uses: ./
|
||||
with:
|
||||
wrapper-directory: __tests__/data/basic
|
||||
build-root-directory: __tests__/data/basic
|
||||
arguments: help
|
||||
- name: Test dist download
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: 6.5
|
||||
build-root-directory: __tests__/data/basic
|
||||
arguments: help
|
||||
- name: Check for uncommitted changes
|
||||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||
run: |
|
||||
git diff --exit-code --stat -- . ':!node_modules' \
|
||||
|| (echo "##[error] found changed files after build. please 'npm run all'" \
|
||||
"and check in all changes" \
|
||||
&& exit 1)
|
34
.github/workflows/prod.yml
vendored
Normal file
34
.github/workflows/prod.yml
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
# make sure the action works on a clean machine without building
|
||||
name: prod
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Test wrapper
|
||||
uses: ./
|
||||
with:
|
||||
wrapper-directory: __tests__/data/basic
|
||||
build-root-directory: __tests__/data/basic
|
||||
arguments: help
|
||||
- name: Test dist download
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: 6.5
|
||||
build-root-directory: __tests__/data/basic
|
||||
arguments: help
|
||||
- name: Check for uncommitted changes
|
||||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||
run: |
|
||||
git diff --exit-code --stat -- . ':!node_modules' \
|
||||
|| (echo "##[error] found changed files after build. please 'npm run all'" \
|
||||
"and check in all changes" \
|
||||
&& exit 1)
|
17
.gitignore
vendored
17
.gitignore
vendored
|
@ -1,10 +1,6 @@
|
|||
lib/
|
||||
# Dependency directory
|
||||
node_modules
|
||||
|
||||
.idea
|
||||
*.iml
|
||||
__tests__/runner/*
|
||||
|
||||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
|
@ -93,3 +89,14 @@ typings/
|
|||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# OS metadata
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
__tests__/runner/*
|
||||
# lib/**/*
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
|
|
3
.prettierignore
Normal file
3
.prettierignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 4,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
|
@ -6,7 +6,7 @@ You might also be interested by the related [Gradle Plugin](https://github.com/e
|
|||
|
||||
## Usage
|
||||
|
||||
The following workflow will run `gradle build` using the wrapper from the repository on ubuntu, macos and windows. The only prerequisite is to have Java installed, you can define the version you need to run the build using the `actions/setup-java` action.
|
||||
The following workflow will run `./gradlew build` using the wrapper from the repository on ubuntu, macos and windows. The only prerequisite is to have Java installed, you can define the version you need to run the build using the `actions/setup-java` action.
|
||||
|
||||
|
||||
|
||||
|
|
33
__tests__/cache.test.ts
Normal file
33
__tests__/cache.test.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import * as cache from '../src/cache'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('cache', () => {
|
||||
describe('can extract gradle wrapper slug', () => {
|
||||
it('from wrapper properties file', async () => {
|
||||
const version = cache.extractGradleWrapperSlugFrom(
|
||||
path.resolve(
|
||||
'__tests__/data/basic/gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
)
|
||||
expect(version).toBe('6.5-bin')
|
||||
})
|
||||
it('for -bin dist', async () => {
|
||||
const version = cache.extractGradleWrapperSlugFromDistUri(
|
||||
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.5-bin.zip'
|
||||
)
|
||||
expect(version).toBe('6.5-bin')
|
||||
})
|
||||
it('for -all dist', async () => {
|
||||
const version = cache.extractGradleWrapperSlugFromDistUri(
|
||||
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.5-all.zip'
|
||||
)
|
||||
expect(version).toBe('6.5-all')
|
||||
})
|
||||
it('for milestone', async () => {
|
||||
const version = cache.extractGradleWrapperSlugFromDistUri(
|
||||
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.6-milestone-1-all.zip'
|
||||
)
|
||||
expect(version).toBe('6.6-milestone-1-all')
|
||||
})
|
||||
})
|
||||
})
|
6
__tests__/data/basic/.gitattributes
vendored
Normal file
6
__tests__/data/basic/.gitattributes
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
__tests__/data/basic/.gitignore
vendored
Normal file
5
__tests__/data/basic/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
6
__tests__/data/basic/build.gradle
Normal file
6
__tests__/data/basic/build.gradle
Normal file
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This is a general purpose Gradle build.
|
||||
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
|
||||
*/
|
BIN
__tests__/data/basic/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
__tests__/data/basic/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
__tests__/data/basic/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
__tests__/data/basic/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
185
__tests__/data/basic/gradlew
vendored
Executable file
185
__tests__/data/basic/gradlew
vendored
Executable file
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
104
__tests__/data/basic/gradlew.bat
vendored
Normal file
104
__tests__/data/basic/gradlew.bat
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
10
__tests__/data/basic/settings.gradle
Normal file
10
__tests__/data/basic/settings.gradle
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/6.5/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = 'basic'
|
|
@ -1,3 +0,0 @@
|
|||
describe('TODO - Add a test suite', () => {
|
||||
it('TODO - Add a test', async () => {});
|
||||
});
|
|
@ -27,7 +27,9 @@ outputs:
|
|||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
||||
main: 'dist/main/index.js'
|
||||
post: 'dist/post/index.js'
|
||||
post-if: success()
|
||||
|
||||
branding:
|
||||
icon: 'box'
|
||||
|
|
1
dist/main/index.js
vendored
Normal file
1
dist/main/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/post/index.js
vendored
Normal file
1
dist/post/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,12 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
moduleFileExtensions: ['js', 'ts', 'json'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
verbose: true,
|
||||
setupFilesAfterEnv: ['./jest.setup.js']
|
||||
}
|
||||
|
|
1
jest.setup.js
Normal file
1
jest.setup.js
Normal file
|
@ -0,0 +1 @@
|
|||
jest.setTimeout(10000) // in milliseconds
|
6386
package-lock.json
generated
6386
package-lock.json
generated
File diff suppressed because it is too large
Load diff
42
package.json
42
package.json
|
@ -1,11 +1,15 @@
|
|||
{
|
||||
"name": "gradle-command-action",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Execute Gradle Command Line",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest"
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"build": "ncc build src/main.ts --out dist/main --minify && ncc build src/post.ts --out dist/post --minify",
|
||||
"test": "jest",
|
||||
"all": "npm run format && npm run lint && npm run build && npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -20,21 +24,29 @@
|
|||
"author": "Paul Merlin <paul@nosphere.org>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "1.2.1",
|
||||
"@actions/exec": "1.0.3",
|
||||
"@actions/core": "1.2.4",
|
||||
"@actions/exec": "1.0.4",
|
||||
"@actions/io": "1.0.2",
|
||||
"@actions/tool-cache": "1.3.0",
|
||||
"@actions/tool-cache": "1.5.5",
|
||||
"@actions/cache": "0.2.1",
|
||||
"string-argv": "0.3.1",
|
||||
"typed-rest-client": "1.7.1",
|
||||
"unzipper": "0.10.5"
|
||||
"typed-rest-client": "1.7.3",
|
||||
"unzipper": "0.10.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "24.0.25",
|
||||
"@types/node": "12.7.5",
|
||||
"@types/unzipper": "0.10.1",
|
||||
"jest": "24.9.0",
|
||||
"jest-circus": "24.9.0",
|
||||
"ts-jest": "24.3.0",
|
||||
"typescript": "3.7.4"
|
||||
"@types/jest": "26.0.0",
|
||||
"@types/node": "12.12.6",
|
||||
"@types/unzipper": "0.10.3",
|
||||
"@typescript-eslint/parser": "3.2.0",
|
||||
"@zeit/ncc": "0.22.3",
|
||||
"eslint": "7.2.0",
|
||||
"eslint-plugin-github": "4.0.1",
|
||||
"eslint-plugin-jest": "23.13.2",
|
||||
"jest": "26.0.1",
|
||||
"jest-circus": "26.0.1",
|
||||
"js-yaml": "3.14.0",
|
||||
"prettier": "2.0.5",
|
||||
"ts-jest": "26.1.0",
|
||||
"typescript": "3.8.3"
|
||||
}
|
||||
}
|
||||
|
|
96
src/cache.ts
Normal file
96
src/cache.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
const WRAPPER_CACHE_KEY = 'WRAPPER_CACHE_KEY'
|
||||
const WRAPPER_CACHE_PATH = 'WRAPPER_CACHE_PATH'
|
||||
const WRAPPER_CACHE_RESULT = 'WRAPPER_CACHE_RESULT'
|
||||
|
||||
export async function restoreCachedWrapperDist(
|
||||
executableDirectory: string
|
||||
): Promise<void> {
|
||||
const wrapperSlug = extractGradleWrapperSlugFrom(
|
||||
path.join(
|
||||
path.resolve(executableDirectory),
|
||||
'gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
)
|
||||
if (!wrapperSlug) return
|
||||
|
||||
const wrapperCacheKey = `wrapper-${wrapperSlug}`
|
||||
const wrapperCachePath = path.join(
|
||||
process.env.HOME!,
|
||||
`.gradle/wrapper/dists/gradle-${wrapperSlug}`
|
||||
)
|
||||
|
||||
core.saveState(WRAPPER_CACHE_KEY, wrapperCacheKey)
|
||||
core.saveState(WRAPPER_CACHE_PATH, wrapperCachePath)
|
||||
|
||||
const restoredKey = await cache.restoreCache(
|
||||
[wrapperCachePath],
|
||||
wrapperCacheKey
|
||||
)
|
||||
|
||||
if (!restoredKey) {
|
||||
core.info(
|
||||
'Wrapper installation cache not found, expect a Gradle distribution download.'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
core.saveState(WRAPPER_CACHE_RESULT, restoredKey)
|
||||
core.info(`Wrapper installation restored from cache key: ${restoredKey}`)
|
||||
return
|
||||
}
|
||||
|
||||
export async function cacheWrapperDist(): Promise<void> {
|
||||
const cacheKey = core.getState(WRAPPER_CACHE_KEY)
|
||||
const cachePath = core.getState(WRAPPER_CACHE_PATH)
|
||||
const cacheResult = core.getState(WRAPPER_CACHE_RESULT)
|
||||
|
||||
if (!cachePath) {
|
||||
core.debug('No wrapper installation to cache.')
|
||||
return
|
||||
}
|
||||
|
||||
if (cacheResult && cacheKey === cacheResult) {
|
||||
core.info(
|
||||
`Wrapper installation cache hit occurred on the cache key ${cacheKey}, not saving cache.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await cache.saveCache([cachePath], cacheKey)
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
throw error
|
||||
} else if (error.name === cache.ReserveCacheError.name) {
|
||||
core.info(error.message)
|
||||
} else {
|
||||
core.info(`[warning] ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
export function extractGradleWrapperSlugFrom(
|
||||
wrapperProperties: string
|
||||
): string | null {
|
||||
const props = fs.readFileSync(wrapperProperties, {encoding: 'utf8'})
|
||||
const distUrlLine = props
|
||||
.split('\n')
|
||||
.find(line => line.startsWith('distributionUrl'))
|
||||
if (!distUrlLine) return null
|
||||
return extractGradleWrapperSlugFromDistUri(distUrlLine.substr(16).trim())
|
||||
}
|
||||
|
||||
export function extractGradleWrapperSlugFromDistUri(
|
||||
distUri: string
|
||||
): string | null {
|
||||
const regex = /.*gradle-(.*-(bin|all))\.zip/
|
||||
const match = distUri.match(regex)
|
||||
return match ? match[1] : null
|
||||
}
|
|
@ -1,31 +1,33 @@
|
|||
import * as exec from "@actions/exec";
|
||||
import * as exec from '@actions/exec'
|
||||
|
||||
|
||||
export async function execute(executable: string, root: string, argv: string[]): Promise<BuildResult> {
|
||||
|
||||
let publishing = false;
|
||||
let buildScanUrl: string | undefined;
|
||||
export async function execute(
|
||||
executable: string,
|
||||
root: string,
|
||||
argv: string[]
|
||||
): Promise<BuildResult> {
|
||||
let publishing = false
|
||||
let buildScanUrl: string | undefined
|
||||
|
||||
const status: number = await exec.exec(executable, argv, {
|
||||
cwd: root,
|
||||
ignoreReturnCode: true,
|
||||
listeners: {
|
||||
stdline: (line: string) => {
|
||||
if (line.startsWith("Publishing build scan...")) {
|
||||
publishing = true;
|
||||
if (line.startsWith('Publishing build scan...')) {
|
||||
publishing = true
|
||||
}
|
||||
if (publishing && line.length == 0) {
|
||||
if (publishing && line.length === 0) {
|
||||
publishing = false
|
||||
}
|
||||
if (publishing && line.startsWith("http")) {
|
||||
buildScanUrl = line.trim();
|
||||
if (publishing && line.startsWith('http')) {
|
||||
buildScanUrl = line.trim()
|
||||
publishing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
return new BuildResultImpl(status, buildScanUrl);
|
||||
return new BuildResultImpl(status, buildScanUrl)
|
||||
}
|
||||
|
||||
export interface BuildResult {
|
||||
|
@ -34,9 +36,5 @@ export interface BuildResult {
|
|||
}
|
||||
|
||||
class BuildResultImpl implements BuildResult {
|
||||
constructor(
|
||||
readonly status: number,
|
||||
readonly buildScanUrl?: string
|
||||
) {
|
||||
}
|
||||
constructor(readonly status: number, readonly buildScanUrl?: string) {}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
const IS_WINDOWS = process.platform === "win32";
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
|
||||
export function wrapperFilename(): string {
|
||||
return IS_WINDOWS ? "gradlew.bat" : "gradlew";
|
||||
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
|
||||
}
|
||||
|
||||
|
||||
export function installScriptFilename(): string {
|
||||
return IS_WINDOWS ? "gradle.bat" : "gradle";
|
||||
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
||||
}
|
||||
|
|
79
src/main.ts
79
src/main.ts
|
@ -1,80 +1,77 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as path from "path";
|
||||
import {parseArgsStringToArgv} from "string-argv";
|
||||
|
||||
import * as execution from "./execution";
|
||||
import * as gradlew from "./gradlew";
|
||||
import * as provision from "./provision";
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import {parseArgsStringToArgv} from 'string-argv'
|
||||
|
||||
import * as cache from './cache'
|
||||
import * as execution from './execution'
|
||||
import * as gradlew from './gradlew'
|
||||
import * as provision from './provision'
|
||||
|
||||
// Invoked by GitHub Actions
|
||||
export async function run() {
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
||||
|
||||
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
|
||||
|
||||
let result = await execution.execute(
|
||||
const result = await execution.execute(
|
||||
await resolveGradleExecutable(baseDirectory),
|
||||
resolveBuildRootDirectory(baseDirectory),
|
||||
parseCommandLineArguments()
|
||||
);
|
||||
)
|
||||
|
||||
if (result.buildScanUrl) {
|
||||
core.setOutput("build-scan-url", result.buildScanUrl);
|
||||
core.setOutput('build-scan-url', result.buildScanUrl)
|
||||
}
|
||||
|
||||
if (result.status != 0) {
|
||||
if (result.status !== 0) {
|
||||
core.setFailed(`Gradle process exited with status ${result.status}`)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
run();
|
||||
|
||||
run()
|
||||
|
||||
async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
||||
|
||||
const gradleVersion = inputOrNull("gradle-version");
|
||||
if (gradleVersion != null && gradleVersion != "wrapper") {
|
||||
const gradleVersion = inputOrNull('gradle-version')
|
||||
if (gradleVersion !== null && gradleVersion !== 'wrapper') {
|
||||
return path.resolve(await provision.gradleVersion(gradleVersion))
|
||||
}
|
||||
|
||||
const gradleExecutable = inputOrNull("gradle-executable");
|
||||
if (gradleExecutable != null) {
|
||||
const gradleExecutable = inputOrNull('gradle-executable')
|
||||
if (gradleExecutable !== null) {
|
||||
return path.resolve(baseDirectory, gradleExecutable)
|
||||
}
|
||||
|
||||
const wrapperDirectory = inputOrNull("wrapper-directory");
|
||||
const executableDirectory = wrapperDirectory != null
|
||||
? path.join(baseDirectory, wrapperDirectory)
|
||||
: baseDirectory;
|
||||
const wrapperDirectory = inputOrNull('wrapper-directory')
|
||||
const executableDirectory =
|
||||
wrapperDirectory !== null
|
||||
? path.join(baseDirectory, wrapperDirectory)
|
||||
: baseDirectory
|
||||
|
||||
return path.resolve(executableDirectory, gradlew.wrapperFilename());
|
||||
await cache.restoreCachedWrapperDist(executableDirectory)
|
||||
|
||||
return path.resolve(executableDirectory, gradlew.wrapperFilename())
|
||||
}
|
||||
|
||||
|
||||
function resolveBuildRootDirectory(baseDirectory: string): string {
|
||||
let buildRootDirectory = inputOrNull("build-root-directory");
|
||||
return buildRootDirectory == null
|
||||
? path.resolve(baseDirectory)
|
||||
: path.resolve(baseDirectory, buildRootDirectory);
|
||||
const buildRootDirectory = inputOrNull('build-root-directory')
|
||||
const resolvedBuildRootDirectory =
|
||||
buildRootDirectory === null
|
||||
? path.resolve(baseDirectory)
|
||||
: path.resolve(baseDirectory, buildRootDirectory)
|
||||
return resolvedBuildRootDirectory
|
||||
}
|
||||
|
||||
|
||||
function parseCommandLineArguments(): string[] {
|
||||
const input = inputOrNull("arguments");
|
||||
return input == null ? [] : parseArgsStringToArgv(input)
|
||||
const input = inputOrNull('arguments')
|
||||
return input === null ? [] : parseArgsStringToArgv(input)
|
||||
}
|
||||
|
||||
|
||||
function inputOrNull(name: string): string | null {
|
||||
const inputString = core.getInput(name);
|
||||
if (inputString.length == 0) {
|
||||
return null;
|
||||
const inputString = core.getInput(name)
|
||||
if (inputString.length === 0) {
|
||||
return null
|
||||
}
|
||||
return inputString
|
||||
}
|
||||
|
|
8
src/post.ts
Normal file
8
src/post.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import * as cache from './cache'
|
||||
|
||||
// Invoked by GitHub Actions
|
||||
export async function run(): Promise<void> {
|
||||
await cache.cacheWrapperDist()
|
||||
}
|
||||
|
||||
run()
|
221
src/provision.ts
221
src/provision.ts
|
@ -1,163 +1,174 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as httpm from 'typed-rest-client/HttpClient';
|
||||
import * as unzip from "unzipper"
|
||||
import * as core from "@actions/core";
|
||||
import * as io from '@actions/io';
|
||||
import * as toolCache from "@actions/tool-cache";
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as httpm from 'typed-rest-client/HttpClient'
|
||||
import * as unzip from 'unzipper'
|
||||
import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
|
||||
import * as gradlew from "./gradlew";
|
||||
|
||||
|
||||
const httpc = new httpm.HttpClient("eskatos/gradle-command-action");
|
||||
const gradleVersionsBaseUrl = "https://services.gradle.org/versions";
|
||||
import * as gradlew from './gradlew'
|
||||
|
||||
const httpc = new httpm.HttpClient('eskatos/gradle-command-action')
|
||||
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||
|
||||
/**
|
||||
* @return Gradle executable path
|
||||
*/
|
||||
export async function gradleVersion(gradleVersion: string): Promise<string> {
|
||||
switch (gradleVersion) {
|
||||
case "current":
|
||||
return gradleCurrent();
|
||||
case "rc":
|
||||
return gradleReleaseCandidate();
|
||||
case "nightly":
|
||||
return gradleNightly();
|
||||
case "release-nightly":
|
||||
return gradleReleaseNightly();
|
||||
export async function gradleVersion(version: string): Promise<string> {
|
||||
switch (version) {
|
||||
case 'current':
|
||||
return gradleCurrent()
|
||||
case 'rc':
|
||||
return gradleReleaseCandidate()
|
||||
case 'nightly':
|
||||
return gradleNightly()
|
||||
case 'release-nightly':
|
||||
return gradleReleaseNightly()
|
||||
default:
|
||||
return gradle(gradleVersion);
|
||||
return gradle(version)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function gradleCurrent(): Promise<string> {
|
||||
const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
|
||||
return provisionGradle(json.version, json.downloadUrl);
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/current`
|
||||
)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
|
||||
async function gradleReleaseCandidate(): Promise<string> {
|
||||
const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
|
||||
if (json) {
|
||||
return provisionGradle(json.version, json.downloadUrl);
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/release-candidate`
|
||||
)
|
||||
if (versionInfo) {
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
return gradleCurrent();
|
||||
return gradleCurrent()
|
||||
}
|
||||
|
||||
|
||||
async function gradleNightly(): Promise<string> {
|
||||
const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/nightly`);
|
||||
return provisionGradle(json.version, json.downloadUrl);
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/nightly`
|
||||
)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
|
||||
async function gradleReleaseNightly(): Promise<string> {
|
||||
const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-nightly`);
|
||||
return provisionGradle(json.version, json.downloadUrl);
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/release-nightly`
|
||||
)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
|
||||
async function gradle(version: string): Promise<string> {
|
||||
const declaration = await findGradleVersionDeclaration(version);
|
||||
if (!declaration) {
|
||||
throw new Error(`Gradle version ${version} does not exists`);
|
||||
const versionInfo = await findGradleVersionDeclaration(version)
|
||||
if (!versionInfo) {
|
||||
throw new Error(`Gradle version ${version} does not exists`)
|
||||
}
|
||||
return provisionGradle(declaration.version, declaration.downloadUrl);
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
|
||||
async function gradleVersionDeclaration(url: string): Promise<any | undefined> {
|
||||
const json: any = await httpGetJson(url);
|
||||
return (json.version && json.version.length > 0) ? json : undefined
|
||||
async function gradleVersionDeclaration(
|
||||
url: string
|
||||
): Promise<GradleVersionInfo> {
|
||||
return await httpGetGradleVersion(url)
|
||||
}
|
||||
|
||||
|
||||
async function findGradleVersionDeclaration(version: string): Promise<any | undefined> {
|
||||
const json: any = await httpGetJson(`${gradleVersionsBaseUrl}/all`);
|
||||
const found: any = json.find((entry: any) => {
|
||||
return entry.version === version;
|
||||
});
|
||||
return found ? found : undefined
|
||||
async function findGradleVersionDeclaration(
|
||||
version: string
|
||||
): Promise<GradleVersionInfo | undefined> {
|
||||
const gradleVersions = await httpGetGradleVersions(
|
||||
`${gradleVersionsBaseUrl}/all`
|
||||
)
|
||||
return gradleVersions.find((entry: GradleVersionInfo) => {
|
||||
return entry.version === version
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async function provisionGradle(version: string, url: string): Promise<string> {
|
||||
|
||||
const cachedInstall: string = toolCache.find("gradle", version);
|
||||
const cachedInstall: string = toolCache.find('gradle', version)
|
||||
if (cachedInstall.length > 0) {
|
||||
const cachedExecutable = executableFrom(cachedInstall);
|
||||
core.info(`Provisioned Gradle executable ${cachedExecutable}`);
|
||||
return cachedExecutable;
|
||||
const cachedExecutable = executableFrom(cachedInstall)
|
||||
core.info(`Provisioned Gradle executable ${cachedExecutable}`)
|
||||
return cachedExecutable
|
||||
}
|
||||
|
||||
const home = process.env["HOME"] || "";
|
||||
const tmpdir = path.join(home, "gradle-provision-tmpdir");
|
||||
const downloadsDir = path.join(tmpdir, "downloads");
|
||||
const installsDir = path.join(tmpdir, "installs");
|
||||
await io.mkdirP(downloadsDir);
|
||||
await io.mkdirP(installsDir);
|
||||
const home = process.env['HOME'] || ''
|
||||
const tmpdir = path.join(home, 'gradle-provision-tmpdir')
|
||||
const downloadsDir = path.join(tmpdir, 'downloads')
|
||||
const installsDir = path.join(tmpdir, 'installs')
|
||||
await io.mkdirP(downloadsDir)
|
||||
await io.mkdirP(installsDir)
|
||||
|
||||
core.info(`Downloading ${url}`);
|
||||
core.info(`Downloading ${url}`)
|
||||
|
||||
const downloadPath = path.join(downloadsDir, `gradle-${version}-bin.zip`);
|
||||
await httpDownload(url, downloadPath);
|
||||
core.info(`Downloaded at ${downloadPath}, size ${fs.statSync(downloadPath).size}`);
|
||||
const downloadPath = path.join(downloadsDir, `gradle-${version}-bin.zip`)
|
||||
await httpDownload(url, downloadPath)
|
||||
core.info(
|
||||
`Downloaded at ${downloadPath}, size ${fs.statSync(downloadPath).size}`
|
||||
)
|
||||
|
||||
await extractZip(downloadPath, installsDir);
|
||||
const installDir = path.join(installsDir, `gradle-${version}`);
|
||||
core.info(`Extracted in ${installDir}`);
|
||||
await extractZip(downloadPath, installsDir)
|
||||
const installDir = path.join(installsDir, `gradle-${version}`)
|
||||
core.info(`Extracted in ${installDir}`)
|
||||
|
||||
const executable = executableFrom(installDir);
|
||||
fs.chmodSync(executable, "755");
|
||||
core.info(`Provisioned Gradle executable ${executable}`);
|
||||
const executable = executableFrom(installDir)
|
||||
fs.chmodSync(executable, '755')
|
||||
core.info(`Provisioned Gradle executable ${executable}`)
|
||||
|
||||
toolCache.cacheDir(installDir, "gradle", version);
|
||||
toolCache.cacheDir(installDir, 'gradle', version)
|
||||
|
||||
return executable;
|
||||
return executable
|
||||
}
|
||||
|
||||
|
||||
function executableFrom(installDir: string): string {
|
||||
return path.join(installDir, "bin", `${gradlew.installScriptFilename()}`);
|
||||
return path.join(installDir, 'bin', `${gradlew.installScriptFilename()}`)
|
||||
}
|
||||
|
||||
|
||||
async function httpGetJson(url: string): Promise<any> {
|
||||
const response = await httpc.get(url);
|
||||
const body = await response.readBody();
|
||||
return JSON.parse(body);
|
||||
async function httpGetGradleVersion(url: string): Promise<GradleVersionInfo> {
|
||||
return JSON.parse(await httpGetString(url))
|
||||
}
|
||||
|
||||
async function httpGetGradleVersions(
|
||||
url: string
|
||||
): Promise<GradleVersionInfo[]> {
|
||||
return JSON.parse(await httpGetString(url))
|
||||
}
|
||||
|
||||
async function httpDownload(url: string, path: string): Promise<void> {
|
||||
async function httpGetString(url: string): Promise<string> {
|
||||
const response = await httpc.get(url)
|
||||
return response.readBody()
|
||||
}
|
||||
|
||||
async function httpDownload(url: string, localPath: string): Promise<void> {
|
||||
const response = await httpc.get(url)
|
||||
return new Promise<void>(function (resolve, reject) {
|
||||
const writeStream = fs.createWriteStream(path);
|
||||
httpc.get(url).then(response => {
|
||||
response.message.pipe(writeStream)
|
||||
.on("close", () => {
|
||||
resolve();
|
||||
})
|
||||
.on("error", err => {
|
||||
reject(err)
|
||||
});
|
||||
}).catch(reason => {
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
const writeStream = fs.createWriteStream(localPath)
|
||||
response.message
|
||||
.pipe(writeStream)
|
||||
.on('close', () => {
|
||||
resolve()
|
||||
})
|
||||
.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async function extractZip(zip: string, destination: string): Promise<void> {
|
||||
return new Promise<void>(function (resolve, reject) {
|
||||
fs.createReadStream(zip)
|
||||
.pipe(unzip.Extract({"path": destination}))
|
||||
.on("close", () => {
|
||||
resolve();
|
||||
.pipe(unzip.Extract({path: destination}))
|
||||
.on('close', () => {
|
||||
resolve()
|
||||
})
|
||||
.on("error", err => {
|
||||
.on('error', err => {
|
||||
reject(err)
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
interface GradleVersionInfo {
|
||||
version: string
|
||||
downloadUrl: string
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"incremental": true, /* Enable incremental compilation */
|
||||
"incremental": false, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
|
|
Loading…
Reference in a new issue