Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions - How to build project in sub-directory

I'm using GitHub Actions to build my project but my Dart project is in a sub-directory in the repository. The Action script can't find my pubspec.yaml and get the dependencies.

How can I point my GitHub Action to look for the source code in a sub-directory within my repository?

. (root of my GitHub repository) └── dart_project     ├── pubspec.yaml   <-- Git Hub action must point to this sub-dir └── node_project     ├── packages.json 

This is the error I am getting:

Could not find a file named "pubspec.yaml" in "/__w/<my_project_path>". ##[error]Process completed with exit code 66. 

This is the dart.yml file auto-generated by GitHub.

name: Dart CI  on: [push]  jobs:   build:      runs-on: ubuntu-latest      container:       image:  google/dart:latest      steps:     - uses: actions/checkout@v1     - name: Install dependencies       run: pub get     - name: Run tests       run: pub run test 

enter image description here

like image 739
Evandro Pomatti Avatar asked Sep 05 '19 13:09

Evandro Pomatti


People also ask

Which directory does GitHub Actions run?

Create an example workflow 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 .

How do I set environment variables in GitHub Actions?

To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.


1 Answers

If I understand your needs, you need the pub steps to run as if you'd done a cd dart_project first, right? Add the working-directory parameter to your steps:

steps: - uses: actions/checkout@v1 - name: Install dependencies   run: pub get   working-directory: dart_project - name: Run tests   run: pub run test   working-directory: dart_project 

If you want to apply it to every step, use the tag defaults

defaults:   run:     working-directory: dart_project 

I believe that should be all you need.

like image 91
rmunn Avatar answered Sep 23 '22 15:09

rmunn