Skip to content

Commit 28cebc5

Browse files
committed
chore: nx cache
1 parent eaa9e62 commit 28cebc5

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

.github/workflows/auto-review.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v4
15+
- name: 保存当前 SHA
16+
run: echo "${{ github.sha }}" > previous_sha.txt
17+
- name: 更新 previous_sha.txt 缓存
18+
uses: actions/cache/save@v4
19+
with:
20+
path: previous_sha.txt
21+
key: ${{ github.ref_name }}-previous_sha
1522
- name : GITHUB CONTEXT
1623
env:
1724
GITHUB_CONTEXT: ${{ toJson(github) }}

.github/workflows/merged.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/cache/restore@v4
2929
with:
3030
path: .nx
31-
key: NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.ref_name }}-${{ github.sha }}
31+
key: ${{ github.ref_name }}-NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
3232

3333
- name: 更新 NX 缓存
3434
uses: actions/cache/save@v4

.github/workflows/nodejs.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,21 @@ jobs:
7878
node-version: ${{ matrix.node-version }}
7979
cache: 'pnpm'
8080

81-
- name: 获取上一次提交的 SHA
82-
run: echo "PREV_SHA=$(git rev-parse HEAD^)" >> $GITHUB_ENV
81+
- name: 获取上次提交 SHA
82+
uses: actions/cache/restore@v4
83+
with:
84+
path: previous_sha.txt
85+
key: ${{ github.ref_name }}-previous_sha
86+
- name: 读取 SHA 文件
87+
id: read_previous
88+
run: echo "previous_sha=$(cat previous_sha.txt)" >> $GITHUB_OUTPUT
8389
- name: 使用 NX 缓存
8490
uses: actions/cache/restore@v4
8591
with:
8692
path: .nx
87-
key: NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.ref_name }}-${{ env.PREV_SHA }}
93+
key: ${{ github.ref_name }}-NX-${{ runner.os }}-${{ matrix.node-version }}-${{ steps.read_previous.outputs.previous_sha }}
8894
restore-keys: |
89-
NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.ref_name }}-
95+
${{ github.ref_name }}-NX-${{ runner.os }}-${{ matrix.node-version }}-
9096
NX-${{ runner.os }}-${{ matrix.node-version }}
9197
9298
- name: Prune store
@@ -130,14 +136,14 @@ jobs:
130136
# 部分测试依赖使用 moduleNameMapper 映射,破坏了 NX 的依赖视图,但若加入 package.json 又会造成循环依赖
131137
# actions/checkout 需要设置 fetch-depth: 0 获取所有的 commit 历史才能正确计算 affected,非常耗时
132138
- name: 构建、测试
133-
run: pnpm nx run-many -t prod test:ci --exclude @tarojs/cli @tarojs/tests --parallel=3 && pnpm --filter=@tarojs/cli prod && pnpm --filter=@tarojs/cli --filter=@tarojs/tests test:ci
139+
run: pnpm nx run-many -t prod test:ci --exclude @tarojs/tests --parallel=3 && pnpm --filter=@tarojs/tests test:ci
134140

135141
- name: 更新 NX 缓存
136-
if: ${{ always() }}
142+
if: always()
137143
uses: actions/cache/save@v4
138144
with:
139145
path: .nx
140-
key: NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.ref_name }}-${{ github.sha }}
146+
key: ${{ github.ref_name }}-NX-${{ runner.os }}-${{ matrix.node-version }}-${{ github.sha }}
141147

142148
# 以下 coverage 流程通过 artifact 拆分文件作为单独 job 上传时间损耗过长,因此在 node test 后直接继续执行
143149
- name: Upload [taro-cli] coverage to Codecov

0 commit comments

Comments
 (0)