npm Github Action在创建和发布的版本之间存在差异

b1zrtrql  于 12个月前  发布在  Git
关注(0)|答案(4)|浏览(115)

由于 Github Releases实际上是一个 Git Tags,我想在有新的Release(和Tag)时使用 Github Action 自动升级我的package.json版本。
我知道我需要触发一个jobon: release,但是根据Github Actions文档,我不知道我是否需要在createdpublished,两者或全部时触发?
Github说:

注意:draft版本不会触发release事件。

我创建了两个管道:一个on: release, type: created和一个on: release, type: published
然后我创建了一个draft版本,然后我发布了它。
只有published管道被触发了,而且是在我
发布**版本的时候。

q3qa4bjr

q3qa4bjr1#

我的经历与here on the forum所描述的相反。测试时:

  • 如果发布是通过/releases页面上的“Draft a new release”按钮创建的,则两个事件都将触发,因为发布状态从“draft”变为“published”。
  • 如果发布版本是由像release-it这样的脚本创建的,绕过“draft”阶段并直接成为“published”,则只有release:published会触发

因此,很明显,一个版本可以在没有创建的情况下发布。确实很奇怪我会选择published

3pvhb19x

3pvhb19x2#

如果你试图捕获从Github Action触发的发布到另一个工作流的创建和发布,那么它将无法工作。
解决方案是将两个工作流统一为一个工作流,以便在创建发布后继续下一个工作流。
来源:https://twitter.com/ethomson/status/1183838077166477316
范例:

name: Create Release and Publish

# Trigger the create release workflow
on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: false
          prerelease: false

  publish-gpr:
    needs: release # After release is created then run the second workflow
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 10
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
50few1ms

50few1ms3#

可以创建发布,但不能发布。这是一个关于“释放”的问题。
我建议使用published类型的版本。

sshcrbum

sshcrbum4#

我在这里查看了它们之间的差异:
https://docs.github.com/en/webhooks/webhook-events-and-payloads#release

这里有一个注解:https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release。

虽然文档没有明确说明,但我猜created应该只在GitHub浏览器UI上创建预发布/发布时生效。
这也符合得票最多的答案的结论。created必须经过草稿阶段才能触发。

相关问题