GitHub Actions如何引用ipfs-pin步骤输出执行命令并解决YAML语法错误
问题修复方案
1. 报错原因分析
- YAML缩进错误:GitHub Action的YAML配置严格要求2空格缩进,你现有配置中多处缩进不符合规范,包括
steps字段缩进层级错误、id: ipfs-pin下的with字段多缩进了一层、第二个Jobsaves-hash-on-file的整体缩进、内部steps的缩进都存在错误,这是触发36行语法报错的直接原因。 - 输出引用逻辑错误:你将构建部署和保存哈希拆成了两个独立Job,不同Job默认运行在完全隔离的runner环境中,无法直接引用另一个Job的步骤输出,同时你用的
steps.build.ipfs-pin.hash的引用格式也是错误的。
2. 正确实现方案
推荐直接把保存哈希的步骤合并到build Job中,既不需要处理跨Job传参,也能简化配置,修正后的完整配置如下:
name: deploy on: push: branches: [ main ] pull_request: branches: [ main ] workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - uses: jakejarvis/hugo-build-action@master with: args: --minify --buildDrafts - uses: anantaramdas/ipfs-pinata-deploy-action@v1.6.4 id: ipfs-pin with: pin-name: '[my-pin-name]' path: './public' # 秘钥请存到仓库Secrets中,不要直接写在配置里 pinata-api-key: ${{ secrets.PINATA_API_KEY }} pinata-secret-api-key: ${{ secrets.PINATA_SECRET_API_KEY }} verbose: true remove-old: true # 保存哈希到文件 - run: | # 提前创建目录避免不存在报错 mkdir -p .github echo ${{ steps.ipfs-pin.outputs.hash }} > .github/ipfs-hash.txt # 如需把哈希文件提交回仓库可以添加以下步骤 # - run: | # git config user.name "github-actions[bot]" # git config user.email "github-actions[bot]@users.noreply.github.com" # git add .github/ipfs-hash.txt # git commit -m "chore: update ipfs pin hash" # git push
同一个Job内引用id为ipfs-pin的步骤输出,直接使用${{ steps.ipfs-pin.outputs.hash }}格式即可,这是Pinata部署Action官方定义的输出字段。
内容的提问来源于stack exchange,提问作者Lakatoi
相关产品推荐
相关产品推荐

