Skip to content

Commit c75673e

Browse files
committed
chore: add cache to ci
1 parent 763156c commit c75673e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.github/workflows/Build.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
pull_request:
8+
89
concurrency:
910
group: build-${{ github.ref }}
1011
cancel-in-progress: true
@@ -30,6 +31,20 @@ jobs:
3031
distribution: 'zulu'
3132
java-version: 11
3233

34+
- name: chmod cache key
35+
run: chmod +x ./scripts/checksum.sh
36+
37+
- name: Generate cache key
38+
run: ./scripts/checksum.sh app checksum.txt
39+
40+
- uses: actions/cache@v3
41+
with:
42+
path: |
43+
~/.gradle/caches/modules-*
44+
~/.gradle/caches/jars-*
45+
~/.gradle/caches/build-cache-*
46+
key: gradle-${{ hashFiles('checksum.txt') }}
47+
3348
- name: Setup Gradle
3449
uses: gradle/gradle-build-action@v2
3550

scripts/checksum.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Cache check
2+
3+
#!/bin/bash
4+
SAMPLE=$1
5+
RESULT_FILE=$2
6+
7+
if [ -f $RESULT_FILE ]; then
8+
rm $RESULT_FILE
9+
fi
10+
touch $RESULT_FILE
11+
12+
checksum_file() {
13+
echo $(openssl md5 $1 | awk '{print $2}')
14+
}
15+
16+
FILES=()
17+
while read -r -d ''; do
18+
FILES+=("$REPLY")
19+
done < <(find $SAMPLE -type f \( -name "build.gradle*" -o -name "gradle-wrapper.properties" -o -name "robolectric.properties" \) -print0)
20+
21+
# Loop through files and append MD5 to result file
22+
for FILE in ${FILES[@]}; do
23+
echo $(checksum_file $FILE) >> $RESULT_FILE
24+
done
25+
# Now sort the file so that it is idempotent
26+
sort $RESULT_FILE -o $RESULT_FILE

0 commit comments

Comments
 (0)