-
Notifications
You must be signed in to change notification settings - Fork 1
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
Get best-fitting branch name of a given repo based on current branch name (on current repo) action #12
base: main
Are you sure you want to change the base?
Get best-fitting branch name of a given repo based on current branch name (on current repo) action #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||
name: 'get_branch' | ||||||||
description: 'Get the branch name of the given repository that fits with the given repo@branch' | ||||||||
|
||||||||
inputs: | ||||||||
|
||||||||
result_env_var: | ||||||||
description: 'Environment Variable name for result' | ||||||||
required: true | ||||||||
|
||||||||
head_ref: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume head and base are used here as arguments because of where this action will be used from. Let's be pythonic, the function does not depend on where it is called. Who calls it dependens on the function. 🔫 |
||||||||
description: 'Reference to Git Head to compare with' | ||||||||
required: true | ||||||||
|
||||||||
base_ref: | ||||||||
description: 'Reference to Git current' | ||||||||
required: true | ||||||||
|
||||||||
remote_repository: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT;
Suggested change
It does not need to be remote, is it? |
||||||||
description: 'Remote Github repository name' | ||||||||
required: true | ||||||||
|
||||||||
runs: | ||||||||
using: composite | ||||||||
steps: | ||||||||
|
||||||||
- name: get_branch | ||||||||
run: | | ||||||||
echo "::group::Get the branch name of ${{ inputs.remote_repository }}" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please, keep same format as other actions when possible |
||||||||
echo "using head '${{ inputs.head_ref }}' branch" | ||||||||
DOC_REPO=https://github.com/eProsima/${{ remote_repository }}.git | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also helps you to use this action with variable |
||||||||
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO ${{ inputs.head_ref }} | wc -l) | ||||||||
if [[ ${RESPONSE_CODE} == "0" ]] | ||||||||
then | ||||||||
echo "head '${{ inputs.head_ref }}' branch DOES NOT exist, using base '${{ github.base_ref }}'" | ||||||||
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO ${{ inputs.base_ref }} | wc -l) | ||||||||
if [[ ${RESPONSE_CODE} == "0" ]] | ||||||||
then | ||||||||
echo "base '${{ inputs.base_ref }}' branch DOES NOT exist, using 'MASTER'" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if what you are looking for is the default branch ( Check: |
||||||||
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO master | wc -l) | ||||||||
if [[ ${RESPONSE_CODE} == "0" ]] | ||||||||
then | ||||||||
echo "'MASTER' branch DOES NOT exist, using 'MAIN'" | ||||||||
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO main | wc -l) | ||||||||
if [[ ${RESPONSE_CODE} == "0" ]] | ||||||||
then | ||||||||
echo "'main' branch DOES NOT exist, using ''" | ||||||||
echo "${{ inputs.result_env_var }}=" >> $GITHUB_ENV | ||||||||
else | ||||||||
echo "${{ inputs.result_env_var }}=main" >> $GITHUB_ENV | ||||||||
fi | ||||||||
else | ||||||||
echo "${{ inputs.result_env_var }}=master" >> $GITHUB_ENV | ||||||||
fi | ||||||||
else | ||||||||
echo "${{ inputs.result_env_var }}=${{ inputs.base_ref }}" >> $GITHUB_ENV | ||||||||
fi | ||||||||
else | ||||||||
echo "${{ inputs.result_env_var }}=${{ inputs.head_ref }}" >> $GITHUB_ENV | ||||||||
fi | ||||||||
|
||||||||
echo "::endgroup::" | ||||||||
|
||||||||
shell: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, explain a bit more the logic of the algorithm