Skip to content

Commit 2e13f85

Browse files
Cache yarn files (#815)
1 parent eb985a6 commit 2e13f85

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,49 @@ jobs:
4646
- name: Run twine checker
4747
run: |
4848
twine check dist/*
49+
50+
yarn_build:
51+
permissions:
52+
contents: read # to fetch code (actions/checkout)
53+
54+
name: Build JS with Yarn
55+
runs-on: ubuntu-latest
56+
timeout-minutes: 5
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
- name: Install yarn
61+
run: sudo apt install yarn -y
62+
- name: Get yarn cache dir
63+
run: echo "yarn_cache=$(yarn cache dir)" >> "$GITHUB_ENV"
64+
- name: Cache node modules
65+
uses: actions/cache@v3
66+
id: cache-modules
67+
with:
68+
key: node-${{ hashFiles('admin-js/package.json') }}-${{ github.run_id }}
69+
restore-keys: node-${{ hashFiles('admin-js/package.json') }}
70+
path: |
71+
${{ env.yarn_cache }}
72+
admin-js/node_modules
73+
- name: Yarn install
74+
run: yarn install
75+
working-directory: admin-js/
76+
- name: Cache output files
77+
uses: actions/cache@v3
78+
id: cache_admin_js
79+
with:
80+
key: yarn-${{ hashFiles('admin-js/src/*') }}-${{ hashFiles('admin-js/yarn.lock') }}
81+
path: |
82+
aiohttp_admin/static/admin.js
83+
aiohttp_admin/static/*.map
84+
- name: Yarn build
85+
if: steps.cache_admin_js.outputs.cache-hit != 'true'
86+
run: yarn build
87+
working-directory: admin-js/
88+
4989
test:
5090
name: Test
91+
needs: yarn_build
5192
strategy:
5293
matrix:
5394
pyver: ['3.9', '3.10', '3.11', '3.12']
@@ -65,14 +106,14 @@ jobs:
65106
python-version: ${{ matrix.pyver }}
66107
cache: 'pip'
67108
cache-dependency-path: '**/requirements*.txt'
68-
- name: Install yarn
69-
run: sudo apt install yarn -y
70-
- name: Yarn install
71-
run: yarn install
72-
working-directory: admin-js/
73-
- name: Yarn build
74-
run: yarn build
75-
working-directory: admin-js/
109+
- name: Restore cached JS files
110+
uses: actions/cache/restore@v3
111+
with:
112+
key: yarn-${{ hashFiles('admin-js/src/*') }}
113+
fail-on-cache-miss: true
114+
path: |
115+
aiohttp_admin/static/admin.js
116+
aiohttp_admin/static/*.map
76117
- name: Install dependencies
77118
uses: py-actions/py-dependency-install@v4
78119
with:

0 commit comments

Comments
 (0)