This example robot code repository includes another robot repository (https://github.com/robocorp/example-shared-robot-framework-keywords-and-libraries) as a Git submodule.
The included repository contains (fictional) common shared code used by many robot projects. Instead of copying & pasting the code into each robot project that needs it, isolating and sharing the common code between the robots might make sense!
This project was created using RCC and the standard Robot Framework template.
The robot includes the shared robot code from the other repository as a Git submodule. The submodule is stored in the shared
directory.
The shared
Git submodule in this project was created with the git submodule add
command:
git submodule add https://github.com/robocorp/example-shared-robot-framework-keywords-and-libraries shared
The .gitmodules
file defines the path and the URL to the included repository:
[submodule "shared"]
path = shared
url = https://github.com/robocorp/example-shared-robot-framework-keywords-and-libraries
See the tasks.robot
file for examples of importing and using the shared code.
To test and clone this project, including the Git submodule, you can use the following command:
git clone --recurse-submodules [email protected]:robocorp/example-use-git-submodule-for-shared-code.git
The
--recurse-submodules
option handles cloning the submodule. See the Git submodule documentation for more information.
To pull the upstream changes to the submodule, use the following command:
git submodule update --remote
The Git submodule strategy works for code-sharing, but there are some caveats. Control Room does not automatically clone the submodules at the time of writing, and there is no way to run manual cloning commands in Control Room.
If you use Git submodules, you can still upload your robot to Control Room using the upload functionality in Robocorp Lab, VS Code, or RCC. Since the upload creates a zip package with the project contents, the zip also contains the submodules!