简体   繁体   English

Github 动作跳过发布文件

[英]Github action skipping release file

I own an npm package and decided to create Github actions to automate processes effectively.我拥有一个 npm 包,并决定创建 Github 操作来有效地自动化流程。

  • main.yml - handle Node CI. main.yml - 处理节点 CI。 on every push to the master branch, the action will install the dependencies and build through multiple operating systems.在每次推送到主分支时,该操作将安装依赖项并通过多个操作系统进行构建。
  • release.yml - required to release a new version to npm and Github Releases. release.yml - 需要向 npm 和 Github 发布新版本。 It'll fire on every commit tag which begins with "v" (eg, "v0.1.4").它会在每个以“v”开头的提交标签上触发(例如,“v0.1.4”)。

However, the release.yml action is being skipped while pushing to git with the commit tag.但是,在使用 commit 标签推送到 git 时会跳过release.yml操作。

How to fire the release.yml file?如何触发release.yml文件? but still, wait for main.yml to finish the entire workflow?但是,仍然等待main.yml完成整个工作流程?

I would appreciate your assistance.我会很感激你的帮助。

main.yml action: main.yml动作:

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 action: release.yml动作:

# 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

The problem is with your if condition inside the jobs.问题在于您在工作中的 if 条件。 if: ${{ github.ref == 'refs/heads/master' }} In case of tags push, github.ref will be something like refs/tags/v.2.2.2 Since the if condition is not matching the jobs are skipped. if: ${{ github.ref == 'refs/heads/master' }}在标签推送的情况下, github.ref将类似于refs/tags/v.2.2.2因为 if 条件与作业不匹配被跳过。

I ran a sample job here to validate it.我在这里运行了一个示例作业来验证它​​。 Link 关联

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM