Skip to content

Commit 8d6fd83

Browse files
committed
feat: implement an E2E test for cache-dependency-path option
1 parent afbedba commit 8d6fd83

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Validate cache with cache-dependency-path option
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- releases/*
8+
paths-ignore:
9+
- '**.md'
10+
pull_request:
11+
paths-ignore:
12+
- '**.md'
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
jobs:
19+
gradle1-save:
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [macos-latest, windows-latest, ubuntu-latest]
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
- name: Run setup-java with the cache for gradle
29+
uses: ./
30+
id: setup-java
31+
with:
32+
distribution: 'adopt'
33+
java-version: '11'
34+
cache: gradle
35+
cache-dependency-path: __tests__/cache/gradle1/*.gradle*
36+
- name: Create files to cache
37+
# Need to avoid using Gradle daemon to stabilize the save process on Windows
38+
# https://github.com/actions/cache/issues/454#issuecomment-840493935
39+
run: |
40+
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
41+
if [ ! -d ~/.gradle/caches ]; then
42+
echo "::error::The ~/.gradle/caches directory does not exist unexpectedly"
43+
exit 1
44+
fi
45+
gradle1-restore:
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
os: [macos-latest, windows-latest, ubuntu-latest]
51+
needs: gradle1-save
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v3
55+
- name: Run setup-java with the cache for gradle
56+
uses: ./
57+
id: setup-java
58+
with:
59+
distribution: 'adopt'
60+
java-version: '11'
61+
cache: gradle
62+
cache-dependency-path: __tests__/cache/gradle1/*.gradle*
63+
- name: Confirm that ~/.gradle/caches directory has been made
64+
run: |
65+
if [ ! -d ~/.gradle/caches ]; then
66+
echo "::error::The ~/.gradle/caches directory does not exist unexpectedly"
67+
exit 1
68+
fi
69+
ls ~/.gradle/caches/
70+
gradle2-restore:
71+
runs-on: ${{ matrix.os }}
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
os: [macos-latest, windows-latest, ubuntu-latest]
76+
needs: gradle1-save
77+
steps:
78+
- name: Checkout
79+
uses: actions/checkout@v3
80+
- name: Run setup-java with the cache for gradle
81+
uses: ./
82+
id: setup-java
83+
with:
84+
distribution: 'adopt'
85+
java-version: '11'
86+
cache: gradle
87+
cache-dependency-path: __tests__/cache/gradle2/*.gradle*
88+
- name: Confirm that ~/.gradle/caches directory has not been made
89+
run: |
90+
if [ -d ~/.gradle/caches ]; then
91+
echo "::error::The ~/.gradle/caches directory exists unexpectedly"
92+
exit 1
93+
fi

.github/workflows/e2e-cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
# Need to avoid using Gradle daemon to stabilize the save process on Windows
3737
# https://github.com/actions/cache/issues/454#issuecomment-840493935
3838
run: |
39-
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle
39+
gradle downloadDependencies --no-daemon -p __tests__/cache/gradle1
4040
if [ ! -d ~/.gradle/caches ]; then
4141
echo "::error::The ~/.gradle/caches directory does not exist unexpectedly"
4242
exit 1

__tests__/cache/gradle2/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.gradle
2+
**/build/
3+
!src/**/build/
4+
5+
# Ignore Gradle GUI config
6+
gradle-app.setting
7+
8+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
9+
!gradle-wrapper.jar
10+
11+
# Cache of project
12+
.gradletasknamecache

__tests__/cache/gradle2/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
id 'java'
3+
}
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
implementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
9+
}
10+
tasks.register('downloadDependencies') {
11+
doLast {
12+
def total = configurations.compileClasspath.inject (0) { sum, file ->
13+
sum + file.length()
14+
}
15+
println total
16+
}
17+
}

0 commit comments

Comments
 (0)