Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching to the github workflows #189

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
40b0e34
Add vcpkg caching
neilenns Oct 26, 2024
bea2f99
Echo the revision, fix release.yml
neilenns Oct 26, 2024
2474894
Try echoing again
neilenns Oct 26, 2024
db54cf3
Clean up build step names
neilenns Oct 26, 2024
dc3c6ab
Merge branch 'main' into neilenns/issue185
neilenns Oct 27, 2024
3a5c674
Force rebuild
neilenns Oct 27, 2024
ee7a3e4
Add afv-native caching
neilenns Oct 27, 2024
3c2fd77
force rebuild
neilenns Oct 27, 2024
f55ee7c
Get rid of afv-native change
neilenns Oct 27, 2024
8f18e2e
Try caching electron-builder
neilenns Oct 27, 2024
5fb07b2
force rebuild
neilenns Oct 27, 2024
4e86f1e
Add OS to electron-builder cache key
neilenns Oct 27, 2024
81e48ad
Fix restore-keys
neilenns Oct 27, 2024
6f94cfe
force rebuild
neilenns Oct 27, 2024
370c10e
Get rid of fallback cache keys
neilenns Oct 27, 2024
bd0ae4e
Try caching afv-native
neilenns Oct 27, 2024
8e343d8
Try splitting restore cache to a composite action
neilenns Oct 27, 2024
d636996
Fix restore-cache composite action
neilenns Oct 27, 2024
c9779c1
Fix path
neilenns Oct 27, 2024
8a10fc3
Add shell
neilenns Oct 27, 2024
50b6d4f
Fix trackaudio-afv path
neilenns Oct 27, 2024
63e9abe
Fix path again
neilenns Oct 27, 2024
52c27ff
Update release.yml
neilenns Oct 27, 2024
8a79cd0
Use backend/ for cache key
neilenns Oct 27, 2024
7476fbd
Only cache afv-native during CI builds
neilenns Oct 27, 2024
ae056d7
Change cache to make it work on Windows
neilenns Oct 27, 2024
96670d9
Explicitly set electron-builder cache folders
neilenns Oct 27, 2024
4d08eff
Fix hashFiles on windows
neilenns Oct 27, 2024
d8929aa
Try again
neilenns Oct 27, 2024
27c0ec1
Try again
neilenns Oct 27, 2024
190b0e4
Add shell
neilenns Oct 27, 2024
40027e6
Fix unix/macos
neilenns Oct 27, 2024
6ab7f84
Force rebuild
neilenns Oct 27, 2024
3df35d5
Fix up terms
neilenns Oct 27, 2024
6dd6119
Force rebuild
neilenns Oct 27, 2024
5da92e0
Fix typo
neilenns Oct 27, 2024
ec19043
Force rebuild
neilenns Oct 27, 2024
dc06cc5
Force rebuild
neilenns Oct 28, 2024
7c60039
Temporarily disable electron-builder cache
neilenns Oct 28, 2024
81a65dc
Try without env
neilenns Oct 28, 2024
1d2d10f
Add back ~
neilenns Oct 28, 2024
baea6fc
Try using github.workspace
neilenns Oct 28, 2024
7bc64f8
Add node_modules caching
neilenns Oct 28, 2024
5540b97
Try fixing electron-builder again
neilenns Oct 28, 2024
34475e8
Fix OS typo
neilenns Oct 28, 2024
8ec77b4
Clean up comments, remove npm install
neilenns Oct 28, 2024
fe6a881
Force rebuild
neilenns Oct 28, 2024
c8f8efe
Add additional comments
neilenns Oct 28, 2024
c6156d4
Tweak npm caching and use npm ci
neilenns Oct 29, 2024
b33025c
Merge remote-tracking branch 'upstream/main' into neilenns/issue185
neilenns Oct 29, 2024
0bfc4c5
Try switching back to npm install
neilenns Oct 29, 2024
8255819
Fix cache key, go back to ci
neilenns Oct 29, 2024
3e2d890
Revert npm ci
neilenns Oct 29, 2024
2762a51
Fix npm install
neilenns Oct 29, 2024
0a5a544
Merge branch 'main' into neilenns/issue185
neilenns Nov 4, 2024
d0a5869
Try using setup-node's cache instead
neilenns Nov 4, 2024
8173ad0
Force rebuild
neilenns Nov 4, 2024
8f9a6f5
Merge branch 'main' into neilenns/issue185
neilenns Nov 4, 2024
8c4273e
Try using bash on Windows
neilenns Nov 5, 2024
8244a64
Merge branch 'main' into neilenns/issue185
neilenns Nov 15, 2024
cfbf1f9
Add libuiohook, clean up mistakes
neilenns Nov 15, 2024
0e6561d
Update windows version
neilenns Nov 15, 2024
8364642
Fix outputs definition
neilenns Nov 15, 2024
492f687
Force build
neilenns Nov 15, 2024
da418be
Fix afv-native and libuiohook caching. Oops.
neilenns Nov 15, 2024
eacc0b9
Force build
neilenns Nov 15, 2024
d1a3653
Merge branch 'main' into neilenns/issue185
neilenns Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions .github/actions/restore-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Restore cached files
description: Restores backend, vcpkg, and electron-builder from cache

