-
Notifications
You must be signed in to change notification settings - Fork 972
77 lines (72 loc) · 2.68 KB
/
prepare-java-cache.yml
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
# Copyright 2022 Google LLC
#
# 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.
# Prepares the Java cache either daily on demand. Since GitHub's cache action doesn't
# allow overwriting an existing entry, this is necessary to try to keep the cached dependencies
# as up-to-date as possible, hopefully minimizing the time it takes for PR checks to
# complete.
name: Prepare Java Cache
on:
# At the start of each day, refresh the cache.
schedule:
- cron: '0 0 * * *'
# A way to try to force the cache forward should something cause it to get stuck.
workflow_dispatch:
inputs:
days:
type: choice
description: 'The cache entry N days ahead to claim.'
required: true
default: '1'
options: ['1', '2', '3', '4', '5', '6']
# Run on PRs that change this workflow or our local actions just to make sure nothing breaks.
pull_request:
branches:
- 'main'
paths:
- '.github/workflows/prepare-java-cache.yml'
- '.github/actions/setup-java-env/*'
- '.github/actions/cleanup-java-env/*'
permissions: read-all
jobs:
cache_dependencies:
name: Cache Java Dependencies
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Set Manual Key
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "$(date -u --date='${{ inputs.days }} days' +%Y%m%d)" >> $GITHUB_ENV
- name: Set Empty Key
if: ${{ github.event_name != 'workflow_dispatch' }}
run: |
echo "CACHE_KEY=''" >> $GITHUB_ENV
- name: Checkout Code
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4.0.0
- name: Setup Java
id: setup-java
uses: ./.github/actions/setup-java-env
with:
cache-key: ${{ env.CACHE_KEY }}
- name: Resolve Dependencies
if: ${{ steps.setup-java.outputs.cache-hit != 'true' || github.event_name == 'pull_request' }}
run: |
mvn -B clean install \
-Dmaven.test.skip \
-Dcheckstyle.skip \
-Djib.skip \
-Dmdep.analyze.skip \
-Dspotless.check.skip
- name: Cleanup Java Environment
uses: ./.github/actions/cleanup-java-env