Skip to content

Commit

Permalink
refactor workflows by decoupling processes
Browse files Browse the repository at this point in the history
  • Loading branch information
skierkowski committed Sep 24, 2024
1 parent c5cfaea commit d5b0f1b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
46 changes: 5 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
name: Deploy main branch
name: Deploy Prod

on:
push:
branches:
- main
pull_request:
branches:
- main
pull_request_target:
types:
- closed

jobs:
deploy:
name: deploy
if: github.event_name != 'pull_request_target' || github.event.pull_request.merged != true
name: deploy-prod
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Serverless Framework
run: npm install serverless --global
cache: "npm"
- name: Install Dependencies
run: npm install
run: npm ci
- name: Update domain settings
uses: mikefarah/yq@master
with:
Expand All @@ -35,35 +27,7 @@ jobs:
- name: Serverless Deploy
uses: serverless/github-action@v4
with:
args: deploy --stage ${{ github.event.pull_request.number && 'pr-${{ github.event.pull_request.number }}' || 'prod' }}
env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
remove:
name: remove
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Serverless Framework
run: npm install serverless --global
- uses: bahmutov/npm-install@v1
with:
working-directory: |
ai-chat-api
auth
business-api
business-worker
website
- name: serverless remove
uses: serverless/github-action@v4
with:
args: remove --stage pr-${{ github.event.pull_request.number }}
args: deploy --stage prod
env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/pr-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy PR Preview

on:
pull_request:
branches:
- main

jobs:
remove:
name: deploy-pr-preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "npm"
- name: Install dependencies
run: npm ci
- name: serverless deploy
uses: serverless/github-action@v4
with:
args: deploy --stage pr-${{ github.event.pull_request.number }}
env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28 changes: 28 additions & 0 deletions .github/workflows/pr-remove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Remove PR Preview

on:
pull_request_target:
types:
- closed

jobs:
remove:
name: remove-pr-preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "npm"
- name: Install dependencies
run: npm ci
- name: serverless remove
uses: serverless/github-action@v4
with:
args: remove --stage pr-${{ github.event.pull_request.number }}
env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

0 comments on commit d5b0f1b

Please sign in to comment.