{"id":15649208,"url":"https://github.com/javierarce/glitchub","last_synced_at":"2025-03-09T09:30:23.916Z","repository":{"id":66561033,"uuid":"176254635","full_name":"javierarce/glitchub","owner":"javierarce","description":"A step by step guide on how to keep a Glitch project in sync with a GitHub repo","archived":false,"fork":false,"pushed_at":"2019-12-25T15:50:01.000Z","size":5877,"stargazers_count":44,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T09:13:01.575Z","etag":null,"topics":["deploy","github","glitch","tutorial","webhooks"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/javierarce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-18T10:07:47.000Z","updated_at":"2025-02-13T11:55:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac8da721-755f-447d-8f21-450ef1e8b28e","html_url":"https://github.com/javierarce/glitchub","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"330444c7500db602fe688d4573a15208b6b608bc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javierarce%2Fglitchub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javierarce%2Fglitchub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javierarce%2Fglitchub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javierarce%2Fglitchub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javierarce","download_url":"https://codeload.github.com/javierarce/glitchub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242673795,"owners_count":20167294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deploy","github","glitch","tutorial","webhooks"],"created_at":"2024-10-03T12:28:53.319Z","updated_at":"2025-03-09T09:30:23.606Z","avatar_url":"https://github.com/javierarce.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to keep a Glitch project in sync with a GitHub repo\n\nYou can follow the \"initial steps\" below or just [remix this glitch project](https://glitch.com/~glitchub) and continue in the next section.\n\n\u003cdetails\u003e\u003csummary\u003eClick here to reveal the \u003cstrong\u003einitial steps\u003c/strong\u003e\u003c/summary\u003e\n\n1. Go to [glitch.com](http://glitch.com) and create a new `hello-express` app.\n2. Open the `package.json` file and add the following packages:\n\n  - `node-cmd`\n  - `body-parser`\n\n3. Open the `server.js` file and load the following libraries:\n\n```js\nconst cmd = require('node-cmd');\nconst crypto = require('crypto'); \nconst bodyParser = require('body-parser');\n```\n\n4. Look for `app.use(express.static('public'));` and add the following line below:\n\n`app.use(bodyParser.json());`\n\n5. Create a post endpoint to receive the GitHub webhook:\n\n```js\nconst onWebhook = (req, res) =\u003e {\n  let hmac = crypto.createHmac('sha1', process.env.SECRET);\n  let sig  = `sha1=${hmac.update(JSON.stringify(req.body)).digest('hex')}`;\n\n  if (req.headers['x-github-event'] === 'push' \u0026\u0026 sig === req.headers['x-hub-signature']) {\n    cmd.run('chmod 777 ./git.sh'); \n    \n    cmd.get('./git.sh', (err, data) =\u003e {  \n      if (data) {\n        console.log(data);\n      }\n      if (err) {\n        console.log(err);\n      }\n    })\n\n    cmd.run('refresh');\n  }\n\n  return res.sendStatus(200);\n}\n\napp.post('/git', onWebhook);\n```\n\n6. Create a `git.sh` file adding the following lines:\n\n```bash\n#/bin/sh\n\n# Fetch the newest code\ngit fetch origin master\n\n# Hard reset\ngit reset --hard origin/master\n\n# Force pull\ngit pull origin master --force\n```\n\n*This file will be in charge of pulling the changes from your Github repo.*\n\n\u003c/details\u003e\n\n1. Open the `.env` file and set a SECRET:\n\n```bash\nSECRET=cirrus-socrates-particle-decibel-hurricane-dolphin-tulip\n```\n\n2. Open the glitch console for your project and generate a new SSH key with:\n\n```bash \nssh-keygen\n```\n\n*Just press `\u003cEnter\u003e` to accept all the questions.*\n\n3. Read the content of the `.ssh/id_rsa.pub` file with:\n\n```bash \ncat .ssh/id_rsa.pub\n```\n\n*Then copy the string to your clipboard.*\n\n4. Create a new GitHub repo with a `README.me` file (or any other file, it's important that the project is not empty).\n5. Go to the `deploy keys` section of the settings page of your GitHub project.\n6. Click on `Add deploy key` and add the SSH key you generated in the step #8; add `glitch.com` in the title field.\n7. Check the `Allow write access` box too.\n8. Now open the `webhooks` section and add a new webhook (replacing `PROJECT_NAME` with your actual project name):\n\n```html\nPayload URL: https://PROJECT_NAME.glitch.me/git\nContent type: application/json\nSecret: use the SECRET you set up in your glitch project\n```\n*The rest of the defaults are OK.*\n\n9. Go back to your Glitch project and export your project to GitHub (that will create a new `glitch` branch in your GitHub repo): Tools \u003e Git, Import, and Export \u003e Export to GitHub.\n\n10. In the Glitch console, set the remote origin to the master branch of your GitHub project:\n\n```bash\ngit remote add origin git@github.com:USERNAME/PROJECT.git\ngit pull\ngit branch --set-upstream-to=origin/master master\n```\n\n11. Clone your repo in your dev machine and merge the newly created `glitch` branch with the master branch:\n\n```bash \ngit fetch\ngit merge master origin/glitch\n```\n# Testing \n\n1. In your dev machine, create a dummy test file (like `hello.txt`) and commit it.\n2. Push the changes with `git push`. \n\nIf everything is OK, your Glitch project should be updated, and a `hello.txt` file should appear in the list of files.   \nIf you don't see it, have a look to the log of your Glitch project.\n\n# Updating your project from GitHub → Glitch\n\nThis should be the default method of updating your project. Develop in your dev machine, commit the changes and do a `git push`\n\n# Updating your project from Glitch → GitHub\n\nIf you change something in Glitch, first you'll need to export your project to GitHub and then merge the `glitch` branch with your master branch.\n\n```bash \ngit merge glitch\ngit push\n```\n\n# Credits\n\nWhile I've detailed all the steps and added  information on how to add a deploy key, the overall solution (including the `git.sh` and webhook sync code) comes from [this post by @jarvis394 on the glitch forum](https://support.glitch.com/t/tutorial-how-to-auto-update-your-project-with-github/8124). \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavierarce%2Fglitchub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavierarce%2Fglitchub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavierarce%2Fglitchub/lists"}