GitHub Actions中publish-storybook作业条件触发失败问题排查
问题原因及修复方案
问题出在release作业没有对外暴露published输出值。虽然你在release作业的步骤里能拿到steps.changesets.outputs.published,但这个输出仅在当前作业内部有效,其他作业无法直接通过needs.release.outputs.published访问,除非你显式把它声明为作业级别的输出。
修复步骤
- 在
release作业中添加outputs字段,将changesets步骤的published输出暴露为作业级输出 - 保持
publish-storybook作业的条件判断不变,此时就能正确获取到release作业的输出值
修改后的完整配置
name: Release on: push: branches: [main] concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: release: name: Release runs-on: ubuntu-latest # 新增作业级输出,暴露changesets的published结果 outputs: published: ${{ steps.changesets.outputs.published }} steps: - name: Checkout Repo uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3.2.0 with: node-version-file: ".nvmrc" cache: "yarn" - name: Install Dependencies run: yarn install - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 with: publish: yarn release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }} - name: Send a message if a publish happens if: steps.changesets.outputs.published == 'true' run: echo "A new version of ${GITHUB_REPOSITORY} was published!" publish-storybook: name: Publish Storybook runs-on: ubuntu-latest needs: release if: needs.release.outputs.published == 'true' steps: - name: Checkout Repo uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3.2.0 with: node-version-file: ".nvmrc" cache: "yarn" - name: Install Dependencies run: yarn install - name: Storybook deploy env: GH_TOKEN: ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} run: yarn storybook:deploy
关键说明
- 作业级输出需要在作业根节点声明
outputs,引用内部步骤的输出值 - 其他作业通过
needs.<作业名>.outputs.<输出名>的方式访问该值 - 原步骤中的条件判断
if: steps.changesets.outputs.published == 'true'能正常工作,是因为它在release作业内部,直接访问步骤输出
内容的提问来源于stack exchange,提问作者Tomasz Mularczyk
相关产品推荐
相关产品推荐

