You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions中publish-storybook作业条件触发失败问题排查

问题原因及修复方案

问题出在release作业没有对外暴露published输出值。虽然你在release作业的步骤里能拿到steps.changesets.outputs.published,但这个输出仅在当前作业内部有效,其他作业无法直接通过needs.release.outputs.published访问,除非你显式把它声明为作业级别的输出。

修复步骤

  1. 在release作业中添加outputs字段,将changesets步骤的published输出暴露为作业级输出
  2. 保持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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 14:06:20