|
| 1 | +# Copyright (C) 2020 Dremio |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# CODE_COPIED_TO_POLARIS Copied from Project Nessie v. 0.104.2 |
| 16 | + |
| 17 | +name: 'Save incremental Gradle caches' |
| 18 | +description: 'Save incremental Gradle caches' |
| 19 | +inputs: |
| 20 | + job-name: |
| 21 | + description: 'job name' |
| 22 | + java-version: |
| 23 | + description: 'Java version' |
| 24 | + default: '21' |
| 25 | +runs: |
| 26 | + using: "composite" |
| 27 | + steps: |
| 28 | + - name: Prepare Gradle caches archive |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + if [[ -d ~/.gradle/caches/ ]] ; then |
| 32 | + echo "::group::Gradle caches / identify updated cache items" |
| 33 | +
|
| 34 | + cd ~/.gradle/caches/ |
| 35 | +
|
| 36 | + echo "Gradle caches/ contains $(find . -type f | wc -l) files" |
| 37 | + # Identify the added and changed files in caches/. |
| 38 | +
|
| 39 | + echo "Identifying changed/added files..." |
| 40 | + AGE_SECS=$(($(date +%s) - $(cat ~/caches-prepared-at-epoch))) |
| 41 | + echo "Build started ~ $AGE_SECS seconds ago" |
| 42 | + AGE_MINS=$(($AGE_SECS / 60 + 1)) |
| 43 | + echo " ... assuming that is ~ $AGE_MINS minutes" |
| 44 | + # This lists all relevant files that have been created or modified during by the Gradle |
| 45 | + # runs of the current job. |
| 46 | + find . -mmin -$AGE_MINS -type f '(' \ |
| 47 | + -path './[0-9]*/kotlin-dsl/*' -or \ |
| 48 | + -path './jars-*/*' -or \ |
| 49 | + -path './modules-*/files-*/*' -or \ |
| 50 | + -path './modules-*/files-*/*' -or \ |
| 51 | + -path './build-cache-*/*' \ |
| 52 | + ')' | grep -v '[.]lock$' > ~/ci-gradle-caches-diff || true |
| 53 | + echo "Identified $(wc -l < ~/ci-gradle-caches-diff) changed/added files in caches/" |
| 54 | +
|
| 55 | + # Only call 'tar', if there is some difference |
| 56 | + # Note: actions/upload-artifact takes care of compressing the artifact, no need to bug the CPU here |
| 57 | + echo "Creating artifact (if necessary)..." |
| 58 | + if [[ -s ~/ci-gradle-caches-diff ]] ; then |
| 59 | + tar --create --ignore-failed-read --file ~/ci-gradle-caches-${{ inputs.job-name }}-${{ inputs.java-version }}.tar -T ~/ci-gradle-caches-diff |
| 60 | + ls -al ~/ci-gradle-caches-${{ inputs.job-name }}-${{ inputs.java-version }}.tar |
| 61 | + fi |
| 62 | + echo "::endgroup::" |
| 63 | + fi |
| 64 | + - name: Archive code-checks incremental |
| 65 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 66 | + with: |
| 67 | + name: ci-gradle-caches-${{ inputs.job-name }}-${{ inputs.java-version }} |
| 68 | + path: ~/ci-gradle-caches-${{ inputs.job-name }}-${{ inputs.java-version }}.tar |
| 69 | + if-no-files-found: ignore |
| 70 | + retention-days: 1 |
0 commit comments