Creating branches if branch is missing?
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?
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 :+1: How does the code need to changed to make it happen?
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.
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 :+1:
@TomasVotruba yeah, my code is battle-tested :D. I'll open PR soon, thanks for the response!
@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 👍🏼.