Skip to content

Commit

Permalink
Merge pull request #39 from ahmed-deriv/feature/RestAPI-Platform
Browse files Browse the repository at this point in the history
Feature/rest api platform
  • Loading branch information
ahmed-deriv authored Jan 21, 2025
2 parents a564773 + 577624f commit 0934bcc
Show file tree
Hide file tree
Showing 11 changed files with 612 additions and 14 deletions.
101 changes: 101 additions & 0 deletions .github/actions/deploy/vercel/development/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: 'Deploy to Vercel Development'
description: 'Deploys the application to Vercel Preview environment'

inputs:
vercel-token:
description: 'Vercel authentication token'
required: true
vercel-org-id:
description: 'Vercel organization ID'
required: true
vercel-project-id:
description: 'Vercel project ID'
required: true
pr-number:
description: 'Pull request number'
required: true

outputs:
deployment-url:
description: 'The URL of the deployed application'
value: ${{ steps.deploy.outputs.url }}
deployment-id:
description: 'The ID of the deployment'
value: ${{ steps.deploy.outputs.id }}

runs:
using: 'composite'
steps:
- name: Pull Vercel Environment Information
shell: bash
run: |
echo "πŸ”„ Pulling Vercel environment information..."
echo " - Environment: Preview"
echo " - PR Number: ${{ inputs.pr-number }}"
vercel pull --yes --environment=preview --token=${{ inputs.vercel-token }}
echo "βœ… Successfully pulled Vercel environment information"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}

- name: Build Project
shell: bash
run: |
echo "πŸ—οΈ Starting build process for preview deployment..."
echo "πŸ“ Exporting environment variables..."
# Export all GitHub secrets as environment variables
for secret in $(env | grep "GITHUB_.*=" | cut -d= -f1); do
echo " - Exporting $secret"
echo "$secret=${!secret}" >> $GITHUB_ENV
done
for secret in $(env | grep "INPUT_.*=" | cut -d= -f1); do
# Convert INPUT_VERCEL_TOKEN to VERCEL_TOKEN etc.
clean_name=$(echo "$secret" | sed 's/^INPUT_//' | tr '[:upper:]' '[:lower:]')
echo " - Converting and exporting $secret as $clean_name"
echo "$clean_name=${!secret}" >> $GITHUB_ENV
done
echo "πŸš€ Running build command..."
npm run build
echo "πŸ“¦ Checking build output..."
if [ -d "dist" ]; then
echo " - dist directory exists"
echo " - Contents of dist directory:"
ls -la dist/
else
echo "❌ dist directory not found!"
exit 1
fi
echo "βœ… Preview build completed successfully"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}

- name: Deploy to Vercel
id: deploy
shell: bash
run: |
echo "πŸš€ Starting Vercel preview deployment..."
echo "πŸ“‚ Deploying dist directory..."
echo " - Current directory contents:"
ls -la dist/
echo "☁️ Deploying to Vercel preview environment..."
DEPLOYMENT=$(vercel deploy --cwd dist --token=${{ inputs.vercel-token }} --yes)
DEPLOYMENT_URL="$DEPLOYMENT"
DEPLOYMENT_ID=$(echo "$DEPLOYMENT" | rev | cut -d'/' -f1 | rev)
echo " - Deployment URL: $DEPLOYMENT_URL"
echo " - Deployment ID: $DEPLOYMENT_ID"
echo "πŸ’Ύ Saving deployment information..."
echo "url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
echo "id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
echo "βœ… Preview deployment completed successfully"
echo "🌍 Preview URL: $DEPLOYMENT_URL"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
94 changes: 94 additions & 0 deletions .github/actions/deploy/vercel/production/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: 'Deploy to Vercel Production'
description: 'Deploys the application to Vercel Production environment'

inputs:
vercel-token:
description: 'Vercel authentication token'
required: true
vercel-org-id:
description: 'Vercel organization ID'
required: true
vercel-project-id:
description: 'Vercel project ID'
required: true
sha:
description: 'Git commit SHA'
required: true

outputs:
deployment-url:
description: 'The URL of the deployed application'
value: ${{ steps.deploy.outputs.url }}

runs:
using: 'composite'
steps:
- name: Pull Vercel Environment Information
shell: bash
run: |
echo "πŸ”„ Pulling Vercel environment information..."
vercel pull --yes --environment=production --token=${{ inputs.vercel-token }}
echo "βœ… Successfully pulled Vercel environment information"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}

