Skip to content
Latchkey

on-schedule workflow (module-federation/module-federation-examples)

The on-schedule workflow from module-federation/module-federation-examples, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: module-federation/module-federation-examples.github/workflows/on-schedule.ymlLicense MITView source

What it does

This is the on-schedule workflow from the module-federation/module-federation-examples repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

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

The workflow

workflow (.yml)
name: on-schedule
on:
  workflow_dispatch:
  schedule:
    - cron: 0 */48 * * *

jobs:
  # Cleanup unused cache to save space, run once a day at 8:00 AM. Removes all caches that are older than 10 hours and with names starting with e2e- or codeql-trap-
  cleanup:
    runs-on: ubuntu-22.04
    steps:
      - name: Cleanup unused cache
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const timestamp = new Date().getTime() - 1000 * 60 * 60 * 10;
            const date = new Date(timestamp);
            const isoDate = date.toISOString().replace('Z', '');
            const milliseconds = (date.getMilliseconds() / 1000).toFixed(7).slice(2);
            const resultDate = isoDate + milliseconds + 'Z';
            const caches = await github.rest.actions.getActionsCacheList({
              owner: context.repo.owner,
              repo: context.repo.repo
            });
            if (caches.data) {
              for (const cache of caches.data.actions_caches) {
                if (cache.key.startsWith('e2e-') && cache.ref.match(/refs\/pull\/\d+\/merge/g)) {
                  await github.rest.actions.deleteActionsCacheById({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    cache_id: cache.id
                  });
                  console.log(`Deleted cache ${cache.key}`);
                } else if (cache.key.startsWith('codeql-trap-') && cache.last_accessed_at < resultDate) {
                  await github.rest.actions.deleteActionsCacheById({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    cache_id: cache.id
                  });
                  console.log(`Deleted cache ${cache.key}`);
                } else {
                  console.log(`Cache ${cache.key} is valid and will not be deleted`);
                }
              }
            }

The same workflow, on Latchkey

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

name: on-schedule
on:
  workflow_dispatch:
  schedule:
    - cron: 0 */48 * * *
 
jobs:
  # Cleanup unused cache to save space, run once a day at 8:00 AM. Removes all caches that are older than 10 hours and with names starting with e2e- or codeql-trap-
  cleanup:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - name: Cleanup unused cache
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const timestamp = new Date().getTime() - 1000 * 60 * 60 * 10;
            const date = new Date(timestamp);
            const isoDate = date.toISOString().replace('Z', '');
            const milliseconds = (date.getMilliseconds() / 1000).toFixed(7).slice(2);
            const resultDate = isoDate + milliseconds + 'Z';
            const caches = await github.rest.actions.getActionsCacheList({
              owner: context.repo.owner,
              repo: context.repo.repo
            });
            if (caches.data) {
              for (const cache of caches.data.actions_caches) {
                if (cache.key.startsWith('e2e-') && cache.ref.match(/refs\/pull\/\d+\/merge/g)) {
                  await github.rest.actions.deleteActionsCacheById({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    cache_id: cache.id
                  });
                  console.log(`Deleted cache ${cache.key}`);
                } else if (cache.key.startsWith('codeql-trap-') && cache.last_accessed_at < resultDate) {
                  await github.rest.actions.deleteActionsCacheById({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    cache_id: cache.id
                  });
                  console.log(`Deleted cache ${cache.key}`);
                } else {
                  console.log(`Cache ${cache.key} is valid and will not be deleted`);
                }
              }
            }
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

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

Actions used in this workflow