# Deploy to Fly via GitHub action

> Learn how to set up continuous deployment to Fly.io with a GitHub Actions workflow that runs flyctl deploy using a FLY_API_TOKEN secret on every push.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2024-02-03 | Topics: [Services](https://flaviocopes.com/tags/services/) | Canonical: https://flaviocopes.com/deploy-to-fly-via-github-action/

[Fly.io](http://fly.io/) is a very cool cloud hosting platform but one thing I miss is automatic deploy when I do a [GitHub](https://flaviocopes.com/github/) commit, as the services are not linked to GitHub.

To add CD (Continuous Deployment) to [Fly.io](http://fly.io/) we need to create a GitHub action.

I built a free [GitHub Actions deploy workflow generator](https://flaviocopes.com/tools/gh-actions-deploy/) that writes this file for Fly, Cloudflare Pages and VPS deploys, including the secrets you need to set.

I suppose you already have a Fly app running and a `fly.toml` file in your repo like I describe in [https://flaviocopes.com/dockerfile-to-run-astro-node-ssr-on-flyio/](https://flaviocopes.com/dockerfile-to-run-astro-node-ssr-on-flyio/))

In your project repo, create `.github/workflows/fly.yml`

```javascript
name: Fly Deploy
on:
  push:
    branches:
      - mod12
jobs:
  deploy:
    name: Deploy app
    runs-on: ubuntu-latest
    concurrency: deploy-group
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - uses: superfly/flyctl-actions/setup-flyctl@master
      - run: flyctl deploy --remote-only
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
```

I took this from [https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/](https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/) but updated the checkout version to v4 and added the setup-node step to setup Node 20, as the repo is an [Astro](https://flaviocopes.com/astro-introduction/) site and I want it to use LTS Node.

Make sure you set the name of the branch you want to deploy (in this example, I deploy a branch named `mod12`).

In your terminal run

```javascript
fly tokens create deploy -x 999999h
```

to generate the Fly token and add it to the actions secrets in GitHub:

![GitHub repository Settings tab with Secrets and variables section highlighted in the sidebar menu](https://flaviocopes.com/images/deploy-to-fly-via-github-action/1.webp)

![Actions secrets page showing New repository secret button in GitHub repository settings](https://flaviocopes.com/images/deploy-to-fly-via-github-action/2.webp)

Call the secret `FLY_API_TOKEN` and enter the value you got from `fly tokens...`

![GitHub new repository secret form with FLY_API_TOKEN entered as the secret name](https://flaviocopes.com/images/deploy-to-fly-via-github-action/3.webp)

![Completed GitHub secret creation showing FLY_API_TOKEN secret successfully added to repository](https://flaviocopes.com/images/deploy-to-fly-via-github-action/4.webp)

Push to GitHub, you’ll see your action running:

![GitHub Actions tab showing Fly Deploy workflow running with yellow pending status indicator](https://flaviocopes.com/images/deploy-to-fly-via-github-action/5.webp)

You can see all the details of the action by clicking it:

![GitHub Actions workflow run details page showing the Fly Deploy job with expand button to view logs](https://flaviocopes.com/images/deploy-to-fly-via-github-action/6.webp)

In the jobs tab you can see what happened in the build:

![GitHub Actions job execution log showing successful flyctl deploy steps with green checkmarks](https://flaviocopes.com/images/deploy-to-fly-via-github-action/7.webp)

Go on Fly, you’ll see the action was successful:

![Fly.io dashboard showing successful app deployment with green status and recent activity log](https://flaviocopes.com/images/deploy-to-fly-via-github-action/8.webp)

and the app is deployed on every commit.

All your deploys also have a “check” now to indicate that the action was successful (or not)

![GitHub commit history showing green checkmark indicating successful deployment action completion](https://flaviocopes.com/images/deploy-to-fly-via-github-action/9.webp)
