# Deploy from GitHub

Connect the server's GitHub repository to FiveDash: every push reaches the city on its own, and a deploy that crashes the server is rolled back.

Source: https://fivedash.fivex.gg/docs/en/server/deploy

With **Deploy**, the city's code goes from GitHub to the server without anyone copying files. On every push to the chosen branch, the [FiveDash Agent](https://fivedash.fivex.gg/docs/en/server/agent) downloads that commit straight from GitHub, swaps the files and restarts what changed.

## Before you start

* **Where:** **Servidor → Deploy**.
* **Access level:** the **Deploy** area. **View** shows the history, **Manage** deploys and **Configure** connects GitHub and picks the repository.
* **Agent:** installed, connected and on version 0.1.5 or newer. It updates itself at the next server restart.
* **Repository:** on GitHub, holding the server folder (`server.cfg` and the `resources` folder) or a part of it.

> The code goes from GitHub **straight to the server's machine**. It never passes through FiveDash, so secrets from `server.cfg` that live in the repository, like `sv_licenseKey`, never reach the panel.

## Connect GitHub

### Click Connect GitHub

In **Servidor → Deploy**, click **Connect GitHub**. GitHub opens the **FiveDash** app's page.

### Pick only the server's repository

Install the app on the account or organization that owns the repository, choose **Only select repositories** and pick the city's repository. The app only reads the code; it writes nothing.

### Confirm with your GitHub account

GitHub asks you to sign in. That's how FiveDash checks which repositories **you** can see: only those become available to this organization.

### Choose the branch and folders

Back on FiveDash, choose the repository and the branch (for example, `main`) and save.

If the app is already installed, use **I already installed the app**. After giving it access to another repository on GitHub, click **Refresh repositories**.

## Folders

| Field                    | Empty                                     | Example                                                              |
| ------------------------ | ----------------------------------------- | -------------------------------------------------------------------- |
| Folder in the repository | The repository's root                     | `server-data`, when the repository keeps the server folder inside it |
| Folder on the server     | The server folder (where `server.cfg` is) | `resources/[rua7]`, to send only one group of resources              |

## What happens on each deploy

1. The agent checks that the commit really is on the chosen branch. A commit from a fork, from someone else's pull request, is refused.
2. It downloads the commit, checks every path and only then swaps the files, keeping the previous ones.
3. Files a previous deploy put there and the repository no longer has are deleted. Files that never came from the repository, like `cache`, logs and the database, **are left alone**.
4. With the server running, it does what you chose in **After the deploy**:

| Option                        | What it does                                                                                                               |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| Restart the changed resources | `refresh` and `ensure` on the resources that changed only. Players stay. Changes to `server.cfg` apply at the next restart |
| Restart the server            | Restarts FXServer. Applies everything, but drops the players                                                               |
| Nothing                       | Only swaps the files. It applies at the next restart                                                                       |

> What comes from GitHub replaces the file on the server, including edits someone made in **Resources → Folder**. Make your changes in the repository.

## When something goes wrong

* **The server crashed after the deploy:** if it crashes within 60 seconds, the agent puts the previous files back on its own and the deploy shows as **Rolled back**.
* **What's in the city:** in the history, only the deploy in use shows as **Live**; the ones before it show as **Replaced**. With the option to do nothing after the files, the new one shows as **On the next restart** until the server restarts.
* **Going back to an earlier version:** in the history, click **Deploy again** on an older deploy.
* **Agent disconnected:** the deploy waits up to 10 minutes. After that it leaves the queue without running.

## FAQ

### I use Git LFS for maps and vehicles

GitHub only puts LFS files in the download if you turn on **Include Git LFS objects in archives** in the repository's settings (**Settings → General → Archives**). Without it, the agent refuses the deploy instead of replacing your maps with empty files.

### Can two servers deploy from the same repository?

Yes. Each server picks its own branch and folders, for example `main` on the live server and `teste` on the test server.
