Skip to content

Commit

Permalink
Merge pull request #71 from sgcarstrends/70-refactor-github-action-wo…
Browse files Browse the repository at this point in the history
…rkflows

Refactor GitHub Action workflows
  • Loading branch information
ruchernchong authored Dec 15, 2024
2 parents 17f8058 + 407742e commit 714376a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 107 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/sst.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: SST Deploy

on:
workflow_call:
inputs:
environment:
description: 'GitHub environment name'
required: true
type: string
sst-stage:
description: 'SST deployment stage'
required: true
type: string
secrets:
CLOUDFLARE_API_TOKEN:
required: true
MONGODB_URI:
required: true
SG_CARS_TRENDS_API_TOKEN:
required: true
UPSTASH_REDIS_REST_TOKEN:
required: true
UPSTASH_REDIS_REST_URL:
required: true

jobs:
Deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
FEATURE_FLAG_RATE_LIMIT: ${{ vars.FEATURE_FLAG_RATE_LIMIT }}

# Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish
concurrency:
group: merge-${{ github.ref }}

permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: latest
- uses: actions/setup-node@v4
with:
node-version: latest
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_REGION }}
- name: Deploy app
run: |
pnpm sst deploy --stage ${{ inputs.sst-stage }}
41 changes: 5 additions & 36 deletions .github/workflows/sst.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,10 @@ on:
- 'main'
- 'release/**'

# Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish
concurrency:
group: merge-${{ github.ref }}

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
Deploy:
runs-on: ubuntu-latest
environment: Development
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
FEATURE_FLAG_RATE_LIMIT: ${{ secrets.FEATURE_FLAG_RATE_LIMIT }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.ROLE_TO_ASSUME }}
aws-region: ap-southeast-1
- name: Deploy app
run: |
pnpm sst deploy --stage dev
uses: ./.github/workflows/sst.deploy.yml
with:
environment: Development
sst-stage: dev
secrets: inherit
41 changes: 5 additions & 36 deletions .github/workflows/sst.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,10 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'

# Concurrency group name ensures concurrent workflow runs wait for any in-progress job to finish
concurrency:
group: merge-${{ github.ref }}

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
Deploy:
runs-on: ubuntu-latest
environment: Production
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
FEATURE_FLAG_RATE_LIMIT: ${{ secrets.FEATURE_FLAG_RATE_LIMIT }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.ROLE_TO_ASSUME }}
aws-region: ap-southeast-1
- name: Deploy app
run: |
pnpm sst deploy --stage prod
uses: ./.github/workflows/sst.deploy.yml
with:
environment: Production
sst-stage: prod
secrets: inherit
40 changes: 5 additions & 35 deletions .github/workflows/sst.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,10 @@ on:
tags-ignore:
- '*'

concurrency:
group: merge-${{ github.ref }}

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
Deploy:
runs-on: ubuntu-latest
environment: Staging
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
FEATURE_FLAG_RATE_LIMIT: ${{ secrets.FEATURE_FLAG_RATE_LIMIT }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.ROLE_TO_ASSUME }}
aws-region: ap-southeast-1
- name: Deploy app
run: |
pnpm sst deploy --stage staging
uses: ./.github/workflows/sst.deploy.yml
with:
environment: Staging
sst-stage: staging
secrets: inherit

0 comments on commit 714376a

Please sign in to comment.