-
Notifications
You must be signed in to change notification settings - Fork 36
Add ref-spec matching of spaceros repository (#91). #90
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
Conversation
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.
Already way better than what we had and a great addition to the readme as well.
I've got a few questions but none are blockers so I'll approve after I finish checking out my local test build, but I'll hold off on hitting the merge button until you've had a chance to respond.
spaceros/Earthfile
Outdated
|
||
IF[ -z "$(git ls-remote ${SPACEROS_REPO_URL} ${GIT_BRANCH})" ] | ||
RUN echo "branch '${GIT_BRANCH}' does not exist in spaceros repo, cloning main branch" | ||
GIT CLONE ${SPACEROS_REPO_URL} spaceros_repo_dir/ |
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.
Annoying we need a full clone for this but I understand why - literally the only thing I miss about SVN.
Can we at least make a third case that detects if we're just using the main branch of the default repo and uses the githubusercontent CDN to grab the file? I guess a more complete solution would be checking the url for common host platforms like GitHub and GitLab which expose files directly under a specific URL but that might be out of scope for this issue.
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.
These are good points. Let me break it down:
- "Can we at least make a third case that detects if we're just using the main branch of the default repo and uses the githubusercontent CDN to grab the file?" - For default spaceros repo, I would even go one step further and say that we should use CDN whenever
SPACEROS_REPO_URL="https://github.com/space-ros/space-ros.git"
, regardless of branch. I think that it is important, because I can imagine that if we have multiple spaceros distros, we would rarely pull from main (you would rather pull from specific tag). There is just one caveat with this approach. - "I guess a more complete solution would be checking the url for common host platforms like GitHub and GitLab which expose files directly under a specific URL but that might be out of scope for this issue." -> yes, but here we would ideally need to handle cases when such repos are private. Earthly's
GIT CLONE
handles that automagically (check earthly docs)
In summary, I would refactor that so that we use CDN whenever we pull from default spaceros repo, and use GIT CLONE otherwise. I will document that in the code so that its clear for future generations :D.
Sounds good to you @Bckempa?
Update: I've just discovered a corner case. In case the branch becomes available only after first run of Earthly, it won't pull new repos as results of "$(git ls-remote ${SPACEROS_REPO_URL} ${SPACEROS_GIT_REF})"
are cached across runs. Thats where GIT CLONE
command shines because it checks whether there was a new commit added and reruns the pipeline if so. Let me think about the easiest solution that will mitigate that corner case
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.
Yep, you got everything I was going for and more. If this too big and needs to be split out to another ticket we can do that too.
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.
No worries, I figured it out, I will post the PR today in the evening
Not a huge deal, but while I see it executing the feedback line:
I don't see the actual echo with the substituted output. Can we find a better way to make sure it's clear in logs what branch was used? Either way, seems to work though earthly's caching is so near magical that I want to play with it more before we merge, but you got my green checkmark. |
Note that the |
I think i will just remove these |
Ok @Bckempa, now it should work as expected. Please take a look again. Summary of behavior
Additionally, if |
ARG EARTHLY_GIT_BRANCH | ||
|
||
ARG SPACEROS_REPO_URL="https://github.com/space-ros/space-ros.git" | ||
# if current local branch does not exist in target repo then use main. note that branch supplied from CLI overrides this behavior. | ||
ARG SPACEROS_GIT_REF="$( [ -n \"$(git ls-remote $SPACEROS_REPO_URL $EARTHLY_GIT_BRANCH)\" ] && echo $EARTHLY_GIT_BRANCH || echo 'main' )" |
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.
As we want to re-run git ls-remote
every time, we can no longer keep these args at the top of the file
looks like this should be good to go after a rebase |
63cf59c
to
21a7704
Compare
Rebase applied |
21a7704
to
3790bdc
Compare
Add ref-spec matching of spaceros repository (space-ros/docker#91).
Add ref-spec matching of spaceros repository (space-ros/docker#91).
Description
This PR fixes #91, by matching spaceros repo branch to current local branch during build. Assuming that current local branch is
feature/foo
, the behavior is as follows:SPACEROS_GIT_REF
is not supplied by user via CLI (default behavior):feature/foo
exists in spaceros repo, ros2.repos from that branch will be usedmain
branchSPACEROS_GIT_REF
via CLIIt is also now possible to specify different url for spaceros git repository, which can be useful in testing scenarios, when contributors are forking spaceros repo.
If
SPACEROS_REPO_URL
is not supplied by user, then we use wget to clone ros2.repos file from spaceros repo. Otherwise we use Earthly'sGIT CLONE
command to get the file (see discussion below).Check updated readme file for more details.
Summary of changes
How changes were tested
I have developed python file to test the changes: https://gist.github.com/xfiderek/a697dd33739c035ac6b2b1d6cdee8af1