copycat-action icon indicating copy to clipboard operation
copycat-action copied to clipboard

Automatically detecting the default branch name.

Open spencer741 opened this issue 2 years ago • 6 comments

Automatically detecting the default branch name if the src_branchand/ordst_branch` names are not provided by user.

Background: A while back, GitHub started naming the master branch "main" by default. Since copycat-action looks for a "master" branch by default, you have to explicitly provide branch names if you are using Github's new naming convention "main" for your default branch. Obviously if you are already using custom branch names, you have to explicitly specify them.

Instead of assuming each default branch name is always "master", we need to automatically detect the name to explicitly use it to clone the src and dst repos.

I believe below is a reliable way to get the default branch name.

git remote show upstream | grep "HEAD branch" | sed 's/.*: //'

I will work on a PR to test this out.

spencer741 avatar Jul 28 '21 15:07 spencer741

Making some good progress. Obviously git remote will only work post-clone, so I am looking at git ls-remote to detect branch name, because we need to do it pre-clone.

spencer741 avatar Jul 28 '21 16:07 spencer741

@andstor I think I have something testable working for this... there is likely a few kinks to work out.

How do you test Github actions locally for this repo? Or do you just docker build and run and pass the env variables manually? Or do you use something like act?

Any info to help in the local testing process would be great :)

spencer741 avatar Jul 28 '21 18:07 spencer741

Automatic detection of the default branch is absolutely something we should try to implement 👍

@spencer741 I took a quick look at the git ls-remotecommand you mentioned. I did a quick google search and came up with something like this:

git ls-remote --symref https://github.com/andstor/copycat-action HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'

It seems to do the trick, but has to be more thoroughly tested, both in terms of reliability and validity.

Regarding testing, I have just sat up two private testing repositories and used GitHub Actions directly. This is absolutely not ideal. For this purpose, act seems to be a much better approach. However, I haven't had time to try it out. Please do share your experience if you decide to try it out! 🤩

Manually testing the action's logic (entrypoint.sh) is however, a somewhat painful task when testing for backwards compatibility. I would therefore really like to get some automatic regression testing implemented. If this is something you would be interested in, I would really appreciate it 😍

andstor avatar Jul 31 '21 18:07 andstor

Any progress on this? Surely main should now be the default in the meantime…

danielbayley avatar Feb 13 '22 17:02 danielbayley

Thanks for bringing this up @danielbayley. I think the owner and I have become extremely busy with life. I'll make a note to myself to dive into this later this week.

spencer741 avatar Feb 13 '22 19:02 spencer741

I think the owner and I have become extremely busy with life.

Tell me about it! 😅

danielbayley avatar Feb 13 '22 20:02 danielbayley