Skip to content

Online cache update #14837

Online cache update

Online cache update #14837

Workflow file for this run

name: Online cache update
defaults:
run:
shell: bash
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
concurrency: online-cache-update
jobs:
run:
runs-on: windows-latest
permissions:
contents: write
actions: write # for writing to the cache
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
path: main
- name: Checkout windhawk-mods
uses: actions/checkout@v6
id: checkout-windhawk-mods
with:
repository: ramensoftware/windhawk-mods
ref: pages
path: windhawk-mods
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
cache: 'pip'
cache-dependency-path: 'main/.github/requirements.txt'
- name: Install Python dependencies
run: python -m pip install -r main/.github/requirements.txt
# Workaround for updating cache:
# https://github.com/actions/cache/issues/342#issuecomment-1363953531
- name: Restore cache - binaries and symbols
uses: actions/cache/restore@v5
id: cache-binaries-and-symbols
with:
path: binaries
key: cache-binaries-and-symbols-key-v1
- name: Calculate cache file list hash (before)
id: cache-file-list-hash-before
run: |
echo "hash=$(find binaries -type f | sort | sha256sum | awk '{print $1}')" >> $GITHUB_OUTPUT
- name: Rename cache folder
if: ${{ steps.cache-binaries-and-symbols.outputs.cache-hit }}
run: mv binaries binaries_previous
- name: Run 01_extract_mod_symbols
run: |
python -u main/scripts/01_extract_mod_symbols.py \
windhawk-mods/mods \
extracted_symbols.json
- name: Run 02_download_binaries
run: |
python -u main/scripts/02_download_binaries.py \
extracted_symbols.json \
binaries \
binaries_previous
- name: Run 03_extract_symbols_from_binaries
run: |
python -u main/scripts/03_extract_symbols_from_binaries.py \
binaries \
main/scripts/tools/windhawk-symbol-helper.exe \
main/scripts/tools \
symbols
- name: Calculate cache file list hash (after)
id: cache-file-list-hash-after
run: |
echo "hash=$(find binaries -type f | sort | sha256sum | awk '{print $1}')" >> $GITHUB_OUTPUT
- name: Cache file list changed?
id: cache-file-list-changed
run: |
if [ "${{ steps.cache-file-list-hash-before.outputs.hash }}" = "${{ steps.cache-file-list-hash-after.outputs.hash }}" ]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Last deploy commit message changed?
id: last-deploy-commit-message-changed
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
msg=$(curl -s -H "Authorization: token $GH_TOKEN" \
https://api.github.com/repos/$REPO/commits/gh-pages \
| jq -r '.commit.message | split("\n")[0]')
echo "$msg"
if [ "$msg" = "deploy: ${{ github.sha }}, mods@${{ steps.checkout-windhawk-mods.outputs.commit }}" ]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run 04_create_mod_cache
if: >-
${{
steps.cache-file-list-changed.outputs.changed == 'true' ||
steps.last-deploy-commit-message-changed.outputs.changed == 'true'
}}
run: |
python -u main/scripts/04_create_mod_cache.py \
binaries \
extracted_symbols.json \
symbol_cache
- name: Deploy
if: >-
${{
steps.cache-file-list-changed.outputs.changed == 'true' ||
steps.last-deploy-commit-message-changed.outputs.changed == 'true'
}}
run: |
src_dir=symbol_cache
deploy_dir="${{ runner.temp }}/deploy"
deploy_branch=gh-pages
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
echo Cloning the repository
git clone --branch $deploy_branch --depth 1 --filter=blob:none --no-checkout https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git "$deploy_dir"
echo Adding generated files to the repository
git --git-dir="$deploy_dir/.git" --work-tree="$src_dir" add -A
touch "$deploy_dir/.nojekyll"
git -C "$deploy_dir" add .nojekyll
echo Committing changes
git -C "$deploy_dir" commit -m "deploy: ${{ github.sha }}, mods@${{ steps.checkout-windhawk-mods.outputs.commit }}" --allow-empty
echo Pushing to GitHub
git -C "$deploy_dir" push origin $deploy_branch
# Workaround for updating cache:
# https://github.com/actions/cache/issues/342#issuecomment-1363953531
- name: Clear cache - binaries and symbols
if: >-
${{
steps.cache-file-list-changed.outputs.changed == 'true' &&
steps.cache-binaries-and-symbols.outputs.cache-hit
}}
env:
GH_TOKEN: ${{ github.token }} # required by gh
run: |
gh cache delete cache-binaries-and-symbols-key-v1 -R ${{ github.repository }}
- name: Save cache - binaries and symbols
if: ${{ steps.cache-file-list-changed.outputs.changed == 'true' }}
uses: actions/cache/save@v5
with:
path: binaries
key: cache-binaries-and-symbols-key-v1