From 45adfabbcd132c857e27017bff2cbe2bd7051b91 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Mon, 8 Sep 2025 04:32:23 +0100 Subject: [PATCH] ci: Refactor timelord action to use git-warp-time fallback Updates the timelord action to fall back to git-warp-time when the cache is completely empty, enabling timestamp restoration even on fresh builds. Simplifies the interface by making inputs optional with sensible defaults and adds Docker integration via buildkit-cache-dance. --- .forgejo/actions/timelord/action.yml | 74 +++++++++++++++++----------- .forgejo/workflows/release-image.yml | 8 ++- docker/Dockerfile | 8 +++ 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/.forgejo/actions/timelord/action.yml b/.forgejo/actions/timelord/action.yml index bb9766d5..9038aec9 100644 --- a/.forgejo/actions/timelord/action.yml +++ b/.forgejo/actions/timelord/action.yml @@ -1,46 +1,64 @@ name: timelord description: | - Use timelord to set file timestamps + Use timelord to set file timestamps with git-warp-time fallback for cache misses inputs: key: description: | The key to use for caching the timelord data. - This should be unique to the repository and the runner. - required: true - default: timelord-v0 + required: false + default: '' path: description: | The path to the directory to be timestamped. - This should be the root of the repository. - required: true - default: . + required: false + default: '' + +outputs: + database-path: + description: Path to timelord database + value: '${{ env.TIMELORD_CACHE_PATH }}' runs: using: composite steps: - - name: Cache timelord-cli installation - id: cache-timelord-bin - uses: actions/cache@v3 - with: - path: ~/.cargo/bin/timelord - key: timelord-cli-v3.0.1 - - name: Install timelord-cli - uses: https://github.com/cargo-bins/cargo-binstall@main - if: steps.cache-timelord-bin.outputs.cache-hit != 'true' - - run: cargo binstall timelord-cli@3.0.1 + - name: Set defaults shell: bash - if: steps.cache-timelord-bin.outputs.cache-hit != 'true' + run: | + echo "TIMELORD_KEY=${{ inputs.key || format('timelord-v1-{0}-{1}', github.repository, hashFiles('**/*.rs', '**/Cargo.toml', '**/Cargo.lock')) }}" >> $GITHUB_ENV + echo "TIMELORD_PATH=${{ inputs.path || '.' }}" >> $GITHUB_ENV + echo "TIMELORD_CACHE_PATH=$HOME/.cache/timelord" >> $GITHUB_ENV - - name: Load timelord files - uses: actions/cache/restore@v3 + - name: Install timelord-cli and git-warp-time + uses: taiki-e/install-action@v2 with: - path: /timelord/ - key: ${{ inputs.key }} - - name: Run timelord to set timestamps + tool: git-warp-time,timelord-cli@3.0.1 + + - name: Restore timelord cache with fallbacks + id: timelord-restore + uses: actions/cache/restore@v4 + with: + path: ${{ env.TIMELORD_CACHE_PATH }} + key: ${{ env.TIMELORD_KEY }} + restore-keys: | + timelord-v1-${{ github.repository }}- + + - name: Initialize timestamps on complete cache miss + if: steps.timelord-restore.outputs.cache-hit != 'true' shell: bash - run: timelord sync --source-dir ${{ inputs.path }} --cache-dir /timelord/ - - name: Save timelord - uses: actions/cache/save@v3 + run: | + echo "Complete timelord cache miss - running git-warp-time" + git fetch --unshallow + git-warp-time --quiet ${{ env.TIMELORD_PATH }} + echo "Git timestamps restored" + + - name: Run timelord sync + shell: bash + run: | + mkdir -p ${{ env.TIMELORD_CACHE_PATH }} + timelord sync --source-dir ${{ env.TIMELORD_PATH }} --cache-dir ${{ env.TIMELORD_CACHE_PATH }} + + - name: Save updated timelord cache immediately + uses: actions/cache/save@v4 with: - path: /timelord/ - key: ${{ inputs.key }} + path: ${{ env.TIMELORD_CACHE_PATH }} + key: ${{ env.TIMELORD_KEY }} diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index b7423567..66fddf1f 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -150,10 +150,7 @@ jobs: echo "Commit timestamp: $timestamp" - uses: ./.forgejo/actions/timelord - if: ${{ env.BUILDKIT_ENDPOINT == '' }} - with: - key: timelord-v0 - path: . + id: timelord - name: Cache Rust registry if: ${{ env.BUILDKIT_ENDPOINT == '' }} @@ -202,7 +199,8 @@ jobs: "id": "cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }}" }, "var-cache-apt-${{ matrix.slug }}": "/var/cache/apt", - "var-lib-apt-${{ matrix.slug }}": "/var/lib/apt" + "var-lib-apt-${{ matrix.slug }}": "/var/lib/apt", + "${{ steps.timelord.outputs.database-path }}": "/root/.cache/timelord" } skip-extraction: ${{ steps.cache.outputs.cache-hit }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 17e1c6a1..c49aa055 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -133,6 +133,14 @@ FROM toolchain AS builder # Get source COPY . . +# Restore timestamps from timelord cache if available +RUN if [ -f /root/.cache/timelord/timelord.db ]; then \ + echo "Restoring timestamps from timelord cache"; \ + timelord sync --source-dir /app --cache-dir /root/.cache/timelord; \ + else \ + echo "No timelord cache found, timestamps will be build time"; \ + fi + ARG TARGETPLATFORM # Verify environment configuration