-
Notifications
You must be signed in to change notification settings - Fork 1
171 lines (147 loc) · 5.96 KB
/
preview_env.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Koyeb Preview Environment
on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize, closed]
jobs:
environment:
name: Environment name
runs-on: ubuntu-latest
outputs:
name: ${{ steps.environment.outputs.name }}
app-name: ${{ steps.environment.outputs.name }}-console
steps:
- name: Compute environment name
id: environment
run: |
branch=${{ github.head_ref }}
environment=$(echo "${branch##*/}" | cut -c 1-14)
environment="${environment%-}"
environment="${environment#-}"
echo "name=$environment" >> $GITHUB_OUTPUT
control-panel:
name: Deploy Control Panel
runs-on: ubuntu-latest
needs: environment
if: github.event.action != 'closed'
concurrency:
group: ${{ github.head_ref }}-control-panel
cancel-in-progress: true
steps:
- name: Install Koyeb CLI
uses: koyeb-community/install-koyeb-cli@v2
with:
api_token: ${{ secrets.KOYEB_TOKEN }}
- name: Environment variables
id: environment-variables
shell: bash
run: |
variables=(
ENVIRONMENT=preview
APP_VERSION=${{ github.event.pull_request.head.sha || github.sha }}
API_URL=https://staging.koyeb.com
PAGE_CONTEXT_BASE_URL=@control-panel-staging-page-context-base-url
RECAPTCHA_CLIENT_KEY=@control-panel-staging-recaptcha-client-key
SEGMENT_WRITE_KEY=@control-panel-staging-segment-write-key
POSTHOG_KEY=@control-panel-staging-posthog-key
STRIPE_PUBLIC_KEY=@control-panel-staging-stripe-public-key
MAPBOX_TOKEN=@control-panel-staging-mapbox-token
SENTRY_AUTH_TOKEN=@control-panel-staging-sentry-auth-token
)
IFS=, ; echo "env=${variables[*]}" >> $GITHUB_OUTPUT
- name: Deploy
uses: koyeb/action-git-deploy@v1
with:
app-name: ${{ needs.environment.outputs.app-name }}
service-name: control-panel
git-branch: ${{ github.head_ref }}
git-builder: docker
service-instance-type: nano
service-regions: fra
service-ports: 3000:http
service-routes: /:3000
service-env: ${{ steps.environment-variables.outputs.env }}
- name: Change autoassigned domain
run: koyeb apps update $APP_NAME --domain $DOMAIN
env:
APP_NAME: ${{ needs.environment.outputs.app-name }}
DOMAIN: ${{ needs.environment.outputs.app-name }}-koyeb
storybook:
name: Deploy Storybook
runs-on: ubuntu-latest
needs: environment
if: github.event.action != 'closed'
concurrency:
group: ${{ github.head_ref }}-design-system
cancel-in-progress: true
steps:
- name: Install Koyeb CLI
uses: koyeb-community/install-koyeb-cli@v2
with:
api_token: ${{ secrets.KOYEB_TOKEN }}
- name: Deploy Storybook
uses: koyeb/action-git-deploy@v1
with:
app-name: ${{ needs.environment.outputs.app-name }}
service-name: storybook
git-branch: ${{ github.head_ref }}
service-instance-type: nano
service-regions: fra
service-ports: 8000:http
service-routes: /storybook:8000
git-build-command: pnpm run build-storybook --quiet
git-run-command: pnpx http-server storybook-static
github-comment:
name: Github Comment
runs-on: ubuntu-latest
needs: [environment, control-panel, storybook]
if: github.event.action != 'closed'
steps:
- name: Install Koyeb CLI
uses: koyeb-community/install-koyeb-cli@v2
with:
api_token: ${{ secrets.KOYEB_TOKEN }}
- name: Seed Koyeb info
id: info
run: |
info=$(koyeb app describe ${{ needs.environment.outputs.app-name }} -o json)
service=$(echo $info | jq -r '.services[] | select(.name == "control-panel")')
echo "app_id=$(echo $info | jq -r '.id' | sed '/null/d')" >> $GITHUB_OUTPUT
echo "app_url=$(echo $info | jq -r '.domains[0].name' | sed '/null/d')" >> $GITHUB_OUTPUT
echo "deployment_id=$(echo $service | jq -r '.latest_deployment_id' | sed '/null/d')" >> $GITHUB_OUTPUT
echo "service_id=$(echo $service | jq -r '.id' | sed '/null/d')" >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v3
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: This pull request initialized a new Koyeb App and Service to deploy your application.
- name: Upsert Comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
reactions: rocket
body: |
This pull request initialized a new Koyeb App and Service to deploy your application.
To tack the status of your deployment, click below.
🔍 Track the latest deployment: https://app.koyeb.com/apps/${{ steps.info.outputs.app_id }}/services/${{ steps.info.outputs.service_id }}/deployments/${{ steps.info.outputs.deployment_id }}
✅ Preview: https://${{ steps.info.outputs.app_url }}
📖 Design System: https://${{ steps.info.outputs.app_url }}/design-system/
📖 Storybook: https://${{ steps.info.outputs.app_url }}/storybook/
cleanup:
name: Delete Koyeb Application
runs-on: ubuntu-latest
needs: environment
if: github.event.action == 'closed'
steps:
- name: Install Koyeb CLI
uses: koyeb-community/install-koyeb-cli@v2
with:
api_token: ${{ secrets.KOYEB_TOKEN }}
- name: Delete Koyeb application
uses: koyeb/action-git-deploy/cleanup@v1
with:
app-name: ${{ needs.environment.outputs.app-name }}