Skip to content

Commit

Permalink
Merge branch 'master' into releases/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
eskatos committed Jun 15, 2020
2 parents e220e54 + 682d734 commit 27da3e2
Show file tree
Hide file tree
Showing 20 changed files with 497 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/require-array-sort-compare": ["error", {"ignoreStringArrays": true}],
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ jobs:
with:
wrapper-directory: __tests__/data/basic
build-root-directory: __tests__/data/basic
arguments: help
dependencies-cache-enabled: true
configuration-cache-enabled: true
arguments: test
- name: Test dist download
uses: ./
with:
gradle-version: 6.5
gradle-version: 6.6-milestone-1
build-root-directory: __tests__/data/basic
arguments: help
dependencies-cache-enabled: true
configuration-cache-enabled: true
arguments: test --configuration-cache
10 changes: 7 additions & 3 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:
with:
wrapper-directory: __tests__/data/basic
build-root-directory: __tests__/data/basic
arguments: help
dependencies-cache-enabled: true
configuration-cache-enabled: true
arguments: test
- name: Test dist download
uses: ./
with:
gradle-version: 6.5
gradle-version: 6.6-milestone-1
build-root-directory: __tests__/data/basic
arguments: help
dependencies-cache-enabled: true
configuration-cache-enabled: true
arguments: test --configuration-cache
73 changes: 66 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ You might also be interested by the related [Gradle Plugin](https://github.com/e

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
name: Run Gradle on PRs
Expand All @@ -21,7 +19,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 11
Expand Down Expand Up @@ -83,7 +81,7 @@ If you need to pass environment variables, simply use the GitHub Actions workflo
```yaml
- uses: eskatos/gradle-command-action@v1
with:
gradle-version: 5.6.2
gradle-version: 6.5
```

`gradle-version` can be set to any valid Gradle version.
Expand All @@ -110,7 +108,7 @@ jobs:
gradle-rc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 11
Expand All @@ -120,7 +118,68 @@ jobs:
arguments: build --dry-run # just test build configuration
```

# Build scans
## Caching

This action provides 3 levels of caching to help speed up your GitHub Actions:

- `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.

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:

```yaml
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
```

The wrapper installation cache is simple and can't be configured further.

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.

### Configuring the dependencies and configuration caches

Both the dependencies and configuration caches use the same default configuration:

They use the following inputs to calculate the cache key:
```text
```

They restore cached state even if there isn't an exact match.

If the defaults don't suit your needs you can override them with the following inputs:

```yaml
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-command-action` action will emit the link to the published build scan as an output named `build-scan-url`.

Expand All @@ -139,7 +198,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 11
Expand Down
10 changes: 5 additions & 5 deletions __tests__/cache.test.ts → __tests__/cache-wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import * as cache from '../src/cache'
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 = cache.extractGradleWrapperSlugFrom(
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 = cache.extractGradleWrapperSlugFromDistUri(
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 = cache.extractGradleWrapperSlugFromDistUri(
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 = cache.extractGradleWrapperSlugFromDistUri(
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')
Expand Down
39 changes: 39 additions & 0 deletions __tests__/crypto-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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'
)
})
})
})
17 changes: 11 additions & 6 deletions __tests__/data/basic/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
*/
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation('junit:junit:4.12')
}
10 changes: 10 additions & 0 deletions __tests__/data/basic/src/test/java/basic/BasicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package basic;

import org.junit.Test;

public class BasicTest {
@Test
public void test() {
assert true;
}
}
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ inputs:
arguments:
description: Gradle command line arguments, see gradle --help
required: false
wrapper-cache-enabled:
description: Whether caching wrapper installation is enabled or not, default to 'true'
required: false
dependencies-cache-enabled:
description: Whether caching dependencies is enabled or not, default to 'false'
required: false
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

outputs:
build-scan-url:
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"author": "Paul Merlin <paul@nosphere.org>",
"license": "MIT",
"dependencies": {
"@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",
"@actions/cache": "0.2.1",
"string-argv": "0.3.1",
"typed-rest-client": "1.7.3",
"unzipper": "0.10.11"
Expand Down
Loading

0 comments on commit 27da3e2

Please # to comment.