githubyamlcontinuous-integrationgithub-actionsjobs

GitHub multiple workflows fail to run


I have a problem with workflows. I have several files under .github/workflows directory. For the sake of this post let's say 2: build.yml and cypress.yml. I want to trigger a workflow/job only if paths criteria are met so cypress tests won't run until there is no *.test-cy.tsx file added/modified.

name: CI

on:
  push:
    paths: ["**/*", "!.github/**/*"]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
          cache-dependency-path: "package-lock.json"
      - run: npm ci
      - run: npm run build --if-present
      - run: npm run build-storybook --if-present
name: Cypress

on:
  push:
    paths: ["src/**/*.test-cy.{js,jsx,ts,tsx}"]

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
          cache-dependency-path: "package-lock.json"
      - run: npm ci
      - run: npm run test:cypress --if-present

When I push the commit, only first one runs. I tried doing it also in one workflow with multiple jobs but couldn't find the right condition for if:.


Solution

  • This is the filter pattern cheat sheet for github action. There is no character of { and }. This may work:

    name: Cypress
    
    on:
      push:
        paths:
          - 'src/**/*.test-cy.tsx?'
          - 'src/**/*.test-cy.jsx?'
    
    jobs:
      test:
        runs-on: ubuntu-latest