Ask HN: How do you automate file upload to GitHub?
I’ve been exploring Git workflows and curious how others would approach this challenge:
We need to upload a file to GitHub on demand (a table routing JSON file to minimize API calls) and want to automate it so non-technical users can push the file.
Our ideal workflow is to generate the JSON and push automatically via webhook or API call
How would you approach it? Things you’d be concerned about with this approach?
Some additional context:
- We have to solve this problem in this way due to limitations with another code base we rely on.
- this is a private repo so we aren’t concerned about merge issues, just overwriting the file is fine
13 comments
[ 2.5 ms ] story [ 34.5 ms ] threadSo the question is less about pushing to git and more about what causes the file to update in the first place. If it is an automated update, just have whatever task updates it also run the git command to push it. If it is a manual update, what tool are the non-tech people using that makes it happen? Add a button to that tool which runs the command.
Only piece that you have to be a bit careful with the guarding credentials or token you will be using for the “git” commands. In my case we use Hashicorp Vault for secrets management so I can just checkout the token to use from there.
Appreciate the guidance on credentials, fully agree on using a vault.
Because you're on Github and wanting to edit it from another cloud app, it might be easier to just use the Github API (which is its own thing, not git-based) to edit the file directly: https://docs.github.com/en/rest/repos/contents?apiVersion=20...
Then you can skip all the CI/CD stuff (it's overkill for something like this) and just send a plain fetch from your app's backend (NOT the frontend/client!! Don't expose your Github tokens to your users!). You can either use their JS SDK or just send the raw HTTP commands.
* edit: we're building an integration with a SaaS product that doesn't allow us to reference external files due to security, hence having to upload direct to git
commandToGenerateFile > file.json #or wget some.server.tld/autogen.json file.json git add file.json git commit -m "Automatic upload <date>" git push
You can do this in any number of ways. Powershell, batch script, bash, you could even build a little GUI if you want.
If you want to get fancier, throw the script on a server and give users an SSH script they can double-click, or hook it up to some intranet web interface.
This isn't a particularly complex problem, and git was designed to handle use cases just like this.
Of course you could absolutely overcomplicate and burn dozens of engineer hours building some kubernetes cluster or AWS swarm, but you can do this with a script so simple that I wrote it on my phone.
the k8 approach is tempting though haha
https://docs.github.com/en/rest/gists/gists?apiVersion=2022-...
[0] - https://github.com/decaporg/decap-cms