Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running actions in another directory

I've just started exploring Github actions however I've found myself placing a command in multiple places.

I have a PHP project where the composer.json is not in the root, my structure looks like:

my-project:     readme.md     app:         composer.json 

Obviously there is more to it and there is a reason why, but my composer.json sits in a subdirectory called 'app'. As a result in my workflow, I have to cd into that folder every time to run a command:

name: CI  on: [push]  jobs:   phpunit:     runs-on: ubuntu-latest     steps:       - uses: actions/checkout@v1       - name: Setup Symfony         run: |           cd app           cp .env.dev .env       - name: Install Composer Dependencies         run: |           cd app           composer install --prefer-dist       - name: Run Tests         run: |           cd app           php bin/phpunit 

How can I remove the cd app in every stage?

like image 645
MylesK Avatar asked Sep 27 '19 17:09

MylesK


People also ask

What directory does GitHub Actions run in?

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 schedule GitHub Actions?

You can configure your workflows to run when specific activity on GitHub happens, at a scheduled time, or when an event outside of GitHub occurs.

What is CWD programming?

In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just current directory.


1 Answers

Update: It's now possible to set a working-directory default for a job. See this answer.

There is an option to set a working-directory on a step, but not for multiple steps or a whole job. I'm fairly sure this option only works for script steps, not action steps with uses.

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun

Using working-directory, your workflow would look like this. It's still quite verbose but maybe a bit cleaner.

name: CI  on: [push]  jobs:   phpunit:     runs-on: ubuntu-latest     steps:       - uses: actions/checkout@v1       - name: Setup Symfony         working-directory: ./app         run: cp .env.dev .env       - name: Install Composer Dependencies         working-directory: ./app         run: composer install --prefer-dist       - name: Run Tests         working-directory: ./app         run: php bin/phpunit 

Alternatively, you can run it all in one step so that you only need to specify working-directory once.

name: CI  on: [push]  jobs:   phpunit:     runs-on: ubuntu-latest     steps:       - uses: actions/checkout@v1       - name: Setup and run tests         working-directory: ./app         run: |           cp .env.dev .env           composer install --prefer-dist           php bin/phpunit 
like image 58
peterevans Avatar answered Oct 13 '22 04:10

peterevans