Skip to content

Commit

Permalink
Setup initial CI and CD workflow files (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
FerdiHS authored Oct 12, 2024
1 parent 8d3f9bd commit 7063889
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test

- name: Build application
run: npm run build
28 changes: 28 additions & 0 deletions .github/workflows/deploy-live.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Live Deployment

on:
push:
branches:
- main
- staging

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
deploy-preproduction-preview:
uses: ./.github/workflows/deploy.yml
if: github.ref_name == 'staging'
with:
environment: preproduction
preview: false
secrets: inherit
deploy-production-preview:
uses: ./.github/workflows/deploy.yml
if: github.ref_name == 'main'
with:
environment: production
preview: false
secrets: inherit

28 changes: 28 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Preview Deployment

on:
pull_request:
branches:
- main
- staging

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
deploy-preproduction-preview:
uses: ./.github/workflows/deploy.yml
if: github.base_ref == 'staging'
with:
environment: preproduction
preview: true
secrets: inherit
deploy-production-preview:
uses: ./.github/workflows/deploy.yml
if: github.base_ref == 'main'
with:
environment: production
preview: true
secrets: inherit

60 changes: 60 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy to Vercel
on:
workflow_call:
inputs:
environment:
required: true
type: string
preview:
required: false
type: boolean
default: true

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
deploy-preview:
runs-on: ubuntu-latest
needs: test
environment: ${{ inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up environment variables
run: |
echo "VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}" >> $GITHUB_ENV
echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}" >> $GITHUB_ENV
if [ ${{ inputs.preview }} = true ]; then
echo "VERCEL_ENVIRONMENT=preview" >> $GITHUB_ENV
echo "VERCEL_DEPLOYMENT_FLAG=" >> $GITHUB_ENV
else
echo "VERCEL_ENVIRONMENT=production" >> $GITHUB_ENV
echo "VERCEL_DEPLOYMENT_FLAG=--prod" >> $GITHUB_ENV
fi
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Install Vercel CLI
run: npm install -g vercel
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy to Vercel Preview
run: vercel $VERCEL_DEPLOYMENT_FLAG --token=${{ secrets.VERCEL_TOKEN }}

0 comments on commit 7063889

Please sign in to comment.