Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating branches if branch is missing? #26

Open
pjordaan opened this issue Aug 17, 2022 · 5 comments
Open

Creating branches if branch is missing? #26

pjordaan opened this issue Aug 17, 2022 · 5 comments

Comments

@pjordaan
Copy link

Hi I'm using this github action on my monorepo. Since it's still a WIP all I had is a main branch and I was pushing to other repositories to the main branch. Now I have a 1.0 branch so I can work on making a stable version and I run into issues with the monorepo split.

In the workflow I added:

-
        name: Monorepo Split of ${{ matrix.package }} (no tag)
        if: "!startsWith(github.ref, 'refs/tags/')"
        uses: "symplify/[email protected]"
        with:
          package_directory: 'packages/${{ matrix.package }}'
          repository_organization: '<organization name>'
          repository_name: '${{ matrix.package }}'
          user_name: "<username>"
          user_email: "<email>"
          branch: '${{ github.ref_name }}'

This fails however as the repository I'm pushing to has no 1.0 branch (yet). Which results in this error:

[NOTE] Adding git commit



[NOTE] Pushing git commit with "<commit message>" message to "1.0"

error: src refspec 1.0 does not match any
error: failed to push some refs to 'https://github.com/<repository-link>.git'


[NOTE] Changing directory from "/tmp/monorepo_split/build_directory" to "/github/workspace"

Do I need to manually add these branches to all the child repositories? Or can this be done automatically?

@TomasVotruba
Copy link
Collaborator

Hi, thanks for interesting question.

Do I need to manually add these branches to all the child repositories?

At the moment yes.

Or can this be done automatically?

This would be a great addition though 👍 How does the code need to changed to make it happen?

@jakubtobiasz
Copy link
Contributor

jakubtobiasz commented Sep 6, 2022

Hi @TomasVotruba!🙋🏼‍♂️

I've faced the same problem as the issue author. I've forked the repo and added in entrypoint.php:

// $changedFiles is an array that contains the list of modified files, and is empty if there are no changes.

if ($changedFiles) {
    note('Adding git commit');

+    exec_with_output_print(sprintf('git checkout %s || git checkout -b %s', $config->getBranch(), $config->getBranch()));

    exec_with_output_print('git add .');

    $message = sprintf('Pushing git commit with "%s" message to "%s"', $commitMessage, $config->getBranch());
    note($message);

    exec("git commit --message '$commitMessage'");
    exec('git push --quiet origin ' . $config->getBranch());
} else {
    note('No files to change');
}

It might be written better but for PoC purposes is fine. I'm wondering how we should test this part of code, as testing it might be as problematic as described in #21. Finding the way how to test it is the last obstacle holding me back from opening PR.

@TomasVotruba
Copy link
Collaborator

I see. If that's the case for more of you and you've been running the fix on your code, I think it's ok to put it in a PR 👍

@jakubtobiasz
Copy link
Contributor

@TomasVotruba yeah, my code is battle-tested :D. I'll open PR soon, thanks for the response!

@jakubtobiasz
Copy link
Contributor

@TomasVotruba #29 should do the work, I've reworked a little bit the code from my previous comment and I've performed some manual tests. Everything seems to work perfectly 👍🏼.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants