Github Actions provides us an easier way to setup CI/CD for the application. We can build any application on Github events and deploy to the servers.
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.
Running Command in Subdirectory with Github Actions
For example, your application have composer.json file under the “app” directory. In that case, use the following configuration to run composer install under app directory.
1 2 3 4 | - name: Install composer dependencies run: | composer install --no-scripts working-directory: ./app |
In the above configuration the “composer install –no-scripts” command will be executed under “./app” directory. You can set any directory path by changing the value of working-directory.
Below is a complete action configuration file used in our actual project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # This is an sample workflow for learning working-directory option on: push: branches: [ main ] pull_request: branches: [ main ] name: CI jobs: phpunit: runs-on: ubuntu-latest steps: with: fetch-depth: 1 - name: Install composer dependencies run: | composer install --no-scripts working-directory: ./app - name: Prepare Application run: | php artisan key:generate working-directory: ./app - name: Run Testsuite run: vendor/bin/phpunit tests/ working-directory: ./app |
Conclusion
In this tutorial, you have learned running commands in subdirectory with Github actions.