我正在撰寫一個將在一些存盤庫中使用的自定義操作。它從一個 openapi 檔案生成一個 TS 客戶端并構建它。該問題僅發生 25% 的時間,重新運行最終會解決失敗的運行。有時,npm ioryarn install命令會靜默失敗并且不會安裝任何 node_modules。然后在運行 orval 二進制檔案時,找不到該檔案并出現錯誤(npm run orval 等也失敗)。它與特定軟體包無關,因為所有二進制檔案都丟失了。事實上,yarn install當它出錯時幾乎立即執行,但在它作業時不會。我完全不知道是什么讓這個變得如此脆弱。
更新:我嘗試使用jq而不是下面使用的json命令。但我仍然有一個問題。第二個檔案丟失。我的命令看起來像jq -s '.[0] * .[1]' ./file1.json ./dir/file2.json,錯誤是jq: error (at client/package.json:9): object ({"author":"...) and null (null) cannot be multiplied.
name: 'Generate Client'
description: 'Generates a package from a source openapi.yaml file.'
author: ''
inputs:
API_NAME:
description: 'Name of the API'
required: true
API_TARGET_NAME:
description: 'API name to use for the schemas output target'
required: true
runs:
using: 'composite'
steps:
# Checkout generator repo
- uses: actions/checkout@v3
with:
repository: InformaticsMatters/openapi-js-client-generator
branch: main
- run: cat yarn.lock
shell: bash
- uses: actions/checkout@v3
with:
path: "./client"
# We need Node 16
- uses: actions/setup-node@v2
with:
node-version: 16
# Get the openapi.yaml file
- run: |
curl -H "Private-Token: ${GITLAB_API_TOKEN}" ${GITLAB_API}/${GITLAB_PROJECT}/repository/files/${OPENAPI_PATH}/${OPENAPI_FILE}/raw?ref=${CI_COMMIT_TAG} --output ${OPENAPI_FILE}
tail ${OPENAPI_FILE}
cat ${OPENAPI_FILE} | wc -l
shell: bash
- run: npm i --location=global json
shell: bash
- run: cat package.json client/package.json | json --deep-merge | tee package.json
shell: bash
- run: |
sed -i s/'ORVAL_API_NAME'/'"'${{ inputs.API_NAME }}'"'/ orval.config.ts
sed -i s/'API_TARGET_NAME'/''${{ inputs.API_TARGET_NAME }}''/ orval.config.ts
sed -i s/'API_TARGET_NAME'/${{ inputs.API_TARGET_NAME }}/ src/index.ts
shell: bash
- run: yarn
shell: bash
- run: pwd
shell: bash
- run: ls ./node_modules/.bin
shell: bash
- run: |
./node_modules/.bin/orval
./node_modules/.bin/tsup
ls dist/
node setup-entrypoints.js
shell: bash
uj5u.com熱心網友回復:
您不得從兩個不同的行程讀取和寫入單個檔案:
cat package.json client/package.json | json --deep-merge | tee package.json
這很可能無法按預期作業(類似于cmd <file >file導致空檔案的方式)。
你應該怎么做:
cat package.json client/package.json | json --deep-merge | tee package.json.tmp
mv package.json.tmp package.json
或者可能
cat package.json client/package.json | json --deep-merge > package.json.tmp
tee package.json < package.json.tmp
還有GNUsponge可能會有所幫助,但通常并非在所有系統上都可用:
cat package.json client/package.json | json --deep-merge | sponge package.json
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/506663.html
