mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-10-19 22:38:58 +08:00
Compare commits
13 Commits
v2.0-beta.
...
v1.3.1
Author | SHA1 | Date | |
---|---|---|---|
|
791b98c565 | ||
|
27da3e28b3 | ||
|
e220e54c83 | ||
|
720051268d | ||
|
36d51a403a | ||
|
d0c5f7955e | ||
|
a2ba194e38 | ||
|
064f85c156 | ||
|
580b26a94c | ||
|
c61d0fe2b5 | ||
|
6170f06e8d | ||
|
e561eefa28 | ||
|
2d5ca45eab |
30
.github/workflows/dev.yml
vendored
30
.github/workflows/dev.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Verify generated outputs
|
||||
name: dev
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
@@ -6,7 +6,10 @@ on:
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
@@ -14,10 +17,19 @@ jobs:
|
||||
run: |
|
||||
npm install
|
||||
npm run all
|
||||
- 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)
|
||||
- name: Test wrapper
|
||||
uses: ./
|
||||
with:
|
||||
wrapper-directory: __tests__/data/basic
|
||||
build-root-directory: __tests__/data/basic
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
arguments: test
|
||||
- name: Test dist download
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: 6.6-milestone-1
|
||||
build-root-directory: __tests__/data/basic
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
arguments: test --configuration-cache
|
||||
|
34
.github/workflows/failure-cases.yml
vendored
34
.github/workflows/failure-cases.yml
vendored
@@ -1,34 +0,0 @@
|
||||
name: Execute failure cases
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||
|
||||
jobs:
|
||||
|
||||
wrapper-missing:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Test wrapper missing
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help
|
||||
|
||||
bad-configuration:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Test bad config value
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help
|
||||
cache-disabled: yes
|
84
.github/workflows/integTest-caching.yml
vendored
84
.github/workflows/integTest-caching.yml
vendored
@@ -1,84 +0,0 @@
|
||||
name: Test caching
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||
|
||||
jobs:
|
||||
# Run initial Gradle builds to push initial cache entries
|
||||
# These builds should start fresh without cache hits, due to the seed injected into the cache key above.
|
||||
seed-build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Build using Gradle wrapper
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test
|
||||
- name: Build with configuration-cache enabled
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --configuration-cache
|
||||
|
||||
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
||||
dependencies-cache:
|
||||
needs: seed-build
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Execute Gradle build with --offline
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --offline
|
||||
cache-read-only: true
|
||||
|
||||
# Test that the gradle-user-home cache will cache and restore local build-cache
|
||||
build-cache:
|
||||
needs: seed-build
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Execute Gradle build and verify tasks from cache
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test -DverifyCachedBuild=true
|
||||
cache-read-only: true
|
||||
|
||||
# Test that the project-dot-gradle cache will cache and restore configuration-cache
|
||||
configuration-cache:
|
||||
needs: seed-build
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Execute Gradle build and verify cached configuration
|
||||
uses: ./
|
||||
env:
|
||||
VERIFY_CACHED_CONFIGURATION: true
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --configuration-cache
|
||||
cache-read-only: true
|
42
.github/workflows/integTest-execution.yml
vendored
42
.github/workflows/integTest-execution.yml
vendored
@@ -1,42 +0,0 @@
|
||||
name: Test Gradle execution
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||
|
||||
jobs:
|
||||
# Tests for executing with different Gradle versions.
|
||||
# Each build verifies that it is executed with the expected Gradle version.
|
||||
gradle-execution:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
include:
|
||||
- os: windows-latest
|
||||
script-suffix: '.bat'
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Test use defined Gradle version
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: 6.9
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=6.9
|
||||
- name: Test use Gradle version alias
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: release-candidate
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=7.2
|
||||
- name: Test use defined Gradle executable
|
||||
uses: ./
|
||||
with:
|
||||
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=7.1.1
|
52
.github/workflows/integTest-gradle-user-home.yml
vendored
52
.github/workflows/integTest-gradle-user-home.yml
vendored
@@ -1,52 +0,0 @@
|
||||
name: Test caching with a custom GRADLE_USER_HOME
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||
GRADLE_USER_HOME: custom/gradle/home
|
||||
|
||||
jobs:
|
||||
# Run initial Gradle builds to push initial cache entries
|
||||
# These builds should start fresh without cache hits, due to the seed injected into the cache key above.
|
||||
seed-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Build using Gradle wrapper
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: 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
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Execute Gradle build with --offline
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --offline
|
||||
cache-read-only: true
|
||||
|
||||
# Test that the gradle-user-home cache will cache and restore local build-cache
|
||||
build-cache:
|
||||
needs: seed-build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Execute Gradle build and verify tasks from cache
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test -DverifyCachedBuild=true
|
||||
cache-read-only: true
|
36
.github/workflows/integTest-kotlin-dsl.yml
vendored
36
.github/workflows/integTest-kotlin-dsl.yml
vendored
@@ -1,36 +0,0 @@
|
||||
name: Test caching with Kotlin DSL
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||
CACHE_DEBUG_ENABLED: true
|
||||
|
||||
jobs:
|
||||
# Use kotlin-dsl project to verify caching of generated jars and compiled scripts
|
||||
seed-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Build kotlin-dsl project
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/kotlin-dsl
|
||||
arguments: test
|
||||
|
||||
# Check that the build can run --offline
|
||||
verify-build:
|
||||
needs: seed-build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Build kotlin-dsl project
|
||||
uses: ./
|
||||
with:
|
||||
build-root-directory: __tests__/samples/kotlin-dsl
|
||||
arguments: test --offline
|
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:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
- name: Test wrapper
|
||||
uses: ./
|
||||
with:
|
||||
wrapper-directory: __tests__/data/basic
|
||||
build-root-directory: __tests__/data/basic
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
arguments: test
|
||||
- name: Test dist download
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: 6.6-milestone-1
|
||||
build-root-directory: __tests__/data/basic
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
arguments: test --configuration-cache
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -98,9 +98,5 @@ Thumbs.db
|
||||
__tests__/runner/*
|
||||
# lib/**/*
|
||||
|
||||
# IntelliJ IDEA config files
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# ASDF tool configuration
|
||||
.tool-versions
|
||||
|
182
README.md
182
README.md
@@ -1,14 +1,12 @@
|
||||
# Execute Gradle builds in GitHub Actions workflows
|
||||
# Execute Gradle commands in GitHub Actions workflows
|
||||
|
||||
This GitHub Action can be used to execute a Gradle build on any platform supported by GitHub Actions.
|
||||
This GitHub Action can be used to run arbitrary Gradle commands on any platform supported by GitHub Actions.
|
||||
|
||||
**Note:** The following documentation is for `gradle/gradle-build-action@v2`, currently in Beta release.
|
||||
You can view the documentation for the latest stable release (v1.5.1) [on the GitHub Marketplace](https://github.com/marketplace/actions/gradle-build-action?version=v1.5.1).
|
||||
You might also be interested by the related [Gradle Plugin](https://github.com/eskatos/gradle-github-actions-plugin) that allows your build to easily get GitHub Actions environment and tag Gradle Build Scans accordingly.
|
||||
|
||||
## Usage
|
||||
|
||||
The following workflow will run `./gradlew build` on ubuntu, macos and windows.
|
||||
The only prerequisite is to have Java installed: you define the version of Java 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.
|
||||
|
||||
```yaml
|
||||
# .github/workflows/gradle-build-pr.yml
|
||||
@@ -25,26 +23,12 @@ jobs:
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
arguments: build
|
||||
```
|
||||
|
||||
It is possible to configure multiple Gradle executions to run sequentially in the same job.
|
||||
Each invocation will start its run with the filesystem state remaining from the previous execution.
|
||||
|
||||
```yaml
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
with:
|
||||
arguments: assemble
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
with:
|
||||
arguments: check
|
||||
```
|
||||
|
||||
## Gradle Execution
|
||||
|
||||
### Command-line arguments
|
||||
## Gradle arguments
|
||||
|
||||
The `arguments` input can used to pass arbitrary arguments to the `gradle` command line.
|
||||
|
||||
@@ -60,47 +44,42 @@ arguments: build -DsystemProperty=bar
|
||||
|
||||
See `gradle --help` for more information.
|
||||
|
||||
If you need to pass environment variables, use the GitHub Actions workflow syntax:
|
||||
If you need to pass environment variables, simply use the GitHub Actions workflow syntax:
|
||||
|
||||
```yaml
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
env:
|
||||
CI: true
|
||||
with:
|
||||
arguments: build
|
||||
```
|
||||
|
||||
### Gradle build located in a subdirectory
|
||||
|
||||
By default, the action will execute Gradle in the root directory of your project.
|
||||
Use the `build-root-directory` input to target a Gradle build in a subdirectory.
|
||||
## Run a build from a different directory
|
||||
|
||||
```yaml
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
build-root-directory: some/subdirectory
|
||||
```
|
||||
|
||||
### Using a specific Gradle executable
|
||||
## Use a Gradle wrapper from a different directory
|
||||
|
||||
```yaml
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
wrapper-directory: path/to/wrapper-directory
|
||||
```
|
||||
|
||||
The action will first look for a Gradle wrapper script in the root directory of your project.
|
||||
If not found, `gradle` will be executed from the PATH.
|
||||
Use the `gradle-executable` input to execute using a specific Gradle installation.
|
||||
## Use a specific `gradle` executable
|
||||
|
||||
```yaml
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
gradle-executable: /path/to/installed/gradle
|
||||
gradle-executable: path/to/gradle
|
||||
```
|
||||
|
||||
This mechanism can also be used to target a Gradle wrapper script that is located in a non-default location.
|
||||
|
||||
### Download, install and use a specific Gradle version
|
||||
|
||||
The `gradle-build-action` is able to download and install a specific Gradle version to execute.
|
||||
## Setup and use a declared Gradle version
|
||||
|
||||
```yaml
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
gradle-version: 6.5
|
||||
```
|
||||
@@ -111,13 +90,13 @@ Moreover, you can use the following aliases:
|
||||
|
||||
| Alias | Selects |
|
||||
| --- |---|
|
||||
| `wrapper` | The Gradle wrapper's version (default, useful for matrix builds) |
|
||||
| `current` | The current [stable release](https://gradle.org/install/) |
|
||||
| `release-candidate` | The current [release candidate](https://gradle.org/release-candidate/) if any, otherwise fallback to `current` |
|
||||
| `nightly` | The latest [nightly](https://gradle.org/nightly/), fails if none. |
|
||||
| `release-nightly` | The latest [release nightly](https://gradle.org/release-nightly/), fails if none. |
|
||||
| `wrapper` | The Gradle wrapper's version (default, useful for matrix builds) |
|
||||
| `current` | The current [stable release](https://gradle.org/install/) |
|
||||
| `rc` | The current [release candidate](https://gradle.org/release-candidate/) if any, otherwise fallback to `current` |
|
||||
| `nightly` | The latest [nightly](https://gradle.org/nightly/), fails if none. |
|
||||
| `release-nightly` | The latest [release nightly](https://gradle.org/release-nightly/), fails if none. |
|
||||
|
||||
This can be handy to automatically verify your build works with the latest release candidate of Gradle:
|
||||
This can be handy to, for example, automatically test your build with the next Gradle version once a release candidate is out:
|
||||
|
||||
```yaml
|
||||
# .github/workflows/test-gradle-rc.yml
|
||||
@@ -133,62 +112,84 @@ jobs:
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
gradle-version: release-candidate
|
||||
gradle-version: rc
|
||||
arguments: build --dry-run # just test build configuration
|
||||
```
|
||||
|
||||
## Caching
|
||||
|
||||
By default, this action aims to cache any and all reusable state that may be speed up a subsequent build invocation.
|
||||
This action provides 3 levels of caching to help speed up your GitHub Actions:
|
||||
|
||||
The state that is cached includes:
|
||||
- Any distributions downloaded to satisfy a `gradle-version` parameter ;
|
||||
- A subset of the Gradle User Home directory, including downloaded dependencies, wrapper distributions, and the local build cache ;
|
||||
- Any [configuration-cache](https://docs.gradle.org/nightly/userguide/configuration_cache.html) data stored in the project `.gradle` directory.
|
||||
- `wrapper` caches the local [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) installation, saving time downloading and unpacking Gradle distributions ;
|
||||
- `dependencies` caches the [dependencies](https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:cache_copy), saving time downloading dependencies ;
|
||||
- `configuration` caches the [build configuration](https://docs.gradle.org/nightly/userguide/configuration_cache.html), saving time configuring the build.
|
||||
|
||||
To reduce the space required for caching, this action makes a best effort to reduce duplication in cache entries.
|
||||
Only the first one, caching the wrapper installation, is enabled by default.
|
||||
Future versions of this action will enable all caching by default.
|
||||
|
||||
You can control which level is enabled as follows:
|
||||
|
||||
Caching is enabled by default. You can disable caching for the action as follows:
|
||||
```yaml
|
||||
cache-disabled: true
|
||||
wrapper-cache-enabled: true
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
```
|
||||
|
||||
At this time it is not possible to fine-tune the caching performed by this action.
|
||||
If you have a legitimate use case for fine-grained caching or restricting which files are cached, please raise an issue.
|
||||
The wrapper installation cache is simple and can't be configured further.
|
||||
|
||||
### Cache keys
|
||||
The dependencies and configuration cache will compute a cache key in a best effort manner.
|
||||
Keep reading to learn how to better control how they work.
|
||||
|
||||
For cached distributions, the cache key is unique to the downloaded distribution. This will not change over time.
|
||||
### Configuring the dependencies and configuration caches
|
||||
|
||||
The state of the Gradle User Home and configuration-cache are highly dependent on the Gradle execution, so the cache key is composed of the current commit hash and the GitHub actions job id.
|
||||
As such, the cache key is likely to change on each subsequent run of GitHub actions.
|
||||
This allows the most recent state to always be available in the GitHub actions cache.
|
||||
Both the dependencies and configuration caches use the same default configuration:
|
||||
|
||||
To reduce duplication between cache entries, certain artifacts are cached independently based on their identity.
|
||||
Artifacts that are cached independently include downloaded dependencies, downloaded wrapper distributions and generated Gradle API jars.
|
||||
For example, this means that all jobs executing a particular version of the Gradle wrapper will share common entries for wrapper distributions and for generated Gradle API jars.
|
||||
They use the following inputs to calculate the cache key:
|
||||
|
||||
### Using the caches read-only
|
||||
```text
|
||||
**/*.gradle
|
||||
**/*.gradle.kts
|
||||
**/gradle.properties
|
||||
gradle/**
|
||||
```
|
||||
|
||||
Cache storage space is limited for GitHub actions, and writing new cache entries can trigger the deletion of exising entries.
|
||||
In some circumstances, it makes sense for a Gradle invocation to read any existing cache entries but not to write changes back.
|
||||
For example, you may want to write cache entries for builds on your `main` branch, but not for any PR build invocations.
|
||||
This is a good enough approximation.
|
||||
They restore cached state even if there isn't an exact match.
|
||||
|
||||
You can enable read-only caching for any of the caches as follows:
|
||||
If the defaults don't suit your needs you can override them with the following inputs:
|
||||
|
||||
```yaml
|
||||
cache-read-only: true
|
||||
dependencies-cache-key: |
|
||||
**/gradle.properties
|
||||
gradle/dependency-locking/**
|
||||
dependencies-cache-exact: true
|
||||
configuration-cache-key: |
|
||||
**/gradle.properties
|
||||
gradle/dependency-locking/**
|
||||
configuration-cache-exact: true
|
||||
```
|
||||
|
||||
Coming up with a good cache key isn't trivial and depends on your build.
|
||||
The above example isn't realistic.
|
||||
Stick to the defaults unless you know what you are doing.
|
||||
|
||||
If you happen to use Gradle [dependency locking](https://docs.gradle.org/current/userguide/dependency_locking.html) you can make the dependencies cache more precise with the following configuration:
|
||||
|
||||
```yaml
|
||||
dependencies-cache-enabled: true
|
||||
dependencies-cache-key: gradle/dependency-locking/**
|
||||
dependencies-cache-exact: true
|
||||
```
|
||||
|
||||
## Build scans
|
||||
|
||||
If your build publishes a [build scan](https://gradle.com/build-scans/) the `gradle-build-action` action will:
|
||||
- Add a notice with the link to the GitHub Actions user interface
|
||||
- Emit the link to the published build scan as an output named `build-scan-url`.
|
||||
If your build publishes a [build scan](https://gradle.com/build-scans/) the `gradle-command-action` action will emit the link to the published build scan as an output named `build-scan-url`.
|
||||
|
||||
You can then use that link in subsequent actions of your workflow. For example:
|
||||
You can then use that link in subsequent actions of your workflow.
|
||||
|
||||
For example:
|
||||
|
||||
```yaml
|
||||
# .github/workflows/gradle-build-pr.yml
|
||||
@@ -196,26 +197,21 @@ name: Run Gradle on PRs
|
||||
on: pull_request
|
||||
jobs:
|
||||
gradle:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- uses: gradle/gradle-build-action@v2
|
||||
id: gradle
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
arguments: build
|
||||
- name: "Comment build scan url"
|
||||
uses: actions/github-script@v3
|
||||
if: github.event_name == 'pull_request' && failure()
|
||||
id: gradle
|
||||
- uses: example/action-that-comments-on-the-pr@v0
|
||||
if: failure()
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
github.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: '❌ ${{ github.workflow }} failed: ${{ steps.gradle.outputs.build-scan-url }}'
|
||||
})
|
||||
comment: Build failed ${{ steps.gradle.outputs.build-scan-url }}
|
||||
```
|
||||
|
@@ -1,21 +0,0 @@
|
||||
import * as cacheUtils from '../src/cache-utils'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('cacheUtils-utils', () => {
|
||||
describe('can hash', () => {
|
||||
it('a string', async () => {
|
||||
const hash = cacheUtils.hashStrings(['foo'])
|
||||
expect(hash).toBe('acbd18db4cc2f85cedef654fccc4a4d8')
|
||||
})
|
||||
it('multiple strings', async () => {
|
||||
const hash = cacheUtils.hashStrings(['foo', 'bar', 'baz'])
|
||||
expect(hash).toBe('6df23dc03f9b54cc38a0fc1483df6e21')
|
||||
})
|
||||
it('normalized filenames', async () => {
|
||||
const fileNames = ['/foo/bar/baz.zip', '../boo.html']
|
||||
const posixHash = cacheUtils.hashFileNames(fileNames)
|
||||
const windowsHash = cacheUtils.hashFileNames(fileNames)
|
||||
expect(posixHash).toBe(windowsHash)
|
||||
})
|
||||
})
|
||||
})
|
33
__tests__/cache-wrapper.test.ts
Normal file
33
__tests__/cache-wrapper.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import * as cacheWrapper from '../src/cache-wrapper'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('cache', () => {
|
||||
describe('can extract gradle wrapper slug', () => {
|
||||
it('from wrapper properties file', async () => {
|
||||
const version = cacheWrapper.extractGradleWrapperSlugFrom(
|
||||
path.resolve(
|
||||
'__tests__/data/basic/gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
)
|
||||
expect(version).toBe('6.5-bin')
|
||||
})
|
||||
it('for -bin dist', async () => {
|
||||
const version = cacheWrapper.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 = cacheWrapper.extractGradleWrapperSlugFromDistUri(
|
||||
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.5-all.zip'
|
||||
)
|
||||
expect(version).toBe('6.5-all')
|
||||
})
|
||||
it('for milestone', async () => {
|
||||
const version = cacheWrapper.extractGradleWrapperSlugFromDistUri(
|
||||
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.6-milestone-1-all.zip'
|
||||
)
|
||||
expect(version).toBe('6.6-milestone-1-all')
|
||||
})
|
||||
})
|
||||
})
|
39
__tests__/crypto-utils.test.ts
Normal file
39
__tests__/crypto-utils.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as cryptoUtils from '../src/crypto-utils'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('crypto-utils', () => {
|
||||
describe('can hash', () => {
|
||||
it('a directory', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
path.resolve('__tests__/data/basic/gradle')
|
||||
)
|
||||
expect(hash).toBe(
|
||||
process.platform === 'win32'
|
||||
? '3364336e94e746ce65a31748a6371b7efd7d499e18ad605c74c91cde0edc0a44'
|
||||
: '4ebb65b45e6f6796d5ec6ace96e9471cc6573d294c54f99c4920fe5328e75bab'
|
||||
)
|
||||
})
|
||||
it('a directory with a glob', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
path.resolve('__tests__/data/basic/'),
|
||||
['gradle/**']
|
||||
)
|
||||
expect(hash).toBe(
|
||||
process.platform === 'win32'
|
||||
? '3364336e94e746ce65a31748a6371b7efd7d499e18ad605c74c91cde0edc0a44'
|
||||
: '4ebb65b45e6f6796d5ec6ace96e9471cc6573d294c54f99c4920fe5328e75bab'
|
||||
)
|
||||
})
|
||||
it('a directory with globs', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
path.resolve('__tests__/data/basic/'),
|
||||
['**/*.gradle', 'gradle/**']
|
||||
)
|
||||
expect(hash).toBe(
|
||||
process.platform === 'win32'
|
||||
? 'd9b66fded38f79f601ce745d64ed726a8df8c0b242b02bcd2c1d331f54742ad6'
|
||||
: 'aa72a837158799fbadd1c4aff94fcc2b5bb9dc6ad8d12f6337d047d4b0c8f79e'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
@@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
@@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
6
__tests__/samples/basic/.gitattributes
vendored
6
__tests__/samples/basic/.gitattributes
vendored
@@ -1,6 +0,0 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
__tests__/samples/basic/.gitignore
vendored
5
__tests__/samples/basic/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
@@ -1,23 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation('junit:junit:4.12')
|
||||
}
|
||||
|
||||
tasks.named("test").configure {
|
||||
// Use an environment variable to bypass config-cache checks
|
||||
if (System.getenv('VERIFY_CACHED_CONFIGURATION') != null) {
|
||||
throw new RuntimeException("Configuration was not cached: unexpected configuration of test task")
|
||||
}
|
||||
doLast {
|
||||
if (System.properties.verifyCachedBuild) {
|
||||
throw new RuntimeException("Build was not cached: unexpected execution of test task")
|
||||
}
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
org.gradle.caching=true
|
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
185
__tests__/samples/basic/gradlew
vendored
185
__tests__/samples/basic/gradlew
vendored
@@ -1,185 +0,0 @@
|
||||
#!/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__/samples/basic/gradlew.bat
vendored
104
__tests__/samples/basic/gradlew.bat
vendored
@@ -1,104 +0,0 @@
|
||||
@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
|
@@ -1 +0,0 @@
|
||||
rootProject.name = 'basic'
|
@@ -1,10 +0,0 @@
|
||||
package basic;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BasicTest {
|
||||
@Test
|
||||
public void test() {
|
||||
assert true;
|
||||
}
|
||||
}
|
6
__tests__/samples/kotlin-dsl/.gitattributes
vendored
6
__tests__/samples/kotlin-dsl/.gitattributes
vendored
@@ -1,6 +0,0 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
__tests__/samples/kotlin-dsl/.gitignore
vendored
5
__tests__/samples/kotlin-dsl/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
@@ -1,18 +0,0 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api("org.apache.commons:commons-math3:3.6.1")
|
||||
implementation("com.google.guava:guava:30.1.1-jre")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
@@ -1 +0,0 @@
|
||||
org.gradle.caching=true
|
Binary file not shown.
234
__tests__/samples/kotlin-dsl/gradlew
vendored
234
__tests__/samples/kotlin-dsl/gradlew
vendored
@@ -1,234 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original 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 POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${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 "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# 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 ;; #(
|
||||
MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
__tests__/samples/kotlin-dsl/gradlew.bat
vendored
89
__tests__/samples/kotlin-dsl/gradlew.bat
vendored
@@ -1,89 +0,0 @@
|
||||
@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 execute
|
||||
|
||||
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 execute
|
||||
|
||||
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
|
||||
|
||||
: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 %*
|
||||
|
||||
: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
|
@@ -1,15 +0,0 @@
|
||||
plugins {
|
||||
id("com.gradle.enterprise") version("3.7")
|
||||
}
|
||||
|
||||
gradleEnterprise {
|
||||
buildScan {
|
||||
termsOfServiceUrl = "https://gradle.com/terms-of-service"
|
||||
termsOfServiceAgree = "yes"
|
||||
publishAlways()
|
||||
isUploadInBackground = false
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "kotlin-dsl"
|
||||
|
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
public class Library {
|
||||
public boolean someLibraryMethod() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LibraryTest {
|
||||
@Test void someLibraryMethodReturnsTrue() {
|
||||
Library classUnderTest = new Library();
|
||||
assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'");
|
||||
}
|
||||
}
|
6
__tests__/samples/no-wrapper/.gitattributes
vendored
6
__tests__/samples/no-wrapper/.gitattributes
vendored
@@ -1,6 +0,0 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# These are explicitly windows files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
5
__tests__/samples/no-wrapper/.gitignore
vendored
5
__tests__/samples/no-wrapper/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
@@ -1,21 +0,0 @@
|
||||
plugins {
|
||||
id("com.gradle.enterprise") version("3.7")
|
||||
}
|
||||
|
||||
gradleEnterprise {
|
||||
buildScan {
|
||||
termsOfServiceUrl = "https://gradle.com/terms-of-service"
|
||||
termsOfServiceAgree = "yes"
|
||||
publishAlways()
|
||||
uploadInBackground = false
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = 'no-wrapper'
|
||||
|
||||
println "Using Gradle version: ${gradle.gradleVersion}"
|
||||
|
||||
def gradleVersionCheck = System.properties.gradleVersionCheck
|
||||
if (gradleVersionCheck && gradle.gradleVersion != gradleVersionCheck) {
|
||||
throw new RuntimeException("Got the wrong version: expected ${gradleVersionCheck} but was ${gradle.gradleVersion}")
|
||||
}
|
37
action.yml
37
action.yml
@@ -1,9 +1,13 @@
|
||||
name: "Gradle Build Action"
|
||||
description: 'Executes a Gradle build, caching useful state in the GitHub actions cache'
|
||||
name: "Gradle Command"
|
||||
description: 'Execute Gradle Command Line'
|
||||
author: 'Paul Merlin <paul@nospere.org>'
|
||||
|
||||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
|
||||
inputs:
|
||||
wrapper-directory:
|
||||
description: Path to the Gradle Wrapper directory
|
||||
required: false
|
||||
gradle-executable:
|
||||
description: Path to the Gradle executable
|
||||
required: false
|
||||
@@ -16,20 +20,27 @@ inputs:
|
||||
arguments:
|
||||
description: Gradle command line arguments, see gradle --help
|
||||
required: false
|
||||
cache-disabled:
|
||||
description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
|
||||
wrapper-cache-enabled:
|
||||
description: Whether caching wrapper installation is enabled or not, default to 'true'
|
||||
required: false
|
||||
default: false
|
||||
cache-read-only:
|
||||
description: When 'true', existing entries will be read from the cache but no entries will be written
|
||||
dependencies-cache-enabled:
|
||||
description: Whether caching dependencies is enabled or not, default to 'false'
|
||||
required: false
|
||||
# TODO: It might be useful to default to read-only for PRs, or non-main branch.
|
||||
default: false
|
||||
|
||||
workflow-job-context:
|
||||
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users.
|
||||
dependencies-cache-key:
|
||||
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
||||
required: false
|
||||
dependencies-cache-exact:
|
||||
description: Whether to restore only if exact match, default to 'false'
|
||||
required: false
|
||||
configuration-cache-enabled:
|
||||
description: Whether caching build configuration is enabled or not, default to 'false'
|
||||
required: false
|
||||
configuration-cache-key:
|
||||
description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
|
||||
required: false
|
||||
configuration-cache-exact:
|
||||
description: Whether to restore only if exact match, default to 'false'
|
||||
required: false
|
||||
default: ${{ toJSON(matrix) }}
|
||||
|
||||
outputs:
|
||||
build-scan-url:
|
||||
|
3
dist/main/index.js
vendored
3
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/main/index.js.map
vendored
1
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
3912
dist/main/sourcemap-register.js
vendored
3912
dist/main/sourcemap-register.js
vendored
File diff suppressed because it is too large
Load Diff
3
dist/post/index.js
vendored
3
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/post/index.js.map
vendored
1
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
3912
dist/post/sourcemap-register.js
vendored
3912
dist/post/sourcemap-register.js
vendored
File diff suppressed because it is too large
Load Diff
5164
package-lock.json
generated
5164
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
51
package.json
51
package.json
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"name": "gradle-build-action",
|
||||
"name": "gradle-command-action",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Execute Gradle Build",
|
||||
"description": "Execute Gradle Command Line",
|
||||
"scripts": {
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"build": "ncc build src/main.ts --out dist/main --source-map --minify && ncc build src/post.ts --out dist/post --source-map --minify",
|
||||
"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",
|
||||
"url": "git+https://github.com/gradle/gradle-build-action.git"
|
||||
"url": "git+https://github.com/eskatos/gradle-command-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"github",
|
||||
@@ -24,29 +24,30 @@
|
||||
"author": "Paul Merlin <paul@nosphere.org>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "1.0.7",
|
||||
"@actions/core": "1.5.0",
|
||||
"@actions/exec": "1.1.0",
|
||||
"@actions/github": "5.0.0",
|
||||
"@actions/glob": "0.2.0",
|
||||
"@actions/http-client": "1.0.11",
|
||||
"@actions/tool-cache": "1.7.1",
|
||||
"string-argv": "0.3.1"
|
||||
"@actions/cache": "0.2.1",
|
||||
"@actions/core": "1.2.4",
|
||||
"@actions/exec": "1.0.4",
|
||||
"@actions/glob": "0.1.0",
|
||||
"@actions/io": "1.0.2",
|
||||
"@actions/tool-cache": "1.5.5",
|
||||
"string-argv": "0.3.1",
|
||||
"typed-rest-client": "1.7.3",
|
||||
"unzipper": "0.10.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "26.0.23",
|
||||
"@types/node": "14.17.3",
|
||||
"@types/unzipper": "0.10.4",
|
||||
"@typescript-eslint/parser": "4.28.2",
|
||||
"@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.30.0",
|
||||
"eslint-plugin-github": "4.1.3",
|
||||
"eslint-plugin-jest": "24.3.6",
|
||||
"jest": "26.6.3",
|
||||
"jest-circus": "26.6.3",
|
||||
"js-yaml": "3.14.1",
|
||||
"prettier": "2.3.2",
|
||||
"ts-jest": "26.5.6",
|
||||
"typescript": "4.3.5"
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export function writeInitScript(): string {
|
||||
const tmpDir = process.env['RUNNER_TEMP'] || ''
|
||||
const initScript = path.resolve(tmpDir, 'build-scan-capture.init.gradle')
|
||||
core.info(`Writing init script: ${initScript}`)
|
||||
if (fs.existsSync(initScript)) {
|
||||
return initScript
|
||||
}
|
||||
fs.writeFileSync(
|
||||
initScript,
|
||||
`
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
// Don't run against the included builds (if the main build has any).
|
||||
def isTopLevelBuild = gradle.getParent() == null
|
||||
if (isTopLevelBuild) {
|
||||
def version = GradleVersion.current().baseVersion
|
||||
def atLeastGradle5 = version >= GradleVersion.version("5.0")
|
||||
def atLeastGradle6 = version >= GradleVersion.version("6.0")
|
||||
|
||||
if (atLeastGradle6) {
|
||||
settingsEvaluated { settings ->
|
||||
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
|
||||
registerCallbacks(settings.extensions["gradleEnterprise"], settings.rootProject.name)
|
||||
}
|
||||
}
|
||||
} else if (atLeastGradle5) {
|
||||
projectsEvaluated { gradle ->
|
||||
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
|
||||
registerCallbacks(gradle.rootProject.extensions["gradleEnterprise"], gradle.rootProject.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def registerCallbacks(gradleEnterprise, rootProjectName) {
|
||||
gradleEnterprise.with {
|
||||
buildScan {
|
||||
def scanFile = new File("gradle-build-scan.txt")
|
||||
buildScanPublished { buildScan ->
|
||||
scanFile.text = buildScan.buildScanUri
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
return initScript
|
||||
}
|
96
src/cache-configuration.ts
Normal file
96
src/cache-configuration.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
|
||||
import * as github from './github-utils'
|
||||
import * as crypto from './crypto-utils'
|
||||
|
||||
import {inputCacheKeyGlobs, tryDeleteFiles} from './cache-dependencies'
|
||||
|
||||
const CONFIGURATION_CACHE_PATH = 'CONFIGURATION_CACHE_PATH'
|
||||
const CONFIGURATION_CACHE_KEY = 'CONFIGURATION_CACHE_KEY'
|
||||
const CONFIGURATION_CACHE_RESULT = 'CONFIGURATION_CACHE_RESULT'
|
||||
|
||||
export async function restoreCachedConfiguration(
|
||||
rootDir: string
|
||||
): Promise<void> {
|
||||
if (isConfigurationCacheDisabled()) return
|
||||
|
||||
const cachePath = path.resolve(rootDir, '.gradle/configuration-cache')
|
||||
core.saveState(CONFIGURATION_CACHE_PATH, cachePath)
|
||||
|
||||
const inputCacheExact = github.inputBoolean('configuration-cache-exact')
|
||||
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
|
||||
|
||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const cacheKeyPrefix = 'configuration-'
|
||||
const cacheKey = `${cacheKeyPrefix}${hash}`
|
||||
core.saveState(CONFIGURATION_CACHE_KEY, cacheKey)
|
||||
|
||||
const cacheResult = await cache.restoreCache(
|
||||
[cachePath],
|
||||
cacheKey,
|
||||
inputCacheExact ? [] : [cacheKeyPrefix]
|
||||
)
|
||||
|
||||
if (!cacheResult) {
|
||||
core.info(
|
||||
'Configuration cache not found, expect task graph calculation.'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
core.saveState(CONFIGURATION_CACHE_RESULT, cacheResult)
|
||||
core.info(`Configuration restored from cache key: ${cacheResult}`)
|
||||
return
|
||||
}
|
||||
|
||||
export async function cacheConfiguration(): Promise<void> {
|
||||
if (isConfigurationCacheDisabled()) return
|
||||
|
||||
const cachePath = core.getState(CONFIGURATION_CACHE_PATH)
|
||||
const cacheKey = core.getState(CONFIGURATION_CACHE_KEY)
|
||||
const cacheResult = core.getState(CONFIGURATION_CACHE_RESULT)
|
||||
|
||||
if (!cachePath || !fs.existsSync(cachePath)) {
|
||||
core.debug('No configuration to cache.')
|
||||
return
|
||||
}
|
||||
|
||||
if (cacheResult && cacheKey === cacheResult) {
|
||||
core.info(
|
||||
`Configuration cache hit occurred on the cache key ${cacheKey}, not saving cache.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const locksDeleted = tryDeleteFiles([
|
||||
path.resolve(cachePath, 'configuration-cache.lock')
|
||||
])
|
||||
if (!locksDeleted) {
|
||||
core.warning(
|
||||
'Unable to delete configuration lock files, try using --no-daemon or stopping the daemon last if you have several Gradle steps, 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
|
||||
}
|
||||
|
||||
function isConfigurationCacheDisabled(): boolean {
|
||||
return !github.inputBoolean('configuration-cache-enabled', false)
|
||||
}
|
119
src/cache-dependencies.ts
Normal file
119
src/cache-dependencies.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
|
||||
import * as github from './github-utils'
|
||||
import * as crypto from './crypto-utils'
|
||||
|
||||
const DEPENDENCIES_CACHE_PATH = 'DEPENDENCIES_CACHE_PATH'
|
||||
const DEPENDENCIES_CACHE_KEY = 'DEPENDENCIES_CACHE_KEY'
|
||||
const DEPENDENCIES_CACHE_RESULT = 'DEPENDENCIES_CACHE_RESULT'
|
||||
|
||||
export async function restoreCachedDependencies(
|
||||
rootDir: string
|
||||
): Promise<void> {
|
||||
if (isDependenciesCacheDisabled()) return
|
||||
|
||||
const cachePath = path.resolve(os.homedir(), '.gradle/caches/modules-2')
|
||||
core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)
|
||||
|
||||
const inputCacheExact = github.inputBoolean('dependencies-cache-exact')
|
||||
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
|
||||
|
||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const cacheKeyPrefix = 'dependencies-'
|
||||
const cacheKey = `${cacheKeyPrefix}${hash}`
|
||||
core.saveState(DEPENDENCIES_CACHE_KEY, cacheKey)
|
||||
|
||||
const cacheResult = await cache.restoreCache(
|
||||
[cachePath],
|
||||
cacheKey,
|
||||
inputCacheExact ? [] : [cacheKeyPrefix]
|
||||
)
|
||||
|
||||
if (!cacheResult) {
|
||||
core.info('Dependencies cache not found, expect dependencies download.')
|
||||
return
|
||||
}
|
||||
|
||||
core.saveState(DEPENDENCIES_CACHE_RESULT, cacheResult)
|
||||
core.info(`Dependencies restored from cache key: ${cacheResult}`)
|
||||
return
|
||||
}
|
||||
|
||||
export async function cacheDependencies(): Promise<void> {
|
||||
if (isDependenciesCacheDisabled()) return
|
||||
|
||||
const cachePath = core.getState(DEPENDENCIES_CACHE_PATH)
|
||||
const cacheKey = core.getState(DEPENDENCIES_CACHE_KEY)
|
||||
const cacheResult = core.getState(DEPENDENCIES_CACHE_RESULT)
|
||||
|
||||
if (!cachePath || !fs.existsSync(cachePath)) {
|
||||
core.debug('No dependencies to cache.')
|
||||
return
|
||||
}
|
||||
|
||||
if (cacheResult && cacheKey === cacheResult) {
|
||||
core.info(
|
||||
`Dependencies cache hit occurred on the cache key ${cacheKey}, not saving cache.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const locksDeleted = tryDeleteFiles([
|
||||
path.resolve(cachePath, 'modules-2.lock')
|
||||
])
|
||||
if (!locksDeleted) {
|
||||
core.warning(
|
||||
'Unable to delete dependencies lock files, try using --no-daemon or stopping the daemon last if you have several Gradle steps, 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 tryDeleteFiles(filePaths: string[]): boolean {
|
||||
let failure = false
|
||||
for (const filePath of filePaths) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
try {
|
||||
fs.unlinkSync(filePath)
|
||||
} catch (error) {
|
||||
failure = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return !failure
|
||||
}
|
||||
|
||||
function isDependenciesCacheDisabled(): boolean {
|
||||
return !github.inputBoolean('dependencies-cache-enabled', false)
|
||||
}
|
||||
|
||||
export function inputCacheKeyGlobs(input: string): string[] {
|
||||
const inputValue = github.inputArrayOrNull(input)
|
||||
return inputValue
|
||||
? inputValue
|
||||
: [
|
||||
'**/*.gradle',
|
||||
'**/*.gradle.kts',
|
||||
'**/gradle.properties',
|
||||
'gradle/**'
|
||||
]
|
||||
}
|
@@ -1,208 +0,0 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import os from 'os'
|
||||
import * as core from '@actions/core'
|
||||
import * as glob from '@actions/glob'
|
||||
import * as exec from '@actions/exec'
|
||||
|
||||
import {AbstractCache, hashFileNames} from './cache-utils'
|
||||
|
||||
// Which paths under Gradle User Home should be cached
|
||||
const CACHE_PATH = ['caches', 'notifications']
|
||||
|
||||
const COMMON_ARTIFACT_CACHES = new Map([
|
||||
['generated-gradle-jars', 'caches/*/generated-gradle-jars/*.jar'],
|
||||
['wrapper-zips', 'wrapper/dists/*/*/*.zip'],
|
||||
['dependency-jars', 'caches/modules-*/files-*/**/*.jar'],
|
||||
['instrumented-jars', 'caches/jars-*/*/*.jar']
|
||||
])
|
||||
|
||||
export class GradleUserHomeCache extends AbstractCache {
|
||||
private gradleUserHome: string
|
||||
|
||||
constructor(rootDir: string) {
|
||||
super('gradle', 'Gradle User Home')
|
||||
this.gradleUserHome = this.determineGradleUserHome(rootDir)
|
||||
}
|
||||
|
||||
async afterRestore(): Promise<void> {
|
||||
await this.reportCacheEntrySize('as restored from cache')
|
||||
await this.restoreCommonArtifacts()
|
||||
await this.reportCacheEntrySize('after restoring common artifacts')
|
||||
}
|
||||
|
||||
private async restoreCommonArtifacts(): Promise<void> {
|
||||
const processes: Promise<void>[] = []
|
||||
for (const [bundle, pattern] of this.getCommonArtifactPaths()) {
|
||||
const p = this.restoreCommonArtifactBundle(bundle, pattern)
|
||||
// Run sequentially when debugging enabled
|
||||
if (this.cacheDebuggingEnabled) {
|
||||
await p
|
||||
}
|
||||
processes.push(p)
|
||||
}
|
||||
|
||||
await Promise.all(processes)
|
||||
}
|
||||
|
||||
private async restoreCommonArtifactBundle(
|
||||
bundle: string,
|
||||
artifactPath: string
|
||||
): Promise<void> {
|
||||
const cacheMetaFile = this.getCacheMetaFile(bundle)
|
||||
if (fs.existsSync(cacheMetaFile)) {
|
||||
const cacheKey = fs.readFileSync(cacheMetaFile, 'utf-8').trim()
|
||||
const restoreKey = await this.restoreCache([artifactPath], cacheKey)
|
||||
if (restoreKey) {
|
||||
core.info(
|
||||
`Restored ${bundle} with key ${cacheKey} to ${artifactPath}`
|
||||
)
|
||||
} else {
|
||||
this.debug(
|
||||
`Failed to restore ${bundle} with key ${cacheKey} to ${artifactPath}`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
this.debug(
|
||||
`No metafile found to restore ${bundle}: ${cacheMetaFile}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private getCacheMetaFile(name: string): string {
|
||||
return path.resolve(
|
||||
this.gradleUserHome,
|
||||
'caches',
|
||||
`.gradle-build-action.${name}.cache`
|
||||
)
|
||||
}
|
||||
|
||||
private async reportCacheEntrySize(label: string): Promise<void> {
|
||||
if (!this.cacheDebuggingEnabled) {
|
||||
return
|
||||
}
|
||||
if (!fs.existsSync(this.gradleUserHome)) {
|
||||
return
|
||||
}
|
||||
const result = await exec.getExecOutput(
|
||||
'du',
|
||||
['-h', '-c', '-t', '5M'],
|
||||
{
|
||||
cwd: this.gradleUserHome,
|
||||
silent: true,
|
||||
ignoreReturnCode: true
|
||||
}
|
||||
)
|
||||
|
||||
core.info(`Gradle User Home cache entry (directories >5M): ${label}`)
|
||||
|
||||
core.info(
|
||||
result.stdout
|
||||
.trimEnd()
|
||||
.replace(/\t/g, ' ')
|
||||
.split('\n')
|
||||
.map(it => {
|
||||
return ` ${it}`
|
||||
})
|
||||
.join('\n')
|
||||
)
|
||||
|
||||
core.info('-----------------------')
|
||||
}
|
||||
|
||||
async beforeSave(): Promise<void> {
|
||||
await this.saveCommonArtifacts()
|
||||
}
|
||||
|
||||
private async saveCommonArtifacts(): Promise<void> {
|
||||
const processes: Promise<void>[] = []
|
||||
for (const [bundle, pattern] of this.getCommonArtifactPaths()) {
|
||||
const p = this.saveCommonArtifactBundle(bundle, pattern)
|
||||
// Run sequentially when debugging enabled
|
||||
if (this.cacheDebuggingEnabled) {
|
||||
await p
|
||||
}
|
||||
processes.push(p)
|
||||
}
|
||||
|
||||
await Promise.all(processes)
|
||||
}
|
||||
|
||||
private async saveCommonArtifactBundle(
|
||||
bundle: string,
|
||||
artifactPath: string
|
||||
): Promise<void> {
|
||||
const cacheMetaFile = this.getCacheMetaFile(bundle)
|
||||
|
||||
const globber = await glob.create(artifactPath)
|
||||
const commonArtifactFiles = await globber.glob()
|
||||
|
||||
// Handle no matching files
|
||||
if (commonArtifactFiles.length === 0) {
|
||||
this.debug(`No files found to cache for ${bundle}`)
|
||||
if (fs.existsSync(cacheMetaFile)) {
|
||||
fs.unlinkSync(cacheMetaFile)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const previouslyRestoredKey = fs.existsSync(cacheMetaFile)
|
||||
? fs.readFileSync(cacheMetaFile, 'utf-8').trim()
|
||||
: ''
|
||||
const cacheKey = this.createCacheKey(bundle, commonArtifactFiles)
|
||||
|
||||
if (previouslyRestoredKey === cacheKey) {
|
||||
this.debug(
|
||||
`No change to previously restored ${bundle}. Not caching.`
|
||||
)
|
||||
} else {
|
||||
core.info(`Caching ${bundle} with cache key: ${cacheKey}`)
|
||||
await this.saveCache([artifactPath], cacheKey)
|
||||
|
||||
this.debug(`Writing cache metafile: ${cacheMetaFile}`)
|
||||
fs.writeFileSync(cacheMetaFile, cacheKey)
|
||||
}
|
||||
|
||||
for (const file of commonArtifactFiles) {
|
||||
fs.unlinkSync(file)
|
||||
}
|
||||
}
|
||||
|
||||
protected createCacheKey(bundle: string, files: string[]): string {
|
||||
const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || ''
|
||||
const relativeFiles = files.map(x =>
|
||||
path.relative(this.gradleUserHome, x)
|
||||
)
|
||||
const key = hashFileNames(relativeFiles)
|
||||
|
||||
return `${cacheKeyPrefix}${bundle}-${key}`
|
||||
}
|
||||
|
||||
protected determineGradleUserHome(rootDir: string): string {
|
||||
const customGradleUserHome = process.env['GRADLE_USER_HOME']
|
||||
if (customGradleUserHome) {
|
||||
return path.resolve(rootDir, customGradleUserHome)
|
||||
}
|
||||
|
||||
return path.resolve(os.homedir(), '.gradle')
|
||||
}
|
||||
|
||||
protected cacheOutputExists(): boolean {
|
||||
// Need to check for 'caches' directory to avoid incorrect detection on MacOS agents
|
||||
const dir = path.resolve(this.gradleUserHome, 'caches')
|
||||
return fs.existsSync(dir)
|
||||
}
|
||||
|
||||
protected getCachePath(): string[] {
|
||||
return CACHE_PATH.map(x => path.resolve(this.gradleUserHome, x))
|
||||
}
|
||||
|
||||
private getCommonArtifactPaths(): Map<string, string> {
|
||||
return new Map(
|
||||
Array.from(COMMON_ARTIFACT_CACHES, ([key, value]) => [
|
||||
key,
|
||||
path.resolve(this.gradleUserHome, value)
|
||||
])
|
||||
)
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import {AbstractCache} from './cache-utils'
|
||||
|
||||
// TODO: Maybe allow the user to override / tweak this set
|
||||
const PATHS_TO_CACHE = [
|
||||
'configuration-cache' // Only configuration-cache is stored at present
|
||||
]
|
||||
|
||||
export class ProjectDotGradleCache extends AbstractCache {
|
||||
private rootDir: string
|
||||
constructor(rootDir: string) {
|
||||
super('project', 'Project .gradle directory')
|
||||
this.rootDir = rootDir
|
||||
}
|
||||
|
||||
protected cacheOutputExists(): boolean {
|
||||
const dir = this.getProjectDotGradleDir()
|
||||
return fs.existsSync(dir)
|
||||
}
|
||||
|
||||
protected getCachePath(): string[] {
|
||||
const dir = this.getProjectDotGradleDir()
|
||||
return PATHS_TO_CACHE.map(x => path.resolve(dir, x))
|
||||
}
|
||||
|
||||
private getProjectDotGradleDir(): string {
|
||||
return path.resolve(this.rootDir, '.gradle')
|
||||
}
|
||||
}
|
@@ -1,215 +0,0 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import * as github from '@actions/github'
|
||||
import * as crypto from 'crypto'
|
||||
import * as path from 'path'
|
||||
|
||||
export function isCacheDisabled(): boolean {
|
||||
return core.getBooleanInput('cache-disabled')
|
||||
}
|
||||
|
||||
export function isCacheReadOnly(): boolean {
|
||||
return core.getBooleanInput('cache-read-only')
|
||||
}
|
||||
|
||||
export function isCacheDebuggingEnabled(): boolean {
|
||||
return process.env['CACHE_DEBUG_ENABLED'] ? true : false
|
||||
}
|
||||
|
||||
function generateCacheKey(cacheName: string): CacheKey {
|
||||
// Prefix can be used to force change all cache keys
|
||||
const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || ''
|
||||
|
||||
// At the most general level, share caches for all executions on the same OS
|
||||
const runnerOs = process.env['RUNNER_OS'] || ''
|
||||
const cacheKeyForOs = `${cacheKeyPrefix}${cacheName}|${runnerOs}`
|
||||
|
||||
// Prefer caches that run this job
|
||||
const cacheKeyForJob = `${cacheKeyForOs}|${github.context.job}`
|
||||
|
||||
// Prefer (even more) jobs that run this job with the same context (matrix)
|
||||
const cacheKeyForJobContext = `${cacheKeyForJob}[${determineJobContext()}]`
|
||||
|
||||
// Exact match on Git SHA
|
||||
const cacheKey = `${cacheKeyForJobContext}-${github.context.sha}`
|
||||
|
||||
return new CacheKey(cacheKey, [
|
||||
cacheKeyForJobContext,
|
||||
cacheKeyForJob,
|
||||
cacheKeyForOs
|
||||
])
|
||||
}
|
||||
|
||||
function determineJobContext(): string {
|
||||
// By default, we hash the full `matrix` data for the run, to uniquely identify this job invocation
|
||||
const workflowJobContext = core.getInput('workflow-job-context')
|
||||
return hashStrings([workflowJobContext])
|
||||
}
|
||||
|
||||
export function hashStrings(values: string[]): string {
|
||||
const hash = crypto.createHash('md5')
|
||||
for (const value of values) {
|
||||
hash.update(value)
|
||||
}
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
export function hashFileNames(fileNames: string[]): string {
|
||||
return hashStrings(
|
||||
fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/'))
|
||||
)
|
||||
}
|
||||
|
||||
class CacheKey {
|
||||
key: string
|
||||
restoreKeys: string[]
|
||||
|
||||
constructor(key: string, restoreKeys: string[]) {
|
||||
this.key = key
|
||||
this.restoreKeys = restoreKeys
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class AbstractCache {
|
||||
private cacheName: string
|
||||
private cacheDescription: string
|
||||
private cacheKeyStateKey: string
|
||||
private cacheResultStateKey: string
|
||||
|
||||
protected readonly cacheDebuggingEnabled: boolean
|
||||
|
||||
constructor(cacheName: string, cacheDescription: string) {
|
||||
this.cacheName = cacheName
|
||||
this.cacheDescription = cacheDescription
|
||||
this.cacheKeyStateKey = `CACHE_KEY_${cacheName}`
|
||||
this.cacheResultStateKey = `CACHE_RESULT_${cacheName}`
|
||||
this.cacheDebuggingEnabled = isCacheDebuggingEnabled()
|
||||
}
|
||||
|
||||
async restore(): Promise<void> {
|
||||
if (this.cacheOutputExists()) {
|
||||
core.info(
|
||||
`${this.cacheDescription} already exists. Not restoring from cache.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const cacheKey = generateCacheKey(this.cacheName)
|
||||
|
||||
core.saveState(this.cacheKeyStateKey, cacheKey.key)
|
||||
|
||||
const cacheResult = await this.restoreCache(
|
||||
this.getCachePath(),
|
||||
cacheKey.key,
|
||||
cacheKey.restoreKeys
|
||||
)
|
||||
|
||||
if (!cacheResult) {
|
||||
core.info(
|
||||
`${this.cacheDescription} cache not found. Will start with empty.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
core.saveState(this.cacheResultStateKey, cacheResult)
|
||||
|
||||
core.info(
|
||||
`Restored ${this.cacheDescription} from cache key: ${cacheResult}`
|
||||
)
|
||||
|
||||
await this.afterRestore()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
protected async restoreCache(
|
||||
cachePath: string[],
|
||||
cacheKey: string,
|
||||
cacheRestoreKeys: string[] = []
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
return await cache.restoreCache(
|
||||
cachePath,
|
||||
cacheKey,
|
||||
cacheRestoreKeys
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof cache.ValidationError) {
|
||||
// Validation errors should fail the build action
|
||||
throw error
|
||||
}
|
||||
// Warn about any other error and continue
|
||||
core.warning(`Failed to restore ${cacheKey}: ${error}`)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
protected async afterRestore(): Promise<void> {}
|
||||
|
||||
async save(): Promise<void> {
|
||||
if (!this.cacheOutputExists()) {
|
||||
this.debug(`No ${this.cacheDescription} to cache.`)
|
||||
return
|
||||
}
|
||||
|
||||
const cacheKey = core.getState(this.cacheKeyStateKey)
|
||||
const cacheResult = core.getState(this.cacheResultStateKey)
|
||||
|
||||
if (!cacheKey) {
|
||||
this.debug(
|
||||
`${this.cacheDescription} existed prior to cache restore. Not saving.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (cacheResult && cacheKey === cacheResult) {
|
||||
core.info(
|
||||
`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
await this.beforeSave()
|
||||
|
||||
core.info(
|
||||
`Caching ${this.cacheDescription} with cache key: ${cacheKey}`
|
||||
)
|
||||
const cachePath = this.getCachePath()
|
||||
await this.saveCache(cachePath, cacheKey)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
protected async beforeSave(): Promise<void> {}
|
||||
|
||||
protected async saveCache(
|
||||
cachePath: string[],
|
||||
cacheKey: string
|
||||
): Promise<void> {
|
||||
try {
|
||||
await cache.saveCache(cachePath, cacheKey)
|
||||
} catch (error) {
|
||||
if (error instanceof cache.ValidationError) {
|
||||
// Validation errors should fail the build action
|
||||
throw error
|
||||
} else if (error instanceof cache.ReserveCacheError) {
|
||||
// Reserve cache errors are expected if the artifact has been previously cached
|
||||
this.debug(error.message)
|
||||
} else {
|
||||
// Warn about any other error and continue
|
||||
core.warning(String(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected debug(message: string): void {
|
||||
if (this.cacheDebuggingEnabled) {
|
||||
core.info(message)
|
||||
} else {
|
||||
core.debug(message)
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract cacheOutputExists(): boolean
|
||||
protected abstract getCachePath(): string[]
|
||||
}
|
110
src/cache-wrapper.ts
Normal file
110
src/cache-wrapper.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
|
||||
import * as github from './github-utils'
|
||||
|
||||
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(
|
||||
gradlewDirectory: string | null
|
||||
): Promise<void> {
|
||||
if (isWrapperCacheDisabled()) return
|
||||
if (gradlewDirectory == null) return
|
||||
|
||||
const wrapperSlug = extractGradleWrapperSlugFrom(
|
||||
path.join(
|
||||
path.resolve(gradlewDirectory),
|
||||
'gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
)
|
||||
if (!wrapperSlug) return
|
||||
|
||||
const wrapperCacheKey = `wrapper-${wrapperSlug}`
|
||||
const wrapperCachePath = path.join(
|
||||
os.homedir(),
|
||||
`.gradle/wrapper/dists/gradle-${wrapperSlug}`
|
||||
)
|
||||
if (fs.existsSync(wrapperCachePath)) return
|
||||
|
||||
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> {
|
||||
if (isWrapperCacheDisabled()) return
|
||||
|
||||
const cacheKey = core.getState(WRAPPER_CACHE_KEY)
|
||||
const cachePath = core.getState(WRAPPER_CACHE_PATH)
|
||||
const cacheResult = core.getState(WRAPPER_CACHE_RESULT)
|
||||
|
||||
if (!cachePath || !fs.existsSync(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
|
||||
}
|
||||
|
||||
function isWrapperCacheDisabled(): boolean {
|
||||
return !github.inputBoolean('wrapper-cache-enabled', true)
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
import {GradleUserHomeCache} from './cache-gradle-user-home'
|
||||
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
|
||||
import * as core from '@actions/core'
|
||||
import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
|
||||
|
||||
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
|
||||
|
||||
export async function restore(buildRootDirectory: string): Promise<void> {
|
||||
if (isCacheDisabled()) {
|
||||
core.debug('Cache read disabled')
|
||||
return
|
||||
}
|
||||
|
||||
await core.group('Restore Gradle state from cache', async () => {
|
||||
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
|
||||
return Promise.all([
|
||||
new GradleUserHomeCache(buildRootDirectory).restore(),
|
||||
new ProjectDotGradleCache(buildRootDirectory).restore()
|
||||
])
|
||||
})
|
||||
}
|
||||
|
||||
export async function save(): Promise<void> {
|
||||
if (isCacheReadOnly()) {
|
||||
core.debug('Cache is read-only: not saving cache entry')
|
||||
return
|
||||
}
|
||||
|
||||
await core.group('Caching Gradle state', async () => {
|
||||
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
|
||||
return Promise.all([
|
||||
new GradleUserHomeCache(buildRootDirectory).save(),
|
||||
new ProjectDotGradleCache(buildRootDirectory).save()
|
||||
])
|
||||
})
|
||||
}
|
44
src/crypto-utils.ts
Normal file
44
src/crypto-utils.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as crypto from 'crypto'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as stream from 'stream'
|
||||
import * as util from 'util'
|
||||
|
||||
import * as glob from '@actions/glob'
|
||||
|
||||
export async function hashFiles(
|
||||
baseDir: string,
|
||||
globs: string[] = ['**'],
|
||||
followSymbolicLinks = false
|
||||
): Promise<string | null> {
|
||||
let hasMatch = false
|
||||
type FileHashes = Record<string, Buffer>
|
||||
const hashes: FileHashes = {}
|
||||
for await (const globPattern of globs) {
|
||||
const globMatch = `${baseDir}${path.sep}${globPattern}`
|
||||
const globber = await glob.create(globMatch, {followSymbolicLinks})
|
||||
for await (const file of globber.globGenerator()) {
|
||||
// console.log(file)
|
||||
if (!file.startsWith(`${baseDir}${path.sep}`)) {
|
||||
// console.log(`Ignore '${file}' since it is not under '${baseDir}'.`)
|
||||
continue
|
||||
}
|
||||
if (fs.statSync(file).isDirectory()) {
|
||||
// console.log(`Skip directory '${file}'.`)
|
||||
continue
|
||||
}
|
||||
const hash = crypto.createHash('sha256')
|
||||
const pipeline = util.promisify(stream.pipeline)
|
||||
await pipeline(fs.createReadStream(file), hash)
|
||||
hashes[path.relative(baseDir, file)] = hash.digest()
|
||||
hasMatch = true
|
||||
}
|
||||
}
|
||||
if (!hasMatch) return null
|
||||
const result = crypto.createHash('sha256')
|
||||
for (const file of Object.keys(hashes).sort()) {
|
||||
result.update(hashes[file])
|
||||
}
|
||||
result.end()
|
||||
return result.digest('hex')
|
||||
}
|
@@ -1,36 +1,37 @@
|
||||
import * as exec from '@actions/exec'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {writeInitScript} from './build-scan-capture'
|
||||
import * as cacheDependencies from './cache-dependencies'
|
||||
import * as cacheConfiguration from './cache-configuration'
|
||||
|
||||
export async function execute(
|
||||
executable: string,
|
||||
root: string,
|
||||
args: string[]
|
||||
argv: string[]
|
||||
): Promise<BuildResult> {
|
||||
await cacheDependencies.restoreCachedDependencies(root)
|
||||
await cacheConfiguration.restoreCachedConfiguration(root)
|
||||
|
||||
let publishing = false
|
||||
let buildScanUrl: string | undefined
|
||||
|
||||
// TODO: instead of running with no-daemon, run `--stop` in post action.
|
||||
args.push('--no-daemon')
|
||||
|
||||
const initScript = writeInitScript()
|
||||
args.push('--init-script')
|
||||
args.push(initScript)
|
||||
|
||||
const buildScanFile = path.resolve(root, 'gradle-build-scan.txt')
|
||||
if (fs.existsSync(buildScanFile)) {
|
||||
fs.unlinkSync(buildScanFile)
|
||||
}
|
||||
|
||||
const status: number = await exec.exec(executable, args, {
|
||||
const status: number = await exec.exec(executable, argv, {
|
||||
cwd: root,
|
||||
ignoreReturnCode: true
|
||||
ignoreReturnCode: true,
|
||||
listeners: {
|
||||
stdline: (line: string) => {
|
||||
if (line.startsWith('Publishing build scan...')) {
|
||||
publishing = true
|
||||
}
|
||||
if (publishing && line.length === 0) {
|
||||
publishing = false
|
||||
}
|
||||
if (publishing && line.startsWith('http')) {
|
||||
buildScanUrl = line.trim()
|
||||
publishing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (fs.existsSync(buildScanFile)) {
|
||||
buildScanUrl = fs.readFileSync(buildScanFile, 'utf-8')
|
||||
}
|
||||
|
||||
return new BuildResultImpl(status, buildScanUrl)
|
||||
}
|
||||
|
||||
|
24
src/github-utils.ts
Normal file
24
src/github-utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export function inputOrNull(name: string): string | null {
|
||||
const inputString = core.getInput(name, {required: false})
|
||||
if (inputString.length === 0) {
|
||||
return null
|
||||
}
|
||||
return inputString
|
||||
}
|
||||
|
||||
export function inputArrayOrNull(name: string): string[] | null {
|
||||
const string = inputOrNull(name)
|
||||
if (!string) return null
|
||||
return string
|
||||
.split('\n')
|
||||
.map(s => s.trim())
|
||||
.filter(s => s !== '')
|
||||
}
|
||||
|
||||
export function inputBoolean(name: string, defaultValue = false): boolean {
|
||||
const string = inputOrNull(name)
|
||||
if (!string) return defaultValue
|
||||
return string === 'true'
|
||||
}
|
@@ -1,29 +1,9 @@
|
||||
import * as path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
|
||||
export function wrapperScriptFilename(): string {
|
||||
export function wrapperFilename(): string {
|
||||
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
|
||||
}
|
||||
|
||||
export function installScriptFilename(): string {
|
||||
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
||||
}
|
||||
|
||||
export function locateGradleWrapperScript(buildRootDirectory: string): string {
|
||||
validateGradleWrapper(buildRootDirectory)
|
||||
return path.resolve(buildRootDirectory, wrapperScriptFilename())
|
||||
}
|
||||
|
||||
function validateGradleWrapper(buildRootDirectory: string): void {
|
||||
const wrapperProperties = path.resolve(
|
||||
buildRootDirectory,
|
||||
'gradle/wrapper/gradle-wrapper.properties'
|
||||
)
|
||||
if (!fs.existsSync(wrapperProperties)) {
|
||||
throw new Error(
|
||||
`Cannot locate a Gradle wrapper properties file at '${wrapperProperties}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
65
src/main.ts
65
src/main.ts
@@ -2,7 +2,8 @@ import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import {parseArgsStringToArgv} from 'string-argv'
|
||||
|
||||
import * as caches from './caches'
|
||||
import * as github from './github-utils'
|
||||
import * as cacheWrapper from './cache-wrapper'
|
||||
import * as execution from './execution'
|
||||
import * as gradlew from './gradlew'
|
||||
import * as provision from './provision'
|
||||
@@ -10,69 +11,65 @@ import * as provision from './provision'
|
||||
// Invoked by GitHub Actions
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
||||
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
||||
|
||||
await caches.restore(buildRootDirectory)
|
||||
|
||||
const args: string[] = parseCommandLineArguments()
|
||||
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
||||
|
||||
const result = await execution.execute(
|
||||
await resolveGradleExecutable(
|
||||
workspaceDirectory,
|
||||
buildRootDirectory
|
||||
),
|
||||
buildRootDirectory,
|
||||
args
|
||||
await resolveGradleExecutable(baseDirectory),
|
||||
resolveBuildRootDirectory(baseDirectory),
|
||||
parseCommandLineArguments()
|
||||
)
|
||||
|
||||
if (result.buildScanUrl) {
|
||||
core.setOutput('build-scan-url', result.buildScanUrl)
|
||||
// TODO Include context about the invocation (eg step name) in this message
|
||||
// Unfortunately it doesn't seem possible to access the current step name here
|
||||
core.notice(`Gradle build scan: ${result.buildScanUrl}`)
|
||||
}
|
||||
|
||||
if (result.status !== 0) {
|
||||
core.setFailed(`Gradle process exited with status ${result.status}`)
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(String(error))
|
||||
if (error instanceof Error && error.stack) {
|
||||
core.info(error.stack)
|
||||
}
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
async function resolveGradleExecutable(
|
||||
workspaceDirectory: string,
|
||||
buildRootDirectory: string
|
||||
): Promise<string> {
|
||||
const gradleVersion = core.getInput('gradle-version')
|
||||
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
|
||||
async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
||||
const gradleVersion = github.inputOrNull('gradle-version')
|
||||
if (gradleVersion !== null && gradleVersion !== 'wrapper') {
|
||||
return path.resolve(await provision.gradleVersion(gradleVersion))
|
||||
}
|
||||
|
||||
const gradleExecutable = core.getInput('gradle-executable')
|
||||
if (gradleExecutable !== '') {
|
||||
return path.resolve(workspaceDirectory, gradleExecutable)
|
||||
const gradleExecutable = github.inputOrNull('gradle-executable')
|
||||
if (gradleExecutable !== null) {
|
||||
if (gradleExecutable.endsWith(gradlew.wrapperFilename())) {
|
||||
await cacheWrapper.restoreCachedWrapperDist(
|
||||
path.resolve(gradleExecutable, '..')
|
||||
)
|
||||
}
|
||||
return path.resolve(baseDirectory, gradleExecutable)
|
||||
}
|
||||
|
||||
return gradlew.locateGradleWrapperScript(buildRootDirectory)
|
||||
const wrapperDirectory = github.inputOrNull('wrapper-directory')
|
||||
const gradlewDirectory =
|
||||
wrapperDirectory !== null
|
||||
? path.join(baseDirectory, wrapperDirectory)
|
||||
: baseDirectory
|
||||
|
||||
await cacheWrapper.restoreCachedWrapperDist(gradlewDirectory)
|
||||
|
||||
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
|
||||
}
|
||||
|
||||
function resolveBuildRootDirectory(baseDirectory: string): string {
|
||||
const buildRootDirectory = core.getInput('build-root-directory')
|
||||
const buildRootDirectory = github.inputOrNull('build-root-directory')
|
||||
const resolvedBuildRootDirectory =
|
||||
buildRootDirectory === ''
|
||||
buildRootDirectory === null
|
||||
? path.resolve(baseDirectory)
|
||||
: path.resolve(baseDirectory, buildRootDirectory)
|
||||
return resolvedBuildRootDirectory
|
||||
}
|
||||
|
||||
function parseCommandLineArguments(): string[] {
|
||||
const input = core.getInput('arguments')
|
||||
return parseArgsStringToArgv(input)
|
||||
const input = github.inputOrNull('arguments')
|
||||
return input === null ? [] : parseArgsStringToArgv(input)
|
||||
}
|
||||
|
16
src/post.ts
16
src/post.ts
@@ -1,16 +1,12 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as caches from './caches'
|
||||
import * as cacheWrapper from './cache-wrapper'
|
||||
import * as cacheDependencies from './cache-dependencies'
|
||||
import * as cacheConfiguration from './cache-configuration'
|
||||
|
||||
// Invoked by GitHub Actions
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
await caches.save()
|
||||
} catch (error) {
|
||||
core.setFailed(String(error))
|
||||
if (error instanceof Error && error.stack) {
|
||||
core.info(error.stack)
|
||||
}
|
||||
}
|
||||
await cacheWrapper.cacheWrapperDist()
|
||||
await cacheDependencies.cacheDependencies()
|
||||
await cacheConfiguration.cacheConfiguration()
|
||||
}
|
||||
|
||||
run()
|
||||
|
156
src/provision.ts
156
src/provision.ts
@@ -1,14 +1,15 @@
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as httpm from '@actions/http-client'
|
||||
import * as httpm from 'typed-rest-client/HttpClient'
|
||||
import * as unzip from 'unzipper'
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import * as io from '@actions/io'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
|
||||
import * as gradlew from './gradlew'
|
||||
import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
|
||||
|
||||
const httpc = new httpm.HttpClient('eskatos/gradle-command-action')
|
||||
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||
|
||||
/**
|
||||
@@ -19,11 +20,6 @@ export async function gradleVersion(version: string): Promise<string> {
|
||||
case 'current':
|
||||
return gradleCurrent()
|
||||
case 'rc':
|
||||
core.warning(
|
||||
`Specifying gradle-version 'rc' has been deprecated. Use 'release-candidate' instead.`
|
||||
)
|
||||
return gradleReleaseCandidate()
|
||||
case 'release-candidate':
|
||||
return gradleReleaseCandidate()
|
||||
case 'nightly':
|
||||
return gradleNightly()
|
||||
@@ -38,17 +34,16 @@ async function gradleCurrent(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/current`
|
||||
)
|
||||
return provisionGradle(versionInfo)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
async function gradleReleaseCandidate(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/release-candidate`
|
||||
)
|
||||
if (versionInfo && versionInfo.version && versionInfo.downloadUrl) {
|
||||
return provisionGradle(versionInfo)
|
||||
if (versionInfo) {
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
core.info('No current release-candidate found, will fallback to current')
|
||||
return gradleCurrent()
|
||||
}
|
||||
|
||||
@@ -56,14 +51,14 @@ async function gradleNightly(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/nightly`
|
||||
)
|
||||
return provisionGradle(versionInfo)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
async function gradleReleaseNightly(): Promise<string> {
|
||||
const versionInfo = await gradleVersionDeclaration(
|
||||
`${gradleVersionsBaseUrl}/release-nightly`
|
||||
)
|
||||
return provisionGradle(versionInfo)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
async function gradle(version: string): Promise<string> {
|
||||
@@ -71,7 +66,7 @@ async function gradle(version: string): Promise<string> {
|
||||
if (!versionInfo) {
|
||||
throw new Error(`Gradle version ${version} does not exists`)
|
||||
}
|
||||
return provisionGradle(versionInfo)
|
||||
return provisionGradle(versionInfo.version, versionInfo.downloadUrl)
|
||||
}
|
||||
|
||||
async function gradleVersionDeclaration(
|
||||
@@ -91,90 +86,42 @@ async function findGradleVersionDeclaration(
|
||||
})
|
||||
}
|
||||
|
||||
async function provisionGradle(
|
||||
versionInfo: GradleVersionInfo
|
||||
): Promise<string> {
|
||||
return core.group(`Provision Gradle ${versionInfo.version}`, async () => {
|
||||
return locateGradleAndDownloadIfRequired(versionInfo)
|
||||
})
|
||||
}
|
||||
|
||||
async function locateGradleAndDownloadIfRequired(
|
||||
versionInfo: GradleVersionInfo
|
||||
): Promise<string> {
|
||||
const installsDir = path.join(os.homedir(), 'gradle-installations/installs')
|
||||
const installDir = path.join(installsDir, `gradle-${versionInfo.version}`)
|
||||
if (fs.existsSync(installDir)) {
|
||||
core.info(`Gradle installation already exists at ${installDir}`)
|
||||
return executableFrom(installDir)
|
||||
async function provisionGradle(version: string, url: string): Promise<string> {
|
||||
const cachedInstall: string = toolCache.find('gradle', version)
|
||||
if (cachedInstall.length > 0) {
|
||||
const cachedExecutable = executableFrom(cachedInstall)
|
||||
core.info(`Provisioned Gradle executable ${cachedExecutable}`)
|
||||
return cachedExecutable
|
||||
}
|
||||
|
||||
const downloadPath = await downloadAndCacheGradleDistribution(versionInfo)
|
||||
await toolCache.extractZip(downloadPath, installsDir)
|
||||
core.info(`Extracted Gradle ${versionInfo.version} to ${installDir}`)
|
||||
const home = os.homedir()
|
||||
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}`)
|
||||
|
||||
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}`)
|
||||
|
||||
const executable = executableFrom(installDir)
|
||||
fs.chmodSync(executable, '755')
|
||||
core.info(`Provisioned Gradle executable ${executable}`)
|
||||
|
||||
toolCache.cacheDir(installDir, 'gradle', version)
|
||||
|
||||
return executable
|
||||
}
|
||||
|
||||
async function downloadAndCacheGradleDistribution(
|
||||
versionInfo: GradleVersionInfo
|
||||
): Promise<string> {
|
||||
const downloadPath = path.join(
|
||||
os.homedir(),
|
||||
`gradle-installations/downloads/gradle-${versionInfo.version}-bin.zip`
|
||||
)
|
||||
|
||||
if (isCacheDisabled()) {
|
||||
await downloadGradleDistribution(versionInfo, downloadPath)
|
||||
return downloadPath
|
||||
}
|
||||
|
||||
const cacheKey = `gradle-${versionInfo.version}`
|
||||
const restoreKey = await cache.restoreCache([downloadPath], cacheKey)
|
||||
if (restoreKey) {
|
||||
core.info(
|
||||
`Restored Gradle distribution ${cacheKey} from cache to ${downloadPath}`
|
||||
)
|
||||
return downloadPath
|
||||
}
|
||||
core.info(
|
||||
`Gradle distribution ${versionInfo.version} not found in cache. Will download.`
|
||||
)
|
||||
await downloadGradleDistribution(versionInfo, downloadPath)
|
||||
|
||||
if (!isCacheReadOnly()) {
|
||||
try {
|
||||
await cache.saveCache([downloadPath], cacheKey)
|
||||
} catch (error) {
|
||||
// Fail on validation errors or non-errors (the latter to keep Typescript happy)
|
||||
if (
|
||||
error instanceof cache.ValidationError ||
|
||||
!(error instanceof Error)
|
||||
) {
|
||||
throw error
|
||||
}
|
||||
core.warning(error.message)
|
||||
}
|
||||
}
|
||||
return downloadPath
|
||||
}
|
||||
|
||||
async function downloadGradleDistribution(
|
||||
versionInfo: GradleVersionInfo,
|
||||
downloadPath: string
|
||||
): Promise<void> {
|
||||
await toolCache.downloadTool(versionInfo.downloadUrl, downloadPath)
|
||||
core.info(
|
||||
`Downloaded ${versionInfo.downloadUrl} to ${downloadPath} (size ${
|
||||
fs.statSync(downloadPath).size
|
||||
})`
|
||||
)
|
||||
}
|
||||
|
||||
function executableFrom(installDir: string): string {
|
||||
return path.join(installDir, 'bin', `${gradlew.installScriptFilename()}`)
|
||||
}
|
||||
@@ -190,11 +137,38 @@ async function httpGetGradleVersions(
|
||||
}
|
||||
|
||||
async function httpGetString(url: string): Promise<string> {
|
||||
const httpClient = new httpm.HttpClient('gradle/gradle-build-action')
|
||||
const response = await httpClient.get(url)
|
||||
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(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()
|
||||
})
|
||||
.on('error', err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
interface GradleVersionInfo {
|
||||
version: string
|
||||
downloadUrl: string
|
||||
|
Reference in New Issue
Block a user