inputs:
backend:
description: Set to true to cache backend
required: false
default: 'false'

outputs:
backend:
description: True if backend was restored from cache
value: ${{ steps.backend.outputs.cache-hit }}
afv-native:
description: True if libuiohook was restored from cache
value: ${{ steps.libuiohook.outputs.cache-hit }}
electron-builder:
description: True if electron-builder was restored from cache
value: ${{ steps.electron-builder.outputs.cache-hit }}
vcpkg:
description: True if vcpkg was restored from cache
value: ${{ steps.vcpkg.outputs.cache-hit }}

runs:
using: 'composite'
steps:
# The cache folder for electron and electron-builder is different across the three platforms.
# Furthermore, the ELECTRON_CACHE and ELECTRON_BUILDER_CACHE environment variables don't work.
# So there has to be separate steps for the different platforms to set the proper cache locations,
# which were determined by looking at the code here:
# https://github.com/develar/app-builder/blob/c87157ae504895a7e9e1329437293846b8e57beb/pkg/download/artifactDownloader.go#L195
- name: Set Electron cache paths (macos and linux)
if: matrix.os != 'windows-2022'
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo "ELECTRON_CACHE_DIR=$HOME/.cache/electron" >> $GITHUB_ENV
echo "ELECTRON_BUILDER_CACHE_DIR=$HOME/.cache/electron-builder" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" == "macOS" ]]; then
echo "ELECTRON_CACHE_DIR=$HOME/Library/Caches/electron" >> $GITHUB_ENV
echo "ELECTRON_BUILDER_CACHE_DIR=$HOME/Library/Caches/electron-builder" >> $GITHUB_ENV
fi

- name: Set Electron cache paths (Windows)
if: matrix.os == 'windows-2022'
shell: pwsh
run: |
echo "ELECTRON_CACHE_DIR=$Env:LOCALAPPDATA\electron\Cache" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "ELECTRON_BUILDER_CACHE_DIR=$Env:LOCALAPPDATA\electron-builder\Cache" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append

# Get the afv-native submodule revision to use as the cache key for restoring afv-native.
- name: Get afv-native submodule revision
shell: bash
run: |
AFVNATIVE_REV=$(git rev-parse HEAD:./backend/extern/afv-native)
echo "AFVNATIVE_REV=$AFVNATIVE_REV" >> $GITHUB_ENV
echo "afv-native submodule revision $AFVNATIVE_REV"

# Get the libuiohook submodule revision to use as the cache key for restoring libuiohook.
- name: Get libuiohook submodule revision
shell: bash
run: |
LIBUIOHOOK_REV=$(git rev-parse HEAD:./backend/extern/libuiohook)
echo "LIBUIOHOOK_REV=$LIBUIOHOOK_REV" >> $GITHUB_ENV
echo "libuiohook submodule revision $LIBUIOHOOK_REV"

# Get the vcpkg submodule revision to use as the cache key for restoring vcpkg.
- name: Get vcpkg submodule revision
shell: bash
run: |
VCPKG_REV=$(git rev-parse HEAD:./backend/vcpkg)
echo "VCPKG_REV=$VCPKG_REV" >> $GITHUB_ENV
echo "vcpkg submodule revision $VCPKG_REV"

# The cache key for backend has to be constructed differently on windows vs
# macos/linux because hashFiles doesn't work on windows if you specify `backend/**`.
# backend is cached based on the SHA of backend and the hash of all files under
# backend/. The key is all the files under backend, the afv-native SHA, and libuiohook SHA.
- name: Set backend cache key (windows)
if: matrix.os == 'windows-2022'
shell: pwsh
run: echo "BACKEND_CACHE_KEY=${{ runner.os }}-backend-${{ hashFiles('backend\\**') }}-${{ env.AFVNATIVE_REV }}-${{ env.LIBUIOHOOK_REV }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Set backend cache key (macos and linux)
if: matrix.os != 'windows-2022'
shell: bash
run: echo "BACKEND_CACHE_KEY=${{ runner.os }}-backend-${{ hashFiles('backend/**') }}-${{ env.AFVNATIVE_REV }}-${{ env.LIBUIOHOOK_REV }}" >> $GITHUB_ENV

- name: Restore electron-builder cache
id: electron-builder
uses: actions/cache@v4
with:
path: |
${{ env.ELECTRON_CACHE_DIR }}
${{ env.ELECTRON_BUILDER_CACHE_DIR }}
key: ${{ runner.os }}-electron-builder-${{ hashFiles('package-lock.json') }}

