Skip to content

Deploy

Deploy #17

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
tags: ['v*']
workflow_run:
workflows: [CI]
branches: [main]
types: [completed]
env:
NODE_VERSION: '18'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'
environment:
name: staging
url: https://staging.graphdone.app
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build for production
run: npm run build
env:
NODE_ENV: production
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to staging
run: |
echo "🎭 Deploying to staging environment..."
# Add your staging deployment logic here
# For example: kubectl, docker-compose, or cloud provider CLI
echo "✅ Deployed to staging"
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: production
url: https://graphdone.app
needs: []
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build for production
run: npm run build
env:
NODE_ENV: production
- name: Run production tests
run: npm run test
env:
NODE_ENV: production
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to production
run: |
echo "🏭 Deploying to production environment..."
# Add your production deployment logic here
# For example: kubectl, docker-compose, or cloud provider CLI
echo "✅ Deployed to production"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
notify:
name: Notify
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: always()
steps:
- name: Notification
run: |
if [[ "${{ needs.deploy-staging.result }}" == "success" ]]; then
echo "🎉 Staging deployment successful!"
fi
if [[ "${{ needs.deploy-production.result }}" == "success" ]]; then
echo "🚀 Production deployment successful!"
fi
# Add notification logic here (Slack, Discord, etc.)