Merge pull request #14 from hoangsonww/feat/add-ci-cd-deployment-pipe… #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI / CD Pipeline for Collabify | |
on: | |
push: | |
branches: [main, master] | |
pull_request: | |
branches: [main, master] | |
workflow_dispatch: | |
env: | |
NODE_VERSION: 18 | |
NPM_CONFIG_LEGACY_PEER_DEPS: true | |
jobs: | |
formatting: | |
name: "🔧 Format & Lint" | |
runs-on: ubuntu-latest | |
env: | |
FMT_LINT_B64: ${{ secrets.SCRIPT_FORMAT_LINT }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Decode & run format-lint | |
run: | | |
echo "$FMT_LINT_B64" | base64 --decode > fmt-lint.sh | |
chmod +x fmt-lint.sh | |
./fmt-lint.sh | |
testing: | |
name: "🧪 Test (Jest)" | |
runs-on: ubuntu-latest | |
needs: formatting | |
env: | |
TEST_B64: ${{ secrets.SCRIPT_TEST }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Decode & run tests | |
run: | | |
echo "$TEST_B64" | base64 --decode > test.sh | |
chmod +x test.sh | |
./test.sh | |
build: | |
name: "🏗 Build Next.js" | |
runs-on: ubuntu-latest | |
needs: testing | |
env: | |
BUILD_B64: ${{ secrets.SCRIPT_BUILD }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Decode & run build | |
run: | | |
echo "$BUILD_B64" | base64 --decode > build.sh | |
chmod +x build.sh | |
./build.sh | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nextjs-build | |
path: .next | |
docker: | |
name: "🐳 Build & Push Docker Image" | |
runs-on: ubuntu-latest | |
needs: testing | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Log in to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build & push Collabify image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/collabify:${{ github.sha }} | |
ghcr.io/${{ github.repository_owner }}/collabify:latest | |
build-args: | | |
NODE_ENV=production | |
deploy: | |
name: "🚀 Deploy to Vercel" | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- docker | |
env: | |
DEPLOY_B64: ${{ secrets.SCRIPT_DEPLOY }} | |
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Decode & run deploy | |
run: | | |
echo "$DEPLOY_B64" | base64 --decode > deploy.sh | |
chmod +x deploy.sh | |
./deploy.sh | |
complete: | |
name: "🎉 Pipeline Complete" | |
runs-on: ubuntu-latest | |
needs: deploy | |
env: | |
COMPLETE_B64: ${{ secrets.SCRIPT_COMPLETE }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Decode & run complete | |
run: | | |
echo "$COMPLETE_B64" | base64 --decode > complete.sh | |
chmod +x complete.sh | |
./complete.sh |