Skip to content

Commit 2f48519

Browse files
authored
Improve build time in CI through caching native modules (element-hq#482)
* Improve caching of hak native modules * Avoid double-hashing * Skip native installs where cache is hit * Include Electron version in the hash, it affects the ABI * Add missing step IDs * Add comments
1 parent 6508e17 commit 2f48519

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

.github/workflows/build_linux.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This workflow relies on actions/cache to store the hak dependency artifacts as they take a long time to build
2+
# Due to this extra care must be taken to only ever run all build_* scripts against the same branch to ensure
3+
# the correct cache scoping, and additional care must be taken to not run untrusted actions on the develop branch.
14
on:
25
workflow_call:
36
inputs:
@@ -16,19 +19,21 @@ jobs:
1619
name: webapp
1720

1821
- name: Cache .hak
22+
id: cache
1923
uses: actions/cache@v3
2024
with:
21-
key: ${{ hashFiles('./yarn.lock') }}
25+
key: ${{ runner.os }}-${{ hashFiles('hakDependencies.json', 'electronVersion') }}
2226
path: |
2327
./.hak
2428
2529
- name: Install Rust
30+
if: steps.cache.outputs.cache-hit != 'true'
2631
uses: actions-rs/toolchain@v1
2732
with:
2833
toolchain: stable
2934

3035
- name: Install libsqlcipher-dev
31-
if: inputs.sqlcipher == 'system'
36+
if: steps.cache.outputs.cache-hit != 'true' && inputs.sqlcipher == 'system'
3237
run: sudo apt-get install -y libsqlcipher-dev
3338

3439
- uses: actions/setup-node@v3
@@ -40,6 +45,7 @@ jobs:
4045
run: "yarn install --pure-lockfile"
4146

4247
- name: Build Natives
48+
if: steps.cache.outputs.cache-hit != 'true'
4349
run: "yarn build:native"
4450
env:
4551
SQLCIPHER_STATIC: ${{ inputs.sqlcipher == 'static' && '1' || '' }}

.github/workflows/build_macos.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This workflow relies on actions/cache to store the hak dependency artifacts as they take a long time to build
2+
# Due to this extra care must be taken to only ever run all build_* scripts against the same branch to ensure
3+
# the correct cache scoping, and additional care must be taken to not run untrusted actions on the develop branch.
14
on:
25
workflow_call:
36
jobs:
@@ -11,13 +14,15 @@ jobs:
1114
name: webapp
1215

1316
- name: Cache .hak
17+
id: cache
1418
uses: actions/cache@v3
1519
with:
16-
key: ${{ hashFiles('./yarn.lock') }}
20+
key: ${{ runner.os }}-${{ hashFiles('hakDependencies.json', 'electronVersion') }}
1721
path: |
1822
./.hak
1923
2024
- name: Install Rust
25+
if: steps.cache.outputs.cache-hit != 'true'
2126
uses: actions-rs/toolchain@v1
2227
with:
2328
toolchain: stable
@@ -32,6 +37,7 @@ jobs:
3237
run: "yarn install --pure-lockfile"
3338

3439
- name: Build Natives
40+
if: steps.cache.outputs.cache-hit != 'true'
3541
run: "yarn build:native:universal"
3642

3743
- name: Build App

.github/workflows/build_prepare.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ jobs:
2626
- name: Fetch Element Web
2727
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
2828

29+
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
30+
- name: Generate cache hash files
31+
run: |
32+
yarn run --silent electron --version > electronVersion
33+
cat package.json | jq -c .hakDependencies > hakDependencies.json
34+
2935
- uses: actions/upload-artifact@v3
3036
with:
3137
name: webapp
3238
retention-days: 1
3339
path: |
3440
webapp.asar
3541
package.json
42+
electronVersion
43+
hakDependencies.json

.github/workflows/build_windows.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This workflow relies on actions/cache to store the hak dependency artifacts as they take a long time to build
2+
# Due to this extra care must be taken to only ever run all build_* scripts against the same branch to ensure
3+
# the correct cache scoping, and additional care must be taken to not run untrusted actions on the develop branch.
14
on:
25
workflow_call:
36
inputs:
@@ -32,9 +35,10 @@ jobs:
3235
name: webapp
3336

3437
- name: Cache .hak
38+
id: cache
3539
uses: actions/cache@v3
3640
with:
37-
key: ${{ runner.os }}-${{ hashFiles('./yarn.lock') }}
41+
key: ${{ runner.os }}-${{ hashFiles('hakDependencies.json', 'electronVersion') }}
3842
path: |
3943
./.hak
4044
@@ -58,6 +62,7 @@ jobs:
5862
echo "C:/Program Files/NASM" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
5963
6064
- name: Install Rust
65+
if: steps.cache.outputs.cache-hit != 'true'
6166
uses: actions-rs/toolchain@v1
6267
with:
6368
toolchain: stable
@@ -72,6 +77,7 @@ jobs:
7277
run: "yarn install --pure-lockfile"
7378

7479
- name: Build Natives
80+
if: steps.cache.outputs.cache-hit != 'true'
7581
run: |
7682
refreshenv
7783
yarn build:native --target ${{ steps.config.outputs.target }}

0 commit comments

Comments
 (0)