Skip to content

Commit 4863a2d

Browse files
committed
update deployment workflow
1 parent ab883dd commit 4863a2d

File tree

1 file changed

+154
-153
lines changed

1 file changed

+154
-153
lines changed

.github/workflows/deploy.yml

Lines changed: 154 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,128 @@
11
name: Deploy wildcat-dashboard-ui (Cloudflare Pages)
22

33
on:
4-
# auto deploy new tag to CF project PREVIEW
54
push:
65
tags:
76
- 'v*'
8-
9-
# promote a version to CF project PRODUCTION
7+
branches:
8+
- 'master'
109
workflow_dispatch:
1110
inputs:
1211
environment:
1312
description: 'target'
1413
required: true
15-
default: 'wildcat-dev-docker'
14+
default: 'production'
1615
type: choice
1716
options:
18-
- wildcat-dev-docker
19-
- wildcat-docker
20-
21-
env:
22-
NODE_VERSION: 22
17+
- dev
18+
- staging
19+
- production
2320

2421

2522
jobs:
2623

2724
######################################################################
28-
# ENV: wildcat-dev-docker
29-
# CF project: wildcat-dev-docker
25+
# ENV: dev
26+
# CF project: wildcat-dashboard
27+
######################################################################
28+
deploy-dev:
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
deployments: write
33+
concurrency:
34+
group: 'deploy-dev-${{ github.ref_name }}'
35+
cancel-in-progress: true
36+
37+
# SET ENVIRONMENT
38+
environment: dev
39+
name: Deploy to dev (wildcat-dashboard)
40+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev'
41+
42+
##############################################################################
43+
# keep section similar, dev has different validation step
44+
env:
45+
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
46+
NODE_VERSION: ${{ vars.NODE_VERSION }}
47+
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
48+
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
49+
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
50+
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
51+
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
52+
53+
steps:
54+
- name: Checkout ${{ github.ref_name }}
55+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
56+
with:
57+
ref: ${{ github.ref }}
58+
fetch-depth: 0
59+
60+
# for dev: only allow dev branch
61+
- name: Validate correct branch on manual dispatch
62+
run: |
63+
if [[ "${{ github.ref_name }}" != 'dev' ]]; then
64+
echo "::error::Manual deployments to the 'dev' environment must be triggered from the 'dev' branch."
65+
echo "::error::Please select the 'dev' branch from the 'Use workflow from' dropdown."
66+
exit 1
67+
fi
68+
echo "Validation successful: Running from 'dev' branch."
69+
70+
- name: Setup Node
71+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
72+
with:
73+
node-version: ${{ env.NODE_VERSION }}
74+
cache: 'npm'
75+
76+
- name: Install dependencies
77+
run: npm ci
78+
79+
- name: Build app
80+
run: npm run build
81+
82+
##############################################################################
83+
# Customize deployment triggers
84+
85+
# DEV: manual dispatch, branch dev
86+
- name: Deploy ${{ github.ref_name }} to DEV of ${{ env.CLOUDFLARE_PROJECT }} project
87+
id: deploy-dev-dispatch
88+
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
89+
with:
90+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
91+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
92+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=dev --commit-message="MANUAL DISPATCH ${{ github.sha }}" --commit-hash=${{ github.sha }} --commit-dirty=true
93+
94+
95+
######################################################################
96+
# ENV: staging
97+
# CF project: wildcat-dashboard-staging
3098
######################################################################
31-
deploy-wildcat-dev-docker:
99+
deploy-staging:
32100
runs-on: ubuntu-latest
33101
permissions:
34102
contents: read
35103
deployments: write
104+
concurrency:
105+
group: 'deploy-staging-${{ github.ref_name }}'
106+
cancel-in-progress: true
36107

37-
# set env
38-
name: Deploy to ${{ vars.CLOUDFLARE_PROJECT_DEV_DOCKER }}
39-
108+
# SET ENVIRONMENT
109+
environment: staging
110+
name: Deploy to staging (wildcat-dashboard-staging)
40111
if: |
41112
github.event_name == 'push' ||
42-
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'wildcat-dev-docker')
113+
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
43114
115+
##############################################################################
116+
# keep section similar
44117
env:
45-
PROJECT_NAME: ${{ vars.CLOUDFLARE_PROJECT_DEV_DOCKER }}
46-
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL_DEV_DOCKER }}
47-
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL_DEV_DOCKER }}
48-
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM_DEV_DOCKER || 'dev' }}
49-
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID_DEV_DOCKER || 'bff-dashboard' }}
50-
VITE_API_MOCKING_ENABLED: 'false'
51-
52-
# checkout, validate on dispatch, setup and build, deploy
118+
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
119+
NODE_VERSION: ${{ vars.NODE_VERSION }}
120+
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
121+
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
122+
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
123+
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
124+
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
125+
53126
steps:
54127
- name: Checkout ${{ github.ref_name }}
55128
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -71,108 +144,79 @@ jobs:
71144
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
72145
with:
73146
node-version: ${{ env.NODE_VERSION }}
74-
75-
- name: Cache node modules
76-
id: cache-npm
77-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
78-
env:
79-
cache-name: cache-node-modules
80-
with:
81-
path: ~/.npm
82-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
83-
restore-keys: |
84-
${{ runner.os }}-build-${{ env.cache-name }}-
85-
${{ runner.os }}-build-
86-
${{ runner.os }}-
87-
88-
- name: List the state of node modules
89-
if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
90-
continue-on-error: true
91-
run: npm list
147+
cache: 'npm'
92148

