Github 操作 - CI 由于构建工件而卡住(将打字稿转换为 javascript)
Github actions - CI is stuck because of build artifacts (to convert typescript to javascript)
我正在尝试将我的打字稿文件转换为我的 github 操作管道上的 javascript 文件。我正在使用 Node.js/Express.js 和 typescript.
问题
CI 卡在步骤“ 安装依赖项并将打字稿转换为 javascript”。看起来它有效,因为我可以看到 console.log() ,但 CI 不会完成。这是为什么?
这是我的package.json:
npm 运行 convert 将 typescript 转换为 javascript 文件到 backend-build 文件夹 。 backend-build文件夹包含转换后的js文件。 backend-build 文件夹 未在存储库中跟踪,因为它们是来自 npm 运行 convert 的编译文件(即工件)。
我 运行 每当我启动我的服务器时。
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "backend-build/index.js",
"scripts": {
"tsc": "tsc",
"convert:build": "tsc -w",
"convert:run": "nodemon backend-build/index.js",
"convert": "concurrently npm:convert:*",
"start": " node backend-build/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"concurrently": "^5.3.0"
},
"dependencies": {
"@types/cors": "^2.8.8",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.8",
"@types/pg": "^7.14.7",
"backblaze-b2": "^1.7.0",
"cors": "^2.8.5",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"multer": "^1.4.3",
"nodemon": "^2.0.6",
"pg": "^8.5.1",
"typescript": "^4.0.5"
}
}
这是我的打字稿文件 (index.ts):
import express from "express";
import dotenv from "dotenv";
import cors from "cors";
if (process.env.NODE_ENV !== "production") {
dotenv.config();
}
const app = express();
// middleware for parsing bodies from URL
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors({ origin: true, credentials: true }));
console.log("NODE ENV", process.env.privateKey);
app.use("/api/test", (req, res) => {
res.send("hi");
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`App running on port ${port}.`);
});
这是我的 main.yml 的 Github 操作:
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 #deploys to heroku
- uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "app" #Must be unique in Heroku
heroku_email: "a.com"
- name: install dependencies & convert typescript to javascript
run: |
npm install
npm run convert
CI/问题的输出(卡在这一步)
Run npm install
npm install
npm run convert
shell: /usr/bin/bash -e {0}
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
> nodemon@2.0.15 postinstall /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/node_modules/nodemon
> node bin/postinstall || exit 0
npm WARN backend@1.0.0 No description
npm WARN backend@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 294 packages from 222 contributors and audited 296 packages in 27.56s
22 packages are looking for funding
run `npm fund` for details
found 4 moderate severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
> backend@1.0.0 convert /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
> concurrently npm:convert:*
[convert:build]
[convert:build] > backend@1.0.0 convert:build /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:build] > tsc -w
[convert:build]
[convert:run]
[convert:run] > backend@1.0.0 convert:run /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:run] > nodemon backend-build/index.js
[convert:run]
[convert:run] [nodemon] 2.0.15
[convert:run] [nodemon] to restart at any time, enter `rs`
[convert:run] [nodemon] watching path(s): *.*
[convert:run] [nodemon] watching extensions: js,mjs,json
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] internal/modules/cjs/loader.js:905
[convert:run] throw err;
[convert:run] ^
[convert:run]
[convert:run] Error: Cannot find module '/home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/backend-build/index.js'
[convert:run] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
[convert:run] at Function.Module._load (internal/modules/cjs/loader.js:746:27)
[convert:run] at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[convert:run] at internal/main/run_main_module.js:17:47 {
[convert:run] code: 'MODULE_NOT_FOUND',
[convert:run] requireStack: []
[convert:run] }
[convert:run] [nodemon] app crashed - waiting for file changes before starting...
[convert:build] c3:28:10 AM - Starting compilation in watch mode...
[convert:build]
[convert:build]
[convert:build] 3:28:12 AM - Found 0 errors. Watching for file changes.
[convert:run] [nodemon] restarting due to changes...
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] NODE ENV undefined
[convert:run] App running on port 5000.
使用的资源:https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts
由于 -w(监视)指令,作业保持“打开”状态。你不想在你的 CI 作业上使用 watch 除非你也正在做一些事情来杀死被监视的进程。
错误表明您的路径不正确,因此它尝试 运行 tsc -w
,然后未能在给定路径 (./gh_actions_heroku_backend/gh_actions_heroku_backend
) 中找到任何内容,然后停留由于 watch 指令而“打开”。
我正在尝试将我的打字稿文件转换为我的 github 操作管道上的 javascript 文件。我正在使用 Node.js/Express.js 和 typescript.
问题
CI 卡在步骤“ 安装依赖项并将打字稿转换为 javascript”。看起来它有效,因为我可以看到 console.log() ,但 CI 不会完成。这是为什么?
这是我的package.json:
npm 运行 convert 将 typescript 转换为 javascript 文件到 backend-build 文件夹 。 backend-build文件夹包含转换后的js文件。 backend-build 文件夹 未在存储库中跟踪,因为它们是来自 npm 运行 convert 的编译文件(即工件)。
我 运行 每当我启动我的服务器时。
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "backend-build/index.js",
"scripts": {
"tsc": "tsc",
"convert:build": "tsc -w",
"convert:run": "nodemon backend-build/index.js",
"convert": "concurrently npm:convert:*",
"start": " node backend-build/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"concurrently": "^5.3.0"
},
"dependencies": {
"@types/cors": "^2.8.8",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.8",
"@types/pg": "^7.14.7",
"backblaze-b2": "^1.7.0",
"cors": "^2.8.5",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"multer": "^1.4.3",
"nodemon": "^2.0.6",
"pg": "^8.5.1",
"typescript": "^4.0.5"
}
}
这是我的打字稿文件 (index.ts):
import express from "express";
import dotenv from "dotenv";
import cors from "cors";
if (process.env.NODE_ENV !== "production") {
dotenv.config();
}
const app = express();
// middleware for parsing bodies from URL
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors({ origin: true, credentials: true }));
console.log("NODE ENV", process.env.privateKey);
app.use("/api/test", (req, res) => {
res.send("hi");
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`App running on port ${port}.`);
});
这是我的 main.yml 的 Github 操作:
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 #deploys to heroku
- uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "app" #Must be unique in Heroku
heroku_email: "a.com"
- name: install dependencies & convert typescript to javascript
run: |
npm install
npm run convert
CI/问题的输出(卡在这一步)
Run npm install
npm install
npm run convert
shell: /usr/bin/bash -e {0}
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
> nodemon@2.0.15 postinstall /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/node_modules/nodemon
> node bin/postinstall || exit 0
npm WARN backend@1.0.0 No description
npm WARN backend@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 294 packages from 222 contributors and audited 296 packages in 27.56s
22 packages are looking for funding
run `npm fund` for details
found 4 moderate severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
> backend@1.0.0 convert /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
> concurrently npm:convert:*
[convert:build]
[convert:build] > backend@1.0.0 convert:build /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:build] > tsc -w
[convert:build]
[convert:run]
[convert:run] > backend@1.0.0 convert:run /home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend
[convert:run] > nodemon backend-build/index.js
[convert:run]
[convert:run] [nodemon] 2.0.15
[convert:run] [nodemon] to restart at any time, enter `rs`
[convert:run] [nodemon] watching path(s): *.*
[convert:run] [nodemon] watching extensions: js,mjs,json
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] internal/modules/cjs/loader.js:905
[convert:run] throw err;
[convert:run] ^
[convert:run]
[convert:run] Error: Cannot find module '/home/runner/work/gh_actions_heroku_backend/gh_actions_heroku_backend/backend-build/index.js'
[convert:run] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
[convert:run] at Function.Module._load (internal/modules/cjs/loader.js:746:27)
[convert:run] at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[convert:run] at internal/main/run_main_module.js:17:47 {
[convert:run] code: 'MODULE_NOT_FOUND',
[convert:run] requireStack: []
[convert:run] }
[convert:run] [nodemon] app crashed - waiting for file changes before starting...
[convert:build] c3:28:10 AM - Starting compilation in watch mode...
[convert:build]
[convert:build]
[convert:build] 3:28:12 AM - Found 0 errors. Watching for file changes.
[convert:run] [nodemon] restarting due to changes...
[convert:run] [nodemon] starting `node backend-build/index.js backend-build/index.js`
[convert:run] NODE ENV undefined
[convert:run] App running on port 5000.
使用的资源:https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts
由于 -w(监视)指令,作业保持“打开”状态。你不想在你的 CI 作业上使用 watch 除非你也正在做一些事情来杀死被监视的进程。
错误表明您的路径不正确,因此它尝试 运行 tsc -w
,然后未能在给定路径 (./gh_actions_heroku_backend/gh_actions_heroku_backend
) 中找到任何内容,然后停留由于 watch 指令而“打开”。