# The backend only gets cached if backend is set to 'true' when calling this composite
# action, currently only in the ci.yml flow. release.yml does not cache backend.
- name: Restore backend from cache
id: backend
uses: actions/cache@v4
if: ${{ inputs.backend }} == 'true'
with:
path: |
backend/trackaudio-afv-1.0.0.tgz
key: ${{ env.BACKEND_CACHE_KEY }}

# vcpkg only get restored if the backend cache wasn't found. That's because if the backend cache
# is found there's no native build at all, so no need to restore vcpkg for the native components.
- name: Restore vcpkg from cache
id: vcpkg
uses: actions/cache@v4
if: steps.backend.outputs.cache-hit != 'true'
with:
path: |
backend/vcpkg
backend/build/vcpkg_installed
key: ${{ runner.os }}-vcpkg-${{ hashFiles('backend/vcpkg.json')}}-${{ env.VCPKG_REV }}
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ jobs:
cd backend/extern/afv-native
git checkout modern-chained-callback

- name: Restore cache
id: restore-cache
uses: ./.github/actions/restore-cache
with:
backend: 'true'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install Python 3.x
uses: actions/setup-python@v5
Expand All @@ -68,11 +75,15 @@ jobs:
sudo apt-get update
sudo apt-get install -y libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev pkg-config libxtst-dev libxinerama-dev libx11-xcb-dev libxkbcommon-dev libxkbcommon-x11-dev libxkbfile-dev

- name: Install dependencies
- name: Build backend and install dependencies
if: steps.restore-cache.outputs.backend != 'true'
run: |
npm -g i cmake-js
npm run build:backend
npm install

- name: Install cached backend and dependencies
if: steps.restore-cache.outputs.backend == 'true'
run: npm install ./backend/trackaudio-afv-1.0.0.tgz
neilenns marked this conversation as resolved.
Show resolved Hide resolved

- name: Run eslint
run: npm run lint
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Release
on:
workflow_dispatch:

env:
ELECTRON_CACHE: .cache/electron
ELECTRON_BUILDER_CACHE: .cache/electron-builder

jobs:
build:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -31,15 +35,20 @@ jobs:
cd backend/extern/afv-native
git checkout modern-chained-callback

- name: Restore cache
id: restore-cache
uses: ./.github/actions/restore-cache

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install Python 3.x
uses: actions/setup-python@v5
with:
python-version: "3.11.x"
python-version: '3.11.x'

- name: Update cmake
if: matrix.os != 'macos-latest'
Expand Down Expand Up @@ -91,7 +100,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y desktop-file-utils ninja-build gcc-aarch64-linux-gnu:amd64 g++-aarch64-linux-gnu:amd64 python3-jinja2:amd64 libgcrypt20:arm64 libgcrypt20-dev:arm64 libgpg-error-dev:arm64 libx11-dev:arm64 libxrandr-dev:arm64 libxcursor-dev:arm64 libxi-dev:arm64 libudev-dev:arm64 libgl1-mesa-dev:arm64

- name: Install dependencies and building backend (x64)
- name: Build backend (x64)
if: matrix.arch == 'x64'
run: |
npm -g i cmake-js
Expand All @@ -102,9 +111,8 @@ jobs:
npm pack
cd ..
npm install ./backend/trackaudio-afv-1.0.0.tgz
npm install

- name: Install dependencies and building backend (macOs arm64)
- name: Build backend (macOs arm64)
if: matrix.arch == 'arm64' && matrix.os == 'macos-latest'
run: |
npm -g i cmake-js
Expand All @@ -115,9 +123,8 @@ jobs:
npm pack
cd ..
npm install ./backend/trackaudio-afv-1.0.0.tgz
npm install

- name: Install dependencies and building backend (linux arm64 cross compile)
- name: Build backend (linux arm64 cross compile)
if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest'
run: |
npm -g i cmake-js
Expand All @@ -128,7 +135,6 @@ jobs:
npm pack
cd ..
npm install ./backend/trackaudio-afv-1.0.0.tgz
npm install

- name: Package app
if: matrix.os == 'windows-2022'
Expand All @@ -149,7 +155,7 @@ jobs:
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_API_KEY: "./.a.p8"
APPLE_API_KEY: './.a.p8'
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
run: |
Expand Down Expand Up @@ -191,7 +197,7 @@ jobs:
if: matrix.os == 'macos-latest'
with:
tag_name: ${{ steps.relinfo.outputs.release }}
files: "dist/*.dmg"
files: 'dist/*.dmg'

- name: Upload artifacts
uses: softprops/action-gh-release@v2
Expand Down
2 changes: 1 addition & 1 deletion backend/vcpkg
Submodule vcpkg updated 3310 files
Loading