{"id":18904237,"url":"https://github.com/kingkool68/testing-github-actions","last_synced_at":"2026-03-04T11:30:20.518Z","repository":{"id":45060425,"uuid":"222046862","full_name":"kingkool68/testing-github-actions","owner":"kingkool68","description":"Simple deployment of a repo via SSH","archived":false,"fork":false,"pushed_at":"2022-01-18T07:32:23.000Z","size":1260,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T05:52:52.940Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kingkool68.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-16T04:28:56.000Z","updated_at":"2025-02-14T05:15:07.000Z","dependencies_parsed_at":"2022-09-23T10:24:04.971Z","dependency_job_id":null,"html_url":"https://github.com/kingkool68/testing-github-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingkool68%2Ftesting-github-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingkool68%2Ftesting-github-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingkool68%2Ftesting-github-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingkool68%2Ftesting-github-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingkool68","download_url":"https://codeload.github.com/kingkool68/testing-github-actions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239889029,"owners_count":19713702,"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":[],"created_at":"2024-11-08T09:07:51.918Z","updated_at":"2026-03-04T11:30:20.456Z","avatar_url":"https://github.com/kingkool68.png","language":"JavaScript","readme":"# Simple Deployment via SSH\n\nWhen a new change is pushed to the repo:\n - Download dependencies (with caching)\n - Compile CSS and JavaScript (via npm commands)\n - Commit compiled version to a build-specific branch (Example: `master` branch gets built and commited to  the `master-build` branch)\n - SSH into a server to run a command for deployment\n\n## How does it work?\nWhen the GitHub action is run we run commands to compile a \"built\" version of the codebase. The \"built\" version gets commited to a build specific branch. Example: `master` branch gets built and commited to  the `master-build` branch. Deploying to a server can be done via a `git pull` to bring down the latest changes.\n\n## Secrets\n\nThe following secrets need to be [set in your repository](settings/secrets/actions) for this GitHub action to work.\n\n - `SSH_HOST` - The address the action should connect to via SSH to run a command to deploy the changes.\n - `SSH_USER` - The username to use for the SSH connection. Example: `ssh user@hostname`.\n - `SSH_PRIVATE_KEY` - The private key for the SSH connection.\n## Creating a Deployment Specific User\nWhen deploying code automatically from server to server its a good idea to use a dedicated system user on the remote server that is locked down in what they can do. If the SSH private key is compromised we want to be sure the deployment user can only perform limited commands so the connecting server isn't compromised. This can be achieved by specifying a command to run using the `authorized_keys` file when the user connects. See [Restrict a User to SSH Forced Command](https://ctrlnotes.com/restrict-a-user-to-ssh-forced-command/#).\n\n - [Generate a new SSH keypair](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)\n - Copy the private key (`id_rsa`) contents to the `SSH_PRIVATE_KEY` secret for your repository\n - Copy the public key (`id_rsa.pub`) to your server you want to deploy to\n - On the server you want to deploy to edit or create a file called `authorized_keys` usually located in `~.ssh/authorized_keys` or `.openssh/authorized_keys`\n  - Add a new line in the format `\u003ccommand\u003e \u003cssh public key\u003e \u003ccomment\u003e`. Example: `command=\"date\" ssh-rsa \u003cthe public ssh key for the user you want to restrict\u003e deployment-user`\n  - Whenever a user connects to the server with the private key that matches the specified public key, a command will be run and the connection will then be closed.\n  - You can run a script with a command like `command=\"/path/to/script.sh\"`.\n  - Make sure your script can be executed like `chmod +x script.sh`.\n\n## Deployment Script\nSince we have a build branch we can deploy the changes to the server by running a force git pull like so:\n\n```\ncd ~/path/to/the/root/directory/of/the/site\n\n# Force git pull\ngit fetch --all\ngit reset --hard origin/\u003cbranch name\u003e\n```\n\nIf you ever need to rollback changes by one commit you can run `git reset --hard HEAD~1`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingkool68%2Ftesting-github-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingkool68%2Ftesting-github-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingkool68%2Ftesting-github-actions/lists"}