1

I have this git action setup where I want to run regression only on folder1 and not folder2.

name: Node.js CI

on:
  push:
    branches: [ develop ]    
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]
        dir: ['./folder1', 'folder2']

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install Dependencies
      run: npm ci
    - name: Run regression tests
      run: npm run regression

How can we achieve this?

kittu
  • 6,662
  • 21
  • 91
  • 185
  • Does this answer your question? [How to run github action only if the pushed files are in a specific folder](https://stackoverflow.com/questions/63822219/how-to-run-github-action-only-if-the-pushed-files-are-in-a-specific-folder) – fredrik Aug 05 '21 at 12:20
  • It's also in the docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions – fredrik Aug 05 '21 at 12:22
  • @fredrik The answer in link mentions about `on push` but not about conditions on git steps – kittu Aug 05 '21 at 12:23
  • Define different jobs for it? Having a "build" job that also runs test does not make sense to me. – fredrik Aug 05 '21 at 12:24
  • @fredrik Why not? We are running tests on push.. – kittu Aug 05 '21 at 12:26
  • I'd do one "tests" job/build and one for tests. – fredrik Aug 05 '21 at 12:26
  • 1
    It does not seem possible to condition a step inside a job, only jobs and actions. You could do it as a shell script check - but it would not prevent it from running - just pass on the npm command. – fredrik Aug 05 '21 at 12:27

1 Answers1

2

You can use if conditions to do this.

name: Node.js CI

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
        dir: ['./folder1', 'folder2']
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install Dependencies
      run: npm ci
      run: npm run lint
    - name: Run unit
      run: npm run test:unit
      working-directory: ${{ matrix.dir }}
    - name: Run integration
      if: ${{ matrix.dir == './folder1' }}
      run: npm run test:integration
      working-directory: ${{ matrix.dir }}
Sam-Sundar
  • 511
  • 1
  • 4
  • 12