Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run github action only if the pushed files are in a specific folder

I have a folder structure that looks something like this.

- folder1
  - file1
  - *other files*
- folder2
  - file1
  - *other files*
- .gitignore
- package.json
- *other files*

I want to run my GitHub Actions workflow on push, only if any of the changed/pushed files are located in the folder1 directory/folder.

like image 652
TheComputerM Avatar asked Sep 10 '20 03:09

TheComputerM


People also ask

In which folder should the GitHub Actions files reside?

GitHub Actions uses YAML syntax to define the workflow. Each workflow is stored as a separate YAML file in your code repository, in a directory named . github/workflows .

How do I run jobs sequentially in GitHub Actions?

To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .

Can you manually trigger a GitHub Action?

Earlier this week, GitHub announced a new feature which allows developers to trigger workflows manually from within the “Actions” tab.

What is the default working directory for GitHub Actions?

The default all commands are executed at root directory of the application. In some cases, you need to execute any command for the sub directories. It's possible by setting the working-directory directive in the configuration file.


2 Answers

The normal syntax involves a path filter

on:
  push:
    paths:
      - folder1/**

If that is not enough, you also have the GitHub Action Path Filter.

like image 144
VonC Avatar answered Oct 08 '22 22:10

VonC


Path filters only work at workflow level.

on:
  push:
    paths:
    - 'sub-project/**'

If you want to apply this at job level, look for changed-files

like image 13
Sayed Naweed Avatar answered Oct 08 '22 20:10

Sayed Naweed