5 github typescript github-actions building-github-actions
我正在为 Marketplace 做一个自定义 GitHub Action,以使其更容易在其他项目中使用。
该 Action 是用 TypeScript 制作的,并使用了一些包,例如typescript、babel(编辑:不再使用 babel)@actions/core和@actions/github。
当我将Action添加到另一个项目的工作流程中时,他可以安装包并构建项目,甚至初始化它,但是当执行开始时,他找不到@actions模块,并且@actions/core的核心未定义( @actions/core 是第一个使用的包,因此,它导致管道崩溃)。
该node_modules文件夹已正确创建,包位于其中,但在脚本内,它们未加载。
当我尝试在我的计算机上运行构建版本(构建器版本,带有 ncc 的版本和带有 tsc 的版本)时,会发生同样的错误:
TypeError: Cannot read property 'getInput' of undefined
Run Code Online (Sandbox Code Playgroud)
编辑:问题是包的导入不正确@actions/core
为了能够安装软件包并构建,我必须在我的action.yml文件中执行以下操作:
TypeError: Cannot read property 'getInput' of undefined
Run Code Online (Sandbox Code Playgroud)
我的文件夹结构:
|-dist # THIS IS'NT BEING PUSHED TO THE REPO
|-src
|--index.ts # Where the @actions/core is required
|--... # More files that are imported by index.ts
|-node_modules # THIS IS'NT BEING PUSHED TO THE REPO
|--... # All the packages are here, this is right and ISN'T THE PROBLEM
|-action.yml
|-babel.config.js
|-package.json
|-tsconfig.json
|-yarn.lock
Run Code Online (Sandbox Code Playgroud)
使用我上面发送的action.yml,返回以下错误:
TypeError: Cannot read property 'getInput' of undefined
Run Code Online (Sandbox Code Playgroud)
getInput是一种方法@actions/core(正在正确导入并且不是问题)
编辑:这就是问题哈哈哈。
如果我不运行yarn install或npm install使用某些脚本,则会发生以下错误:
Error: Cannot find module '@actions/core'
Run Code Online (Sandbox Code Playgroud)
在我看到的教程中,他们都不需要安装软件包,就像它们是自动安装的一样。
我还尝试使用ncc并将编译后的代码推送到操作存储库,但它也不起作用。
我的action.yml:
runs:
using: "composite"
steps:
- run: cd ${{ github.action_path }}
shell: bash
- run: yarn --cwd ${{ github.action_path }} --production=true
shell: bash
- run: yarn --cwd ${{ github.action_path }} build
shell: bash
- run: yarn --cwd ${{ github.action_path }} start
shell: bash
Run Code Online (Sandbox Code Playgroud)
我的文件夹结构:
|-src
|--index.ts # Where the @actions/core is required
|--... # More files that are imported by index.ts
|-node_modules # THIS IS'NT BEING PUSHED TO THE REPO
|--... # All the packages are here, this is right and ISN'T THE PROBLEM
|-action.yml
|-index.js # The compiled code, that is being pushed to the repo
|-package.json
|-tsconfig.json
|-yarn.lock
Run Code Online (Sandbox Code Playgroud)
使用上面的配置,会发生同样的错误:
TypeError: Cannot read property 'getInput' of undefined
Run Code Online (Sandbox Code Playgroud)
这就是我@actions/core在第一行中导入的方式src/index.ts:
import core from "@actions/core";
Run Code Online (Sandbox Code Playgroud)
小智 5
我终于发现了问题所在。
要在 TypeScript 中使用@actions/core,这是导入它的正确方法:
import * as core from "@actions/core"
Run Code Online (Sandbox Code Playgroud)
你需要放一个* as.
很抱歉我在问题描述中提供了不正确的信息,我确信我以正确的方式导入它。
有关该项目的更多详细信息,这是我的行动
| 归档时间: |
|
| 查看次数: |
5022 次 |
| 最近记录: |