The asterisk problem in GitHub actions

Github actions

Github actions

Recently I spent around 2 hours to get the head branch name inside a GitHub action.

Context:

I was trying to configure unit test for my repo, the idea was to get the PR branch name and run a script run_test.sh on a remote server that takes branch name as input. The script checkouts the branch and runs tests. For this, I want the branch name of the PR.

Solutions:

Finally, after searching I found a solution as per my need to use github.head_ref but for me it was printing ***patch-1 The question was why GitHub not printing the entire branch name. GitHub by default creates the branch username-patch-{number} whenever you make a quick fix on the file itself, my all PRs were of this format only.

I was done, then I printed the entire GitHub context

echo "$GITHUB_CONTEXT"

That printed a huge object with user details, repo details, branch details, PR details etc, but there was a pattern my username got asterisk across all the objects.

Realization

Then I realized one of my repository secrets is my username and I guess and pretty sure GitHub must be doing substring match and replacing it with *** before printing to the console/file. Then I tried with a different branch name voila worked!!!

In case you are facing this problem, the first place you should look is Secrets

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *