-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathstaging-preview-production.yml
More file actions
107 lines (97 loc) · 3.07 KB
/
staging-preview-production.yml
File metadata and controls
107 lines (97 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Staging, Preview, and Production deployment workflow
# - Push to develop → deploys to staging
# - Pull request → deploys to preview environment
# - Push to main → deploys to production (requires approval)
#
# Required secrets (configure per environment in GitHub):
# Staging environment:
# - GIGALIXIR_EMAIL
# - GIGALIXIR_API_KEY
# Preview environment:
# - GIGALIXIR_EMAIL
# - GIGALIXIR_API_KEY
# Production environment:
# - GIGALIXIR_EMAIL
# - GIGALIXIR_API_KEY
#
# Note: This example uses a single shared preview app. For true PR-based
# preview environments, you would need to dynamically create/destroy
# Gigalixir apps using the Gigalixir CLI.
name: Deploy
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
# Prevent concurrent deployments to the same environment
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
jobs:
# Deploy to staging on push to develop
deploy-staging:
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
environment:
name: staging
url: https://my-app-staging.gigalixirapp.com
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Deploy to Staging
uses: gigalixir/gigalixir-action@v1
with:
gigalixir_email: ${{ secrets.GIGALIXIR_EMAIL }}
gigalixir_api_key: ${{ secrets.GIGALIXIR_API_KEY }}
app_name: my-app-staging
# Deploy to preview on pull request
deploy-preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
environment:
name: preview
url: https://my-app-preview.gigalixirapp.com
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
# For PRs, checkout the PR head
ref: ${{ github.event.pull_request.head.sha }}
- name: Deploy to Preview
uses: gigalixir/gigalixir-action@v1
with:
gigalixir_email: ${{ secrets.GIGALIXIR_EMAIL }}
gigalixir_api_key: ${{ secrets.GIGALIXIR_API_KEY }}
app_name: my-app-preview
- name: Comment PR with preview URL
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🚀 Preview deployed to https://my-app-preview.gigalixirapp.com'
})
# Deploy to production on push to main
deploy-production:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: production
url: https://my-app.gigalixirapp.com
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Deploy to Production
uses: gigalixir/gigalixir-action@v1
with:
gigalixir_email: ${{ secrets.GIGALIXIR_EMAIL }}
gigalixir_api_key: ${{ secrets.GIGALIXIR_API_KEY }}
app_name: my-app-prod