Skip to content

feat(task-runner): enhance custom command execution and improve depen… #14

feat(task-runner): enhance custom command execution and improve depen…

feat(task-runner): enhance custom command execution and improve depen… #14

name: 🔧 Deploy Backend to Google Apps Script

Check failure on line 1 in .github/workflows/deploy-backend.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy-backend.yml

Invalid workflow file

(Line: 102, Col: 9): 'run' is already defined
on:
# Manually triggered only - backend deployed with care
workflow_dispatch:
inputs:
deploy_description:
description: "Deployment description"
required: false
default: "Manual deployment from GitHub Actions"
enable_deployment:
description: "Enable deployment (set to true to actually deploy)"
required: true
default: "false"
type: choice
options:
- "false"
- "true"
environment:
description: "Target environment"
required: true
default: "production"
type: choice
options:
- "development"
- "staging"
- "production"
permissions:
contents: write
pull-requests: write
env:
NODE_VERSION: "20"
jobs:
validate:
name: 🔍 Validation
runs-on: ubuntu-latest
outputs:
backend-changed: ${{ steps.changes.outputs.backend }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect backend changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
backend:
- 'backend/**'
- name: Validate deployment conditions
run: |
echo "🔍 Validating deployment conditions..."
echo "- Enable deployment: ${{ github.event.inputs.enable_deployment }}"
echo "- Target environment: ${{ github.event.inputs.environment }}"
echo "- Backend changed: ${{ steps.changes.outputs.backend }}"
if [[ "${{ github.event.inputs.enable_deployment }}" != "true" ]]; then
echo "❌ Deployment not enabled - set enable_deployment to 'true' to deploy"
exit 1
fi
echo "✅ Validation passed"
deploy:
name: 🚀 Deploy Backend
runs-on: ubuntu-latest
needs: [validate]
# Only run if manually triggered with enable_deployment set to true
if: github.event.inputs.enable_deployment == 'true'
defaults:
run:
working-directory: ./backend
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"
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Verify setup
run: |
echo "🔍 Verifying backend setup..."
npm run verify || echo "⚠️ Setup verification completed with warnings"
- name: Install Google Apps Script CLI
run: npm install -g @google/clasp
run: npm install -g @google/clasp
- name: Create .clasprc.json
run: |
echo '${{ secrets.CLASPRC_JSON }}' > ~/.clasprc.json
- name: Setup environment variables
run: |
echo "CLASP_SCRIPT_ID=${{ secrets.CLASP_SCRIPT_ID }}" > .env
echo "DEPLOYMENT_DESCRIPTION=${{ github.event.inputs.deploy_description || 'Automated deployment from GitHub Actions' }}" >> .env
echo "DEPLOYMENT_VERSION_DESCRIPTION=Deploy from commit ${{ github.sha }}" >> .env
- name: Validate environment
run: |
if [ -z "${{ secrets.CLASP_SCRIPT_ID }}" ]; then
echo "Error: CLASP_SCRIPT_ID secret is not set"
exit 1
fi
if [ -z "${{ secrets.CLASPRC_JSON }}" ]; then
echo "Error: CLASPRC_JSON secret is not set"
exit 1
fi
- name: Deploy to Google Apps Script
id: deploy
run: |
# Update .clasp.json with script ID
cat > .clasp.json << EOF
{
"scriptId": "${{ secrets.CLASP_SCRIPT_ID }}",
"rootDir": "",
"scriptExtensions": [".js", ".gs"],
"htmlExtensions": [".html"],
"jsonExtensions": [".json"],
"filePushOrder": [],
"skipSubdirectories": false
}
EOF
# Push code
clasp push --force
# Deploy and capture deployment ID
DEPLOY_OUTPUT=$(clasp deploy --description "${{ github.event.inputs.deploy_description || 'Automated deployment from GitHub Actions' }}")
echo "Deploy output: $DEPLOY_OUTPUT"
# Extract deployment ID from output (format: "Deployed AKfycby... @version")
DEPLOYMENT_ID=$(echo "$DEPLOY_OUTPUT" | grep -o 'AK[a-zA-Z0-9_-]*')
if [ -n "$DEPLOYMENT_ID" ]; then
echo "🎉 Deployment successful!"
echo "📋 Deployment ID: $DEPLOYMENT_ID"
echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
else
echo "❌ Failed to extract deployment ID"
exit 1
fi
- name: Update Frontend Configuration
if: steps.deploy.outputs.deployment_id
run: |
cd ../frontend/src/config
# Update environment.ts with new deployment ID
sed -i "s/AK[a-zA-Z0-9_-]*/\${{ steps.deploy.outputs.deployment_id }}/g" environment.ts
echo "✅ Updated frontend configuration with deployment ID: ${{ steps.deploy.outputs.deployment_id }}"
- name: Update Test Script
if: steps.deploy.outputs.deployment_id
run: |
cd ..
# Update test script with new deployment ID
sed -i "s/AK[a-zA-Z0-9_-]*/\${{ steps.deploy.outputs.deployment_id }}/g" test-cors-api.sh
echo "✅ Updated test script with deployment ID: ${{ steps.deploy.outputs.deployment_id }}"
- name: Commit Configuration Updates
if: steps.deploy.outputs.deployment_id
run: |
cd ..
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add and commit changes
git add frontend/src/config/environment.ts test-cors-api.sh
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore(deploy): update API endpoint to deployment ${{ steps.deploy.outputs.deployment_id }}
- Updated frontend configuration with new Google Apps Script deployment ID
- Updated test script with new endpoint
- Auto-generated by backend deployment workflow"
git push
echo "✅ Configuration updates committed and pushed"
fi
- name: Clean up credentials
if: always()
run: |
rm -f ~/.clasprc.json
rm -f .env
rm -f .clasp.json