我刚开始写 GH Actions。我正在完成一个任务,删除常用的工作流程并使用可重用的工作流程功能(reusable workflow feature)。现在我能够按顺序运行我的工作流程,这很棒。然而,第二个工作流程出现了意外的错误消息,似乎与 yarn 依赖项工作流程未保存到缓存有关,这让我感到困惑:
错误发生在“验证 Lint”作业中,因为似乎找不到缓存。我创建了“yarn”作业,以避免每个作业都重新创建轮子。
我的缓存期望与实际工作方式有什么问题?每个作业都需要执行“安装依赖项”步骤感觉过于繁琐。
请您看一下,确认这是否正常?目前,我的目标是创建一个 pull-request 工作流程,调用可重用功能中的 yarn 和 lint。执行 yarn lint ... snip myPackage: /bin/sh: 1: concurrently: not found
name: pull-request
on:
pull_request:
branches:
- main
jobs:
yarn:
uses: ./.github/workflows/yarn.yml
validate_lint:
needs: yarn
uses: ./.github/workflows/validate_lint.yml
使用:
name: Yarn
on:
workflow_call:
jobs:
yarn_and_deps:
name: Run Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Git repository
uses: actions/checkout@v3
- name: Enable node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn bootstrap
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
并且
name: Validate Lint
on:
workflow_call:
jobs:
run_lint:
name: Run Lint
runs-on: ubuntu-latest
- name: Enable node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn' # <<--- THIS CACHE IS NOT FOUND ♂️
# NOTE: if I add in all the "yarn cache/install" commands from above workflow, this passes.
steps:
- name: Validate Lint
run: yarn lint
错误发生在“验证 Lint”作业中,因为似乎找不到缓存。我创建了“yarn”作业,以避免每个作业都重新创建轮子。
我的缓存期望与实际工作方式有什么问题?每个作业都需要执行“安装依赖项”步骤感觉过于繁琐。
actions
提供的示例:https://github.com/actions/cache/blob/main/examples.md#node---yarn - Phil Lucks