Commit GitHub changes to MainModule

I’ve recently began my quest to learn the basics of GitHub as it appears to be the ideal platform to continue open-sourced community contributed projects like HD Admin.

I was wondering, is it possible to have changes from a master branch on GitHub published automatically to a MainModule and its corresponding modules? In doing so, code could be modified and published in one single environment, instead of having to transfer code from one place to another each time.

Projects like @evaera’s Cmdr and @Sceleratis’s Adonis appear to effectively utilise GitHub within their Roblox applications.

Any other tips when approaching a GutHub based project are much appreciated.

4 Likes

I don’t think there are tools for automatically updating scripts when pushed to a github repo, but that might not be what you want either. You should check out Rojo if you want to use things like git for version control or use external editors.

1 Like

Those GitHub repositories are generally just code storage locations. They themselves don’t commit changes (and can’t), they just contain the latest code for a project depending on how often the authors commit changes. They’re fairly static examples.

I personally would use Roblox’s CoreScripts repository or Nevermore as two better references. While none of these auto update anything either, the difference is that the items in their repositories are actually pulled and inserted into a Roblox project. For the CoreScripts, they’re injected at run time before snapshots are queued AFAIK. For Nevermore, it contains an installation script. It works like this:

  • Enable HttpService
  • Wrap the installation file’s raw in loadstring
  • The repository is sifted through; files are created in the DataModel based on a file’s name
    • Folders are, of course, folders. The rest are turned into ModuleScripts, as Nevermore is modular.
  • The raws of each file are set as the LuaSourceContainer’s source

The files installed by Nevermore are considered forks since they are loaded into the Studio window. Roblox CoreScripts don’t exist in Studio view until injection at run time. As you know, you can void Roblox’s auto injection behaviour by forking code and using the same name as the original code in various locations (e.g. Animate in StarterCharacterScripts). That stops the file from being pulled from GitHub and instead uses your own forked code.

So, the answer? Yes you can, so long as your updates only pertain to usage in a DataModel (whether that’s Studio or a production build). If you want to update an actual model asset, you will have to handle that manually. But what comes after?

If you’re looking for a pre-compile time fork, you can adopt Nevermore’s style of whole-repository forking. If you’re looking for an “auto-updating” model for your project, then you’ll need to look into CoreScript-like injection. The latter comes at a cost though; both HttpService and LoadStringEnabled will need to be on so that you are able to accomplish this. LoadStringEnabled cannot be enabled at run time and it is often cautioned against leaving LoadStringEnabled for production environments. You’ll probably have a more difficult time using an injection approach over a fork approach.

3 Likes

I wrote rbxmk for this exact sort of thing, if you’re willing to compile it yourself. It uses a Lua script to read Roblox files, and write them elsewhere, including to assets on the website. Here’s an example script that might be used to update a module:

update.lua

rbxmk.configure{
	-- Add credentials for uploading.
	rbxauth = {
		type = "Username",
		ident = "Builderman",
		file = "SECRET/path/to/cookies.txt",
	},
}
rbxmk.map{
	-- Read script.
	rbxmk.input{
		format = "modulescript.lua",
		"path/to/MainModule.lua",
	},
	-- Upload to asset.
	rbxmk.output{"rbxassetid://12345678"},
}

Then this can be run through the command line:

rbxmk update.lua

cookies.txt would contain the cookies needed for a logged in session, which is formatted as a list of “Set-Cookie” HTTP headers. Only .ROBLOSECURITY should be needed, if I recall. Of course, file should be located somewhere safe, outside of any repositories. Alternatively, prompt = true can be specified to have the program prompt you to log in, though it may not play well with the captcha BS.

For further automation, it should be possible to use git hooks to run the command automatically after you commit.

I haven’t tested uploading very thoroughly, so it may crash and burn. It would help to file an issue, if that happens.

5 Likes

Cmdr does this as well with one of the installation methods :slight_smile:


Rojo also has this ability now! https://lpghatguy.github.io/rojo/creating-a-place/ This guide is for places, but it should work for models just as well. If you want to set this up as a continuous delivery task in your repository, you could use one of the many available CI providers such as travis or circleci.

5 Likes

Thank you all for the responses! Using HTTP Service run-time is something I want to avoid, so rbxmk and Rojo definitely seem like the way forward.

1 Like