首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Github动作跳过发布文件

Github动作跳过发布文件
EN

Stack Overflow用户
提问于 2022-07-23 19:05:17
回答 1查看 120关注 0票数 0

我拥有一个npm包,并决定创建Github操作来有效地自动化流程。

  • main.yml -句柄节点CI。在每次推到主分支时,该操作将安装依赖项并通过多个操作系统进行构建。
  • release.yml -需要发布一个新的版本给npm和Github发行版。它将触发以"v“开头的每个提交标记(例如,"v0.1.4")。

但是,当使用提交标记推送到git时,release.yml操作将被跳过。

如何触发release.yml文件?但是,还是要等待main.yml完成整个工作流吗?

我很感谢你的帮助。

main.yml行动:

代码语言:javascript
复制
name: Node Continous Integration

on: 
  push:
    branches: [master]

jobs:
  build:
    name: Build on Node ${{ matrix.node }} and ${{ matrix.os }}

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node: ['10.x', '12.x', '14.x']
        os: [ubuntu-latest, windows-latest, macOS-latest]

    steps:
      - name: Checkout repo
        uses: actions/checkout@v2

      - name: Use Node ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

      - name: Install deps and build (with cache)
        uses: bahmutov/npm-install@v1

      - name: Build
        run: npm run build

release.yml行动:

代码语言:javascript
复制
# Name of the workflow
name: Release new version

# Run on every commit tag which begins with "v" (e.g., "v0.1.4")
on:
  push:
    tags:
      - "v*"

jobs:
# Automatically publish a NPM release
  npm-publish:
    name: NPM Release
    runs-on: ubuntu-latest
    if: ${{ github.ref == 'refs/heads/master' }}
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
      - name: Use Node ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}
      - name: Install deps and build (with cache)
        uses: bahmutov/npm-install@v1
      - name: Publish
        run: npm publish
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# Automatically create a GitHub Release, with release details specified (the relevant commits)
  github-release:
    name: Github Release
    needs: [npm-publish]
    runs-on: ubuntu-latest
    if: ${{ github.ref == 'refs/heads/master' }}
    steps:
      - uses: "marvinpinto/action-automatic-releases@latest"
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          prerelease: false
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-23 21:00:21

问题在于你在工作中的情况。在标签推送的情况下,if: ${{ github.ref == 'refs/heads/master' }}将类似于refs/tags/v.2.2.2,因为如果条件与作业不匹配,则跳过作业。

我在这里运行了一个示例作业来验证它。链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73093495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档