-
Notifications
You must be signed in to change notification settings - Fork 3
133 lines (109 loc) · 4.46 KB
/
pr-preview.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
name: PR Preview
env:
HUSKY: 0
on:
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
prepare:
runs-on: ubuntu-24.04
env:
PREVIEW_API_DOMAIN: 'test-apps-ninja02.konturlabs.com'
KEYCLOAK_URL: 'https://dev-keycloak.k8s-01.konturlabs.com'
KEYCLOAK_REALM: 'dev'
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Cache pnpm store
uses: actions/cache@v4
with:
path: |
~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --prod=false
- name: Apply domain changes
if: github.event.action != 'closed'
run: |
sed -i "s|https://disaster.ninja|https://${PREVIEW_API_DOMAIN}|" configs/config.default.json
sed -i "s|\"KEYCLOAK_URL\": \"https://keycloak01.kontur.io\"|\"KEYCLOAK_URL\": \"${KEYCLOAK_URL}\"|" configs/config.default.json
sed -i "s|\"KEYCLOAK_REALM\": \"kontur\"|\"KEYCLOAK_REALM\": \"${KEYCLOAK_REALM}\"|" configs/config.default.json
sed -i "s|VITE_BASE_PATH=/active/|VITE_BASE_PATH=/|" .env.production
sed -i "s|VITE_STATIC_PATH=static/|VITE_STATIC_PATH=|" .env.production
- name: Build main app and Cosmos
if: github.event.action != 'closed'
run: |
pnpm build
pnpm cosmos:build
- name: Enable surge.sh redirects
run: cp dist/index.html dist/200.html
- uses: actions/upload-artifact@v4
if: github.event.action != 'closed'
with:
name: main-app
path: ${{ github.workspace }}/dist
- uses: actions/upload-artifact@v4
if: github.event.action != 'closed'
with:
name: cosmos
path: ${{ github.workspace }}/cosmos-export
deploy:
needs: prepare
runs-on: ubuntu-24.04
env:
MAIN_URL: https://${{ github.repository_owner }}-${{ github.event.repository.name }}-pr-${{ github.event.number }}-main.surge.sh
COSMOS_URL: https://${{ github.repository_owner }}-${{ github.event.repository.name }}-pr-${{ github.event.number }}-cosmos.surge.sh
outputs:
main_url: ${{ env.MAIN_URL }}
cosmos_url: ${{ env.COSMOS_URL }}
steps:
- uses: actions/checkout@v4
- name: Install Surge
run: npm install -g surge
- uses: actions/download-artifact@v4
with:
name: main-app
path: dist
- uses: actions/download-artifact@v4
with:
name: cosmos
path: cosmos-export
- name: Deploy main app to Surge
if: github.event.action != 'closed'
run: surge --project ./dist --domain ${{ env.MAIN_URL }} --token ${{ secrets.SURGE_TOKEN }}
- name: Deploy Cosmos to Surge
if: github.event.action != 'closed'
run: surge --project ./cosmos-export --domain ${{ env.COSMOS_URL }} --token ${{ secrets.SURGE_TOKEN }}
- name: Teardown main app preview
if: github.event.action == 'closed'
run: surge teardown ${{ env.MAIN_URL }} --token ${{ secrets.SURGE_TOKEN }}
- name: Teardown Cosmos preview
if: github.event.action == 'closed'
run: surge teardown ${{ env.COSMOS_URL }} --token ${{ secrets.SURGE_TOKEN }}
comment:
needs: deploy
runs-on: ubuntu-24.04
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Preview environments
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
Preview environments for this PR:
- Main App: ${{ needs.deploy.outputs.main_url }}
- Cosmos: ${{ needs.deploy.outputs.cosmos_url }}
These previews are automatically updated with each commit.
**Note:** After a new deployment, it may take a few minutes for the changes to propagate and for caches to update. During this time, you might experience temporary loading issues or see an older version of the app. If the app fails to load, please wait a few minutes and try again.
edit-mode: replace