VeryGoodOpenSource / very_good_workflows

Reusable GitHub workflows used at Very Good Ventures 🦄
https://workflows.vgv.dev
MIT License
293 stars 71 forks source link

fix: allow inputs to run workflows in a monorepo #165

Closed JakeHadley closed 9 months ago

JakeHadley commented 10 months ago

Description Currently there isn't a good way (or I'm ignorant to a way) to run workflows within packages or apps in a monorepo on github actions.

Steps To Reproduce

I've created a monorepo setup with melos, and have a root .github/workflows/main.yaml file. I've tried a number of permutations of the github workflow file to have it run the reusable verygoodworkflows within each of my packages and apps. The issue that I'm filing is that there isn't an input available in the workflows to set the current working directory so that the workflow can operate on the app or package.

Any additional insight into this would be appreciated

alestiago commented 10 months ago

Hi @JakeHadley ! Thanks for opening an issue.

I'm not sure if I'm understanding correctly. Currently all workflows (except the Semantic Pull Request) have an working_directory input you can specify. See the documentation for further information.

Most workflows have an example usage, see how it's done with the Dart package workflow. Alternatively, you can check out other open source software repositories that are using Very Good Workflows, like in the Flutter News Toolkit.

Note, the input path must be absolute, see this FAQ for more details.

I hope this helps you out! Let me know if this answers your issue 🙌

JakeHadley commented 10 months ago

Oh ok, that's perfect. I had tried that previously, but was using working-directory instead of working_directory. Big difference there. The issue now is that I need to run a command before running the job that uses the VGV workflow. In the docs it says that the setup input is ran after dependencies are installed, but the setup I need to run is with melos bootstrap to install my package that exists in my monorepo. Does it just need to be ran in a different job?

JakeHadley commented 10 months ago

I've since tried a number of different things, the latest workflow yaml that I have is this:

name: melos

on: [pull_request, push]

jobs:
  setup:
    runs-on: ubuntu-latest
    outputs:
      cache-hit: ${{ steps.cache.outputs.cache-hit }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Flutter
        uses: subosito/flutter-action@v2

      - name: Bootstrap melos
        uses: bluefireteam/melos-action@v3

      - name: Cache dependencies
        uses: actions/cache@v2
        with: 
          path: ~/.pub-cache
          key: ${{ runner.OS }}-flutter-${{ hashFiles('**/pubspec.lock') }}
          restore-keys: ${{ runner.OS }}-flutter-
      - name: Get Flutter packages
        run: flutter pub get

  semantic-pull-request:
    uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1

  fg-build:
    needs: setup
    uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
    with:
      flutter_channel: stable
      working_directory: 'apps/four_gospels'

My file structure looks like

image

And the error I'm getting in the github action output is: Because four_gospels depends on quiz_core any which doesn't exist (could not find package quiz_core at https://pub.dev)/, version solving failed.

So the main question is, how do we allow the reusable workflow to have access to a local dependency? Melos is doing all the linking between the packages, and I'm able to run the workflow on github in my flutter app, it just can't find the local dependency. Everything works locally also.

tomarra commented 9 months ago

Hi @JakeHadley 👋 in reviewing this some more it seems that your probably running into a case that we have not fully tested as its not a use case that we run into during our project work and is therefore not a key path for us to support. Overall I don't think this is something that we're going to prioritize for a fix. Your more then welcome to continue on this and if you find a solution please feel free to open up a PR with the needed changes or documentation updates and the team will help get it through the contribution process.

Closing as "won't fix"

JakeHadley commented 9 months ago

@tomarra Yeah no problem. I ended up doing myself some learning and went in a different direction. I was trying to cache dependencies to use in a different job so that I could just use the VGV workflow with the cached dependencies. I ended up setting up a private pub server and such to pull in the dependencies I needed and moved away from a monorepo.

Basically on the VGV end, it could be interesting if there was a setup parameter that runs BEFORE the rest of the steps. The flutter package workflow has a setup step that can be passed in that happens AFTER the deps are installed. But not a big deal in any way. Thanks!