93149
- name: Install dependencies
94150
run: npm ci
95151

96152
- name: Build app
97153
run: npm run build
154+
155+
##############################################################################
156+
# Customize deployment triggers
98157

99-
# PREVIEW branch
100-
- name: Deploy ${{ github.ref_name }} to PREVIEW branch of ${{ env.PROJECT_NAME }} project
101-
if: github.event_name == 'push'
102-
id: deploy-preview
158+
# STAGING PREVIEW: on push, branch master
159+
- name: Deploy ${{ github.ref_name }} to STAGING PREVIEW of ${{ env.CLOUDFLARE_PROJECT }} project
160+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
161+
id: deploy-staging-preview-push-master
103162
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
104163
with:
105164
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
106165
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
107-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=preview --commit-message="LATEST PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
108-
109-
# VERSION branch
110-
- name: Deploy ${{ github.ref_name }} to VERSION branch ${{ github.ref_name }} of ${{ env.PROJECT_NAME }} project
111-
id: deploy-version
112-
if: github.event_name == 'push'
166+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=preview --commit-message="PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
167+
168+
# STAGING PROD: on push, with tag
169+
- name: Deploy ${{ github.ref_name }} to STAGING PROD of ${{ env.CLOUDFLARE_PROJECT }} project
170+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
171+
id: deploy-staging-push-tag
113172
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
114173
with:
115174
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
116175
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
117-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=${{ github.ref_name }} --commit-message="VERSION ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
118-
119-
# PRODUCTION branch
120-
- name: Deploy ${{ github.ref_name }} to PRODUCTION of ${{ env.PROJECT_NAME }} project
121-
id: deploy-production
122-
if: github.event_name == 'workflow_dispatch'
176+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }} (TAG PUSH)" --commit-hash=${{ github.sha }} --commit-dirty=true
177+
178+
# STAGING PROD: on manual dispatch
179+
- name: Deploy ${{ github.ref_name }} to STAGING PROD of ${{ env.CLOUDFLARE_PROJECT }} project
180+
id: deploy-staging-dispatch
181+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging'
123182
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
124183
with:
125184
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
126185
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
127-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=master --commit-message="${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
128-
129-
# print deployment URLs
130-
131-
- name: print PREVIEW deployment-url
132-
if: steps.deploy-preview.outputs.deployment-url
133-
env:
134-
DEPLOYMENT_URL_PREVIEW: ${{ steps.deploy-preview.outputs.deployment-url }}
135-
run: echo $DEPLOYMENT_URL_PREVIEW
136-
137-
- name: print VERSION deployment-url
138-
if: steps.deploy-version.outputs.deployment-url
139-
env:
140-
DEPLOYMENT_URL_VERSION: ${{ steps.deploy-version.outputs.deployment-url }}
141-
run: echo $DEPLOYMENT_URL_VERSION
142-
143-
- name: print PRODUCTION deployment-url
144-
if: steps.deploy-production.outputs.deployment-url
145-
env:
146-
DEPLOYMENT_URL_PRODUCTION: ${{ steps.deploy-production.outputs.deployment-url }}
147-
run: echo $DEPLOYMENT_URL_PRODUCTION
186+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }} (DISPATCH)" --commit-hash=${{ github.sha }} --commit-dirty=true
148187

149188

150189
######################################################################
151-
# ENV: wildcat-docker
152-
# CF project: wildcat-docker
190+
# ENV: production
191+
# CF project: wildcat-dashboard-production
153192
######################################################################
154-
deploy-wildcat-docker:
193+
deploy-production:
155194
runs-on: ubuntu-latest
156195
permissions:
157196
contents: read
158197
deployments: write
198+
concurrency:
199+
group: 'deploy-production-${{ github.ref_name }}'
200+
cancel-in-progress: true
159201

160-
# set env
161-
name: Deploy to ${{ vars.CLOUDFLARE_PROJECT_DOCKER }}
162-
202+
# SET ENVIRONMENT
203+
environment: production
204+
name: Deploy to production (wildcat-dashboard-production)
163205
if: |
164206
github.event_name == 'push' ||
165-
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'wildcat-docker')
207+
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
166208
209+
##############################################################################
210+
# keep section similar
167211
env:
168-
PROJECT_NAME: ${{ vars.CLOUDFLARE_PROJECT_DOCKER }}
169-
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL_DOCKER }}
170-
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL_DOCKER }}
171-
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM_DOCKER || 'dev' }}
172-
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID_DOCKER || 'bff-dashboard' }}
173-
VITE_API_MOCKING_ENABLED: 'false'
174-
175-
# checkout, validate on dispatch, setup and build, deploy
212+
CLOUDFLARE_PROJECT: ${{ vars.CLOUDFLARE_PROJECT }}
213+
NODE_VERSION: ${{ vars.NODE_VERSION }}
214+
VITE_API_BASE_URL: ${{ vars.VITE_API_BASE_URL }}
215+
VITE_KEYCLOAK_URL: ${{ vars.VITE_KEYCLOAK_URL }}
216+
VITE_KEYCLOAK_REALM: ${{ vars.VITE_KEYCLOAK_REALM }}
217+
VITE_KEYCLOAK_CLIENT_ID: ${{ vars.VITE_KEYCLOAK_CLIENT_ID }}
218+
VITE_API_MOCKING_ENABLED: ${{ vars.VITE_API_MOCKING_ENABLED }}
219+
176220
steps:
177221
- name: Checkout ${{ github.ref_name }}
178222
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -194,77 +238,34 @@ jobs:
194238
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
195239
with:
196240
node-version: ${{ env.NODE_VERSION }}
197-
198-
- name: Cache node modules
199-
id: cache-npm
200-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
201-
env:
202-
cache-name: cache-node-modules
203-
with:
204-
path: ~/.npm
205-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
206-
restore-keys: |
207-
${{ runner.os }}-build-${{ env.cache-name }}-
208-
${{ runner.os }}-build-
209-
${{ runner.os }}-
210-
211-
- name: List the state of node modules
212-
if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
213-
continue-on-error: true
214-
run: npm list
241+
cache: 'npm'
215242

216243
- name: Install dependencies
217244
run: npm ci
218245

219246
- name: Build app
220247
run: npm run build
248+
249+
250+
##############################################################################
251+
# Customize deployment triggers
221252

222-
# PREVIEW branch
223-
- name: Deploy ${{ github.ref_name }} to PREVIEW branch of ${{ env.PROJECT_NAME }} project
224-
if: github.event_name == 'push'
225-
id: deploy-preview
226-
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
227-
with:
228-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
229-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
230-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=preview --commit-message="LATEST PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
231-
232-
# VERSION branch
233-
- name: Deploy ${{ github.ref_name }} to VERSION branch ${{ github.ref_name }} of ${{ env.PROJECT_NAME }} project
234-
id: deploy-version
235-
if: github.event_name == 'push'
253+
# PRODUCTION PREVIEW: on push, with tag
254+
- name: Deploy ${{ github.ref_name }} to PRODUCTION PREVIEW of ${{ env.CLOUDFLARE_PROJECT }} project
255+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
256+
id: deploy-production-preview-push-tag
236257
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
237258
with:
238259
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
239260
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
240-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=${{ github.ref_name }} --commit-message="VERSION ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
241-
242-
# PRODUCTION branch
243-
- name: Deploy ${{ github.ref_name }} to PRODUCTION of ${{ env.PROJECT_NAME }} project
244-
id: deploy-production
245-
if: github.event_name == 'workflow_dispatch'
261+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=preview --commit-message="PREVIEW ${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
262+
263+
# PRODUCTION PROD: manual dispatch, with tag
264+
- name: Deploy ${{ github.ref_name }} to PRODUCTION PROD of ${{ env.CLOUDFLARE_PROJECT }} project
265+
id: deploy-production-dispatch
266+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production'
246267
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
247268
with:
248269
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
249270
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
250-
command: pages deploy dist --project-name=${{ env.PROJECT_NAME }} --branch=master --commit-message="${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true
251-
252-
# print deployment URLs
253-
254-
- name: print PREVIEW deployment-url
255-
if: steps.deploy-preview.outputs.deployment-url
256-
env:
257-
DEPLOYMENT_URL_PREVIEW: ${{ steps.deploy-preview.outputs.deployment-url }}
258-
run: echo $DEPLOYMENT_URL_PREVIEW
259-
260-
- name: print VERSION deployment-url
261-
if: steps.deploy-version.outputs.deployment-url
262-
env:
263-
DEPLOYMENT_URL_VERSION: ${{ steps.deploy-version.outputs.deployment-url }}
264-
run: echo $DEPLOYMENT_URL_VERSION
265-
266-
- name: print PRODUCTION deployment-url
267-
if: steps.deploy-production.outputs.deployment-url
268-
env:
269-
DEPLOYMENT_URL_PRODUCTION: ${{ steps.deploy-production.outputs.deployment-url }}
270-
run: echo $DEPLOYMENT_URL_PRODUCTION
271+
command: pages deploy dist --project-name=${{ env.CLOUDFLARE_PROJECT }} --branch=master --commit-message="${{ github.ref_name }}" --commit-hash=${{ github.sha }} --commit-dirty=true

0 commit comments

Comments
 (0)