Skip to content

Commit d5b0f1b

Browse files
committed
refactor workflows by decoupling processes
1 parent c5cfaea commit d5b0f1b

File tree

3 files changed

+61
-41
lines changed

3 files changed

+61
-41
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
name: Deploy main branch
1+
name: Deploy Prod
22

33
on:
44
push:
55
branches:
66
- main
7-
pull_request:
8-
branches:
9-
- main
10-
pull_request_target:
11-
types:
12-
- closed
137

148
jobs:
159
deploy:
16-
name: deploy
17-
if: github.event_name != 'pull_request_target' || github.event.pull_request.merged != true
10+
name: deploy-prod
1811
runs-on: ubuntu-latest
1912
steps:
2013
- uses: actions/checkout@v4
2114
- name: Use Node.js
2215
uses: actions/setup-node@v4
2316
with:
2417
node-version: 20.x
25-
- name: Install Serverless Framework
26-
run: npm install serverless --global
18+
cache: "npm"
2719
- name: Install Dependencies
28-
run: npm install
20+
run: npm ci
2921
- name: Update domain settings
3022
uses: mikefarah/yq@master
3123
with:
@@ -35,35 +27,7 @@ jobs:
3527
- name: Serverless Deploy
3628
uses: serverless/github-action@v4
3729
with:
38-
args: deploy --stage ${{ github.event.pull_request.number && 'pr-${{ github.event.pull_request.number }}' || 'prod' }}
39-
env:
40-
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
41-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
42-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
43-
remove:
44-
name: remove
45-
if: github.event.pull_request.merged == true
46-
runs-on: ubuntu-latest
47-
steps:
48-
- uses: actions/checkout@v4
49-
- name: Use Node.js
50-
uses: actions/setup-node@v4
51-
with:
52-
node-version: 20.x
53-
- name: Install Serverless Framework
54-
run: npm install serverless --global
55-
- uses: bahmutov/npm-install@v1
56-
with:
57-
working-directory: |
58-
ai-chat-api
59-
auth
60-
business-api
61-
business-worker
62-
website
63-
- name: serverless remove
64-
uses: serverless/github-action@v4
65-
with:
66-
args: remove --stage pr-${{ github.event.pull_request.number }}
30+
args: deploy --stage prod
6731
env:
6832
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
6933
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

.github/workflows/pr-deploy.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy PR Preview
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
remove:
10+
name: deploy-pr-preview
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Use Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 20.x
18+
cache: "npm"
19+
- name: Install dependencies
20+
run: npm ci
21+
- name: serverless deploy
22+
uses: serverless/github-action@v4
23+
with:
24+
args: deploy --stage pr-${{ github.event.pull_request.number }}
25+
env:
26+
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
27+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.github/workflows/pr-remove.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Remove PR Preview
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- closed
7+
8+
jobs:
9+
remove:
10+
name: remove-pr-preview
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Use Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 20.x
18+
cache: "npm"
19+
- name: Install dependencies
20+
run: npm ci
21+
- name: serverless remove
22+
uses: serverless/github-action@v4
23+
with:
24+
args: remove --stage pr-${{ github.event.pull_request.number }}
25+
env:
26+
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
27+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

0 commit comments

Comments
 (0)