英文:
GitHub action runner can't find node modules after npm ci
问题
这是您提供的GitHub Action工作流程中的一部分代码。以下是代码的翻译:
name: deploy-cdk
on:
workflow_call:
inputs:
service-name:
description: '要构建和发布的服务名称'
type: string
required: true
image-version:
description: '发布镜像的版本'
type: string
required: true
infra-directory:
description: 'cdk项目的位置'
type: string
required: true
target-account:
description: '发布镜像的帐户'
type: string
required: false
default: main
environment:
description: '帐户的环境'
type: string
required: false
default: staging
target-region:
description: '发布镜像的区域'
type: string
required: false
default: us-east-1
stub:
description: '目标帐户的简称'
type: string
required: false
default: m
jobs:
deploy:
name: ${{ inputs.service-name }} 部署 ${{ inputs.environment }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置Node.js环境
uses: private-action/setup-node-action@v1
with:
node-version: 18.x
auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
- name: 清除安装
run: npm ci
- name: 安装CDK
run: npm i -g aws-cdk && cdk --version
- name: 构建基础设施
run: npm run build -w cdk
- name: 配置AWS凭据
uses: private-action/configure-aws-for-deploy-action@v1
with:
target-account: ${{ inputs.target-account }}
aws-region: ${{ inputs.target-region }}
- name: 为 ${{ inputs.service-name }} 设置环境变量
uses: private-action/json-to-env@v1
with:
file-path: '.github/configs/${{ inputs.service-name }}/${{ inputs.stub }}-${{ inputs.environment }}.${{ inputs.target-region }}.json'
- name: 合成 ${{ inputs.service-name }} ${{ inputs.environment }} 栈
run: npm run cdk -w cdk -- synth -q
env:
IMAGE_VERSION: ${{ inputs.image-version }}
- name: 部署 ${{ inputs.service-name }} ${{ inputs.environment }} 栈
run: npm run cdk -w cdk -- deploy --require-approval never
希望这对您有所帮助。如果有其他问题,请随时提出。
英文:
I'm running a GitHub action that makes use of aws-cdk to deploy to the cloud. I'm running this workflow in a repo that has multiple workspaces, exclusively in Typescript. The infra workspace is called cdk
- it contains all of the cdk files to deploy resources to the cloud. This is my workflow:
name: deploy-cdk
on:
workflow_call:
inputs:
service-name:
description: 'name of service to build and publish'
type: string
required: true
image-version:
description: 'version of published image'
type: string
required: true
infra-directory:
description: 'location of the cdk project'
type: string
required: true
target-account:
description: 'account to publish image'
type: string
required: false
default: main
environment:
description: 'environment of account'
type: string
required: false
default: staging
target-region:
description: 'region to publish image'
type: string
required: false
default: us-east-1
stub:
description: 'short name of target account'
type: string
required: false
default: m
jobs:
deploy:
name: ${{ inputs.service-name }} deploy ${{ inputs.environment }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: checkout code
uses: actions/checkout@v3
- name: setup node
uses: private-action/setup-node-action@v1
with:
node-version: 18.x
auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
- name: clean install
run: npm ci
- name: install cdk
run: npm i -g aws-cdk && cdk --version
- name: build infra
run: npm run build -w cdk
- name: configure aws credentials
uses: private-action/configure-aws-for-deploy-action@v1
with:
target-account: ${{ inputs.target-account }}
aws-region: ${{ inputs.target-region }}
- name: set environment variables for ${{ inputs.service-name }}
uses: private-action/json-to-env@v1
with:
file-path: '.github/configs/${{ inputs.service-name }}/${{ inputs.stub }}-${{ inputs.environment }}.${{ inputs.target-region }}.json'
- name: synth ${{ inputs.service-name }} ${{ inputs.environment }} stack
run: npm run cdk -w cdk -- synth -q
env:
IMAGE_VERSION: ${{ inputs.image-version }}
- name: deploy ${{ inputs.service-name }} ${{ inputs.environment }} stack
run: npm run cdk -w cdk -- deploy --require-approval never
The current issue is that when I run this workflow, everything works until I run cdk synth
. For some reason, some packages that I installed in the clean install
step do not show up (namely aws-cdk-lib
). This is an issue, because I built the workspace in a prior step and it should have failed the build if that module could not be found. I'm very lost on what to do to fix this. Any ideas why this is the case? Here is the error I'm getting:
> cdk synth -q
npm WARN exec The following package was not found and will be installed: ts-node@10.9.1
/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
Error: bin/cdk.ts(1,22): error TS2307: Cannot find module 'aws-cdk-lib' or its corresponding type declarations.
Error: bin/cdk.ts(3,29): error TS2307: Cannot find module '@private-action/library' or its corresponding type declarations.
at createTSError (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Object.require.extensions.<computed> [as .ts] (/home/runner/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Function.Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticCodes: [ 2307, 2307 ]
}
答案1
得分: 0
Holy cow, gotta remember to check every piece of code when things behave abnormally. Turns out that in one of the actions I was referencing, it was calling actions/checkout@v3
after I had ran npm ci
, and that cleared out all of my installations.
Specifically, this action here:
- name: set environment variables for ${{ inputs.service-name }}
uses: private-action/json-to-env@v1
with:
file-path: '.github/configs/...'
I forked and modified the action that was performing a checkout. Everything is behaving as expected now. Just make sure to check any actions that you call and make sure they behave how you expect them to.
英文:
Holy cow, gotta remember to check every piece of code when things behave abnormally. Turns out that in one of the actions I was referencing, it was calling actions/checkout@v3
after I had ran npm ci
, and that cleared out all of my installations.
Specifically, this action here:
- name: set environment variables for ${{ inputs.service-name }}
uses: private-action/json-to-env@v1
with:
file-path: '.github/configs/...'
I forked and modified the action that was performing a checkout. Everything is behaving as expected now. Just make sure to check any actions that you call and make sure they behave how you expect them to.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论