Skip to content
Latchkey

Clear cache ... workflow (Lightning-AI/torchmetrics)

The Clear cache ... workflow from Lightning-AI/torchmetrics, explained and optimized by Latchkey.

C

CI health: C - fair

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: Lightning-AI/torchmetrics.github/workflows/clear-cache.ymlLicense Apache-2.0View source

What it does

This is the Clear cache ... workflow from the Lightning-AI/torchmetrics repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Clear cache ...

on:
  pull_request:
    paths:
      - ".github/workflows/clear-cache.yml"
  workflow_dispatch:
    inputs:
      pattern:
        description: "pattern for cleaning cache"
        default: "pip-|conda"
        required: false
        type: string
      age-days:
        description: "setting the age of caches in days to be dropped"
        required: true
        type: number
        default: 5
  schedule:
    # on Sundays
    - cron: "0 0 * * 0"

jobs:
  cron-clear:
    if: github.event_name == 'schedule' || github.event_name == 'pull_request'
    uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@2094525f99d94e25998563f5f7c960d48c12dc87 # v0.15.2
    with:
      scripts-ref: v0.15.2
      dry-run: ${{ github.event_name == 'pull_request' }}
      pattern: "pip-latest"
      age-days: 7

  direct-clear:
    if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
    uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@2094525f99d94e25998563f5f7c960d48c12dc87 # v0.15.2
    with:
      scripts-ref: v0.15.2
      dry-run: ${{ github.event_name == 'pull_request' }}
      pattern: ${{ inputs.pattern || 'pypi_wheels' }} # setting str in case of PR / debugging
      age-days: ${{ fromJSON(inputs.age-days) || 0 }} # setting 0 in case of PR / debugging

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Clear cache ...
 
on:
  pull_request:
    paths:
      - ".github/workflows/clear-cache.yml"
  workflow_dispatch:
    inputs:
      pattern:
        description: "pattern for cleaning cache"
        default: "pip-|conda"
        required: false
        type: string
      age-days:
        description: "setting the age of caches in days to be dropped"
        required: true
        type: number
        default: 5
  schedule:
    # on Sundays
    - cron: "0 0 * * 0"
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  cron-clear:
    timeout-minutes: 30
    if: github.event_name == 'schedule' || github.event_name == 'pull_request'
    uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@2094525f99d94e25998563f5f7c960d48c12dc87 # v0.15.2
    with:
      scripts-ref: v0.15.2
      dry-run: ${{ github.event_name == 'pull_request' }}
      pattern: "pip-latest"
      age-days: 7
 
  direct-clear:
    timeout-minutes: 30
    if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
    uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@2094525f99d94e25998563f5f7c960d48c12dc87 # v0.15.2
    with:
      scripts-ref: v0.15.2
      dry-run: ${{ github.event_name == 'pull_request' }}
      pattern: ${{ inputs.pattern || 'pypi_wheels' }} # setting str in case of PR / debugging
      age-days: ${{ fromJSON(inputs.age-days) || 0 }} # setting 0 in case of PR / debugging
 

What changed

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.