-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yml
More file actions
88 lines (81 loc) · 4.28 KB
/
Copy pathaction.yml
File metadata and controls
88 lines (81 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: "Setup CI caches"
description: "Set up the JDK and restore the Maven dependency cache; reactor jobs also restore the generated-client build cache."
inputs:
cache-type:
description: "application-server-reactor for jobs that run the Maven reactor; application-server-tests for jobs that run goals against the packaged reactor"
required: true
os:
description: "Operating system for cache key"
required: false
default: "ubuntu-latest"
runs:
using: "composite"
steps:
- name: Validate cache type
shell: bash
env:
CACHE_TYPE: ${{ inputs.cache-type }}
run: |
case "$CACHE_TYPE" in
application-server-reactor|application-server-tests) ;;
*) echo "::error::Unknown cache type '$CACHE_TYPE'."; exit 1 ;;
esac
- name: Compute cache identities
id: identity
shell: bash
env:
DEPENDENCY_HASH: ${{ hashFiles('server/**/pom.xml', 'server/.mvn/extensions.xml', 'server/.mvn/wrapper/maven-wrapper.properties') }}
GENERATED_CLIENTS_HASH: ${{ hashFiles('server/pom.xml', 'server/generated-clients/pom.xml', 'server/.mvn/**', 'server/generated-clients/src/**') }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [[ -z "$DEPENDENCY_HASH" || -z "$GENERATED_CLIENTS_HASH" ]]; then
echo "::error::Cannot compute the cache identities from the checked-out repository."
exit 1
fi
echo "dependencies=$DEPENDENCY_HASH" >> "$GITHUB_OUTPUT"
echo "generated-clients=$GENERATED_CLIENTS_HASH" >> "$GITHUB_OUTPUT"
# Only the default branch's pushes and schedules write caches; every other run reads them.
if [[ "$GITHUB_REF" == "refs/heads/$DEFAULT_BRANCH" && "$GITHUB_EVENT_NAME" =~ ^(push|schedule|workflow_dispatch)$ ]]; then
echo "save=true" >> "$GITHUB_OUTPUT"
else
echo "save=false" >> "$GITHUB_OUTPUT"
fi
- name: Set up JDK 21
id: java
uses: actions/setup-java@dd06d9cba3e5552c54d9f8ea23572deb30010f7c # v6.0.0
with:
distribution: "temurin"
java-version: "21"
cache-jdk: false
# A prefix fallback keeps a pom change from downloading the whole dependency tree again;
# setup-java's own Maven cache restores only an exact pom hash.
- name: Restore Maven dependencies
if: steps.identity.outputs.save != 'true'
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.m2/repository
key: ${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-maven-${{ steps.identity.outputs.dependencies }}
restore-keys: |
${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-maven-
# Reactor jobs resolve the complete tree, so only they save; a consumer job would also cache
# the reactor artifacts it installed.
- name: Cache Maven dependencies
if: steps.identity.outputs.save == 'true' && inputs.cache-type == 'application-server-reactor'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.m2/repository
key: ${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-maven-${{ steps.identity.outputs.dependencies }}
restore-keys: |
${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-maven-
- name: Restore generated clients
if: steps.identity.outputs.save != 'true' && inputs.cache-type == 'application-server-reactor'
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.m2/build-cache
key: ${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-generated-clients-${{ steps.identity.outputs.generated-clients }}
- name: Cache generated clients
if: steps.identity.outputs.save == 'true' && inputs.cache-type == 'application-server-reactor'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.m2/build-cache
key: ${{ inputs.os }}-${{ steps.java.outputs.distribution }}-${{ steps.java.outputs.version }}-generated-clients-${{ steps.identity.outputs.generated-clients }}