我正在尝试遵循如何使用 GitHub Actions 构建矩阵将工件部署到多个服务器教程。我已经完成了本教程的一半,但是在构建应用程序时出现以下错误。
Error when evaluating 'strategy' for job 'prepare-release-on-servers'. (Line: 53, Col: 17): Error reading JToken from JsonReader. Path '', line 0, position 0.,(Line: 53, Col: 17): Unexpected value ''
我检查了 JSON 文件以进行验证,并无数次检查了部署文件。
这是 deploy-application.yml 文件。
name: Deploy Application
on:
push:
branches:
- main
jobs:
create-deployment-artifacts:
name: Create deployment artifacts
runs-on: ubuntu-latest
outputs:
deployment-matrix: ${{ steps.export-deployment-matrix.outputs.deployment-matrix }}
steps:
- uses: actions/checkout@v2
- name: Compile CSS and Javascript
run: |
npm install
npm run prod
- name: Configure PHP 8.0
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
- name: composer install
run: |
composer install --no-dev --no-interaction --prefer-dist
- name: Create deployment artifact
env:
GITHUB_SHA: ${{ github.sha }}
run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests *
- name: Store artifact for distribution
uses: actions/upload-artifact@v2
with:
name: app-build
path: ${{ github.sha }}.tar.gz
- name: Export deployment matrix
id: export-deployment-matrix
run: |
JSON="$(cat ./deployment-config.json)"
JSON="${JSON//'%'/'%25'}"
JSON="${JSON//$'\n'/'%0A'}"
JSON="${JSON//$'\r'/'%0D'}"
echo "::set-output name=deployment-matrix::$(echo $JSON)"
prepare-release-on-servers:
name: "${{ matrix.server.name }}: Prepare release"
runs-on: ubuntu-latest
needs: create-deployment-artifacts
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
steps:
- uses: actions/download-artifact@v2
with:
name: app-build
这是 JSON 文件。
[{"name":"server-1","ip":"216.656.30.240","username":"root","password":"sdddssafilgwzxcxvgvggfdassa","port":"22","beforeHooks":"","afterHooks": "","path": "/var/www/html" }]
我在这里找不到问题。你能帮忙的话,我会很高兴。提前致谢。