- name: Build Project
shell: bash
run: |
echo "πŸ—οΈ Starting build process..."
echo "πŸ“ Exporting environment variables..."
# Export all GitHub secrets as environment variables
for secret in $(env | grep "GITHUB_.*=" | cut -d= -f1); do
echo " - Exporting $secret"
echo "$secret=${!secret}" >> $GITHUB_ENV
done
for secret in $(env | grep "INPUT_.*=" | cut -d= -f1); do
# Convert INPUT_VERCEL_TOKEN to VERCEL_TOKEN etc.
clean_name=$(echo "$secret" | sed 's/^INPUT_//' | tr '[:upper:]' '[:lower:]')
echo " - Converting and exporting $secret as $clean_name"
echo "$clean_name=${!secret}" >> $GITHUB_ENV
done
echo "πŸš€ Installing all dependencies..."
npm ci --include=dev
echo "πŸš€ Running build command..."
npm run build
echo "πŸ“¦ Checking build output..."
if [ -d "dist" ]; then
echo " - dist directory exists"
echo " - Contents of dist directory:"
ls -la dist/
else
echo "❌ dist directory not found!"
exit 1
fi
echo "βœ… Build completed successfully"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}

- name: Deploy to Vercel
id: deploy
shell: bash
run: |
echo "πŸš€ Starting Vercel deployment..."
echo "πŸ“‚ Deploying dist directory..."
echo " - Current directory contents:"
ls -la dist/
echo "☁️ Deploying to Vercel..."
DEPLOYMENT_URL=$(vercel deploy --cwd dist --prod --token=${{ inputs.vercel-token }} --yes)
echo " - Deployment URL: $DEPLOYMENT_URL"
echo "πŸ’Ύ Saving deployment URL..."
echo "url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
echo "βœ… Deployment completed successfully"
echo "🌍 Production URL: $DEPLOYMENT_URL"
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
50 changes: 50 additions & 0 deletions .github/actions/deployment-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Update Deployment Status'
description: 'Updates the deployment status in GitHub'

inputs:
environment:
description: 'The deployment environment (production/preview)'
required: true
deployment-url:
description: 'The URL of the deployed application'
required: true
sha:
description: 'Git commit SHA'
required: true
status:
description: 'Deployment status (success/failure)'
required: true
description:
description: 'Status description'
required: true

runs:
using: 'composite'
steps:
- name: Update deployment status
shell: bash
run: |
echo "πŸ”„ Updating deployment status..."
echo " - Environment: ${{ inputs.environment }}"
echo " - Status: ${{ inputs.status }}"
echo " - URL: ${{ inputs.deployment-url }}"
echo " - Commit SHA: ${{ inputs.sha }}"
echo "πŸ“ Creating deployment record..."
DEPLOYMENT_ID=$(curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"ref\":\"${{ inputs.sha }}\",\"environment\":\"${{ inputs.environment }}\",\"auto_merge\":false}" \
"https://api.github.com/repos/${{ github.repository }}/deployments" | jq -r '.id')
echo " - Created deployment with ID: $DEPLOYMENT_ID"
echo "πŸ“€ Updating deployment status..."
STATUS_RESPONSE=$(curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"state\":\"${{ inputs.status }}\",\"environment_url\":\"${{ inputs.deployment-url }}\",\"description\":\"${{ inputs.description }}\"}" \
"https://api.github.com/repos/${{ github.repository }}/deployments/$DEPLOYMENT_ID/statuses")
echo "βœ… Deployment status updated successfully"
echo " - Description: ${{ inputs.description }}"
34 changes: 34 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Setup Environment'
description: 'Sets up Node.js and installs dependencies'

runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
shell: bash
run: |
echo "πŸ”§ Setting up environment..."
echo "πŸ“¦ Node.js version:"
node --version
echo "πŸ“¦ NPM version:"
npm --version
echo "πŸ“₯ Installing dependencies..."
npm ci
echo "πŸ”§ Installing Vercel CLI..."
npm install --global vercel@latest
echo " - Vercel CLI version:"
vercel --version
echo "πŸ“‹ Listing installed packages:"
npm list --depth=0
echo "βœ… Environment setup completed successfully"
Loading

0 comments on commit 0934bcc

Please sign in to comment.