Skip to content

Commit

Permalink
Restore last modification times to commit used to build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRStevens committed Nov 25, 2024
1 parent 66faf23 commit d1884d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ jobs:
key: buildCache-${{ runner.os }}-${{ matrix.platform }}-${{ github.sha }}
restore-keys: buildCache-${{ runner.os }}-${{ matrix.platform }}-

- name: Set modification times
if: ${{ hashFiles('.build/lastBuildSha.txt') != '' }}
shell: bash
run: |
# Determine SHA of last cached build (ignore cache if not marked)
lastBuildSha=$(<.build/lastBuildSha.txt) || exit 0
echo "Last build SHA: ${lastBuildSha}"
# Fetch source code for last build
# (exit successfully if not found, cache will be ignored)
git fetch --depth=1 origin "${lastBuildSha}" || exit 0
git switch --detach "${lastBuildSha}"
# Set last modification times to that of last build's committer time
# The committer time should pre-date any cached output modification time
commitTime=$(git log -1 --format="%cI")
echo "commitTime=${commitTime}"
find . -type f -exec touch -d "${commitTime}" '{}' +
# Re-check out current branch, which updates last modification times of modified files
git switch -
- name: Set build SHA
shell: bash
run: |
# Save copy of current SHA to be cached, and used for reference in future builds
mkdir --parents .build/
echo "${{ github.sha }}" > .build/lastBuildSha.txt
- name: Build
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
Expand Down

0 comments on commit d1884d4

Please sign in to comment.