You now explore the Update dependency cache workflow.
Check out .github/workflows/update-cache.yml file.
name: Update dependency cache
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
update-dependency-cache:
name: Update dependency cache
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK ${{ vars.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: ${{ vars.JAVA_DISTRIBUTION }}
- uses: actions/cache@v4
name: Cache dependencies
id: cache
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
lookup-only: true
- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
name: Update cache
run: |
chmod +x gradlew
./gradlew dependencies
This GitHub Actions workflow is designed to update the dependency cache for a project, specifically for Java Gradle-based projects. Let’s take a high-level look at key components of the workflow.
push: triggers the workflow when the merge group for a given pull request is successful and the PR is actually merged into the main branch.
workflow_dispatch: allows the workflow to be manually started for debugging without inputs.
Ensures that only one instance of the workflow runs for a specific branch at a time, canceling any in-progress runs if a new one starts (explore more about concurrency group in 14. Experiments With GitHub Actions Concurrency Group).
update-dependency-cache