Skip to content

Commit 87e0325

Browse files
committed
Add GitHub Actions workflow for CI/CD
- Run tests on all PRs and pushes to main - Deploy to Fly.io on push to main (if FLY_API_TOKEN is configured) - Gracefully skip deploy when token is not set
1 parent 4b3d7d0 commit 87e0325

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.22"
18+
19+
- name: Run tests
20+
run: make test
21+
22+
deploy:
23+
runs-on: ubuntu-latest
24+
needs: test
25+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
26+
env:
27+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
28+
steps:
29+
- name: Check for FLY_API_TOKEN
30+
id: check-token
31+
run: |
32+
if [ -n "$FLY_API_TOKEN" ]; then
33+
echo "has_token=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "has_token=false" >> $GITHUB_OUTPUT
36+
echo "Skipping deploy - FLY_API_TOKEN not configured"
37+
fi
38+
39+
- uses: actions/checkout@v4
40+
if: steps.check-token.outputs.has_token == 'true'
41+
42+
- uses: superfly/flyctl-actions/setup-flyctl@master
43+
if: steps.check-token.outputs.has_token == 'true'
44+
45+
- name: Deploy to Fly.io
46+
if: steps.check-token.outputs.has_token == 'true'
47+
run: flyctl deploy --remote-only

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ fly deploy
2424

2525
The app will auto-stop when idle and auto-start on incoming requests to minimize costs.
2626

27+
### CI/CD
28+
29+
Pushes to `main` automatically run tests and deploy to Fly.io via GitHub Actions.
30+
31+
To enable automatic deploys, add `FLY_API_TOKEN` to your repository secrets:
32+
33+
1. Generate a token: `fly tokens create deploy -x 999999h`
34+
2. Add it to GitHub: Settings → Secrets and variables → Actions → New repository secret
35+
2736
## Configuration
2837

2938
### Environment Variables

0 commit comments

Comments
 (0)