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

Automatically detecting the default branch name. #55

Open
spencer741 opened this issue Jul 28, 2021 · 6 comments
Open

Automatically detecting the default branch name. #55

spencer741 opened this issue Jul 28, 2021 · 6 comments

Comments

@spencer741
Copy link

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
Copy link
Author

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
Copy link
Author

@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 :)

@andstor
Copy link
Owner

andstor commented Jul 31, 2021

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 😍

@danielbayley
Copy link

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

@spencer741
Copy link
Author

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.

@danielbayley
Copy link

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

Tell me about it! 😅

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