-
Notifications
You must be signed in to change notification settings - Fork 66
91 lines (76 loc) · 2.35 KB
/
ci-js.yml
File metadata and controls
91 lines (76 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: CI - JS testing
on:
workflow_dispatch:
pull_request:
paths:
- 'app/javascript/**'
- 'package.json'
- 'yarn.lock'
- 'spec/javascripts/**'
- '.tool-versions'
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
# strategy:
# matrix:
# node-version: [22.20.0]
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v5
with:
ref: main
path: tmp/main
fetch-depth: 1
- name: Setup Nodejs
id: setup_node
uses: actions/setup-node@v5
with:
node-version-file: .tool-versions
#node-version: ${{ matrix.node-version }}
- name: compute cache key based on main's yarn.lock
id: cache_key
run: |
echo "key=${{ steps.setup_node.outputs.node-version }}-${{ hashFiles('tmp/main/yarn.lock') }}" >> $GITHUB_OUTPUT
- name: Enable Corepack (Yarn)
run: corepack enable
# Figure out Yarn cache directory (works for v1 and v2+/Berry)
- name: Detect Yarn cache dir
id: yarndir
run: |
if yarn --version | grep -q '^1\.'; then
DIR="$(yarn cache dir)"
else
DIR="$(yarn config get cacheFolder)"
fi
echo "dir=$DIR" >> $GITHUB_OUTPUT
# ---- Restore-only on PRs & pushes ----
- name: Restore dependency cache (from main)
uses: actions/cache/restore@v4
with:
path: ${{ steps.yarndir.outputs.dir }}
key: ${{ steps.cache_key.outputs.key }}
# Optional: allow fallback to previous main caches if hash changed recently
restore-keys: |
${{ steps.setup_node.outputs.node-version }}-
- name: Install deps
run: |
if yarn --version | grep -q '^1\.'; then
yarn install --frozen-lockfile
else
yarn install --immutable
fi
# ---- Save cache only on main branch pushes ----
- name: Save dependency cache (update main cache)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: ${{ steps.yarndir.outputs.dir }}
key: ${{ steps.cache_key.outputs.key }}
- name: Tests
run: yarn test