Skip to content

changing environment strategy #20

changing environment strategy

changing environment strategy #20

Workflow file for this run

name: Deploy to Render
on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
# Prevent multiple concurrent deployments
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
deploy-dev:
name: Deploy to Development
runs-on: ubuntu-latest
environment: Development
# ONLY run for dev branch pushes or PRs targeting dev
if: github.ref == 'refs/heads/dev' || (github.event_name == 'pull_request' && github.base_ref == 'dev')
permissions:
deployments: write
pull-requests: write
steps:
- name: Debug Secrets and Environment
run: |
echo "=== DEBUGGING DEVELOPMENT DEPLOYMENT ==="
echo "GitHub Ref: ${{ github.ref }}"
echo "GitHub Event: ${{ github.event_name }}"
echo "GitHub Base Ref: ${{ github.base_ref }}"
echo "Environment: Development"
echo ""
echo "=== CHECKING SECRETS ==="
echo "RENDER_SERVICE_ID exists: ${{ secrets.RENDER_SERVICE_ID != '' }}"
echo "RENDER_SERVICE_ID length: ${#RENDER_SERVICE_ID}"
echo "RENDER_SERVICE_ID value: ${{ secrets.RENDER_SERVICE_ID }}"
echo "RENDER_SERVICE_ID (first 10 chars): ${RENDER_SERVICE_ID:0:10}..."
echo ""
echo "RENDER_API_KEY exists: ${{ secrets.RENDER_API_KEY != '' }}"
echo "RENDER_API_KEY length: ${#RENDER_API_KEY}"
echo "RENDER_API_KEY value: ${{ secrets.RENDER_API_KEY }}"
echo "RENDER_API_KEY (first 10 chars): ${RENDER_API_KEY:0:10}..."
echo ""
echo "SITE_URL exists: ${{ secrets.SITE_URL != '' }}"
echo "SITE_URL value: ${{ secrets.SITE_URL }}"
echo ""
echo "=== ENVIRONMENT VARIABLES ==="
env | grep -E "(RENDER|GITHUB)" || true
echo ""
echo "=== TESTING RENDER API ==="
echo "Testing API connection with service ID: ${{ secrets.RENDER_SERVICE_ID }}"
curl -v -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \
"https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}" || true
echo ""
echo "=== LISTING ALL SERVICES (for debugging) ==="
curl -v -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \
"https://api.render.com/v1/services?limit=100" || true
env:
RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
- name: Trigger Render Deploy
id: deploy
uses: JorgeLNJunior/[email protected]
with:
service_id: ${{ secrets.RENDER_SERVICE_ID }}
api_key: ${{ secrets.RENDER_API_KEY }}
wait_deploy: true
github_deployment: true
deployment_environment: Development
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const deployUrl = '${{ secrets.SITE_URL }}';
const environment = 'Development';
const commentIdentifier = `<!-- deployment-bot:${environment} -->`;
const comment = `${commentIdentifier}
### 🚀 Preview Deployment Ready!
Your changes have been successfully deployed to the ${environment.toLowerCase()} environment.
**Preview URL:** ${deployUrl}
| Status | Environment | Commit | Time |
|--------|-------------|--------|------|
| ✅ Success | ${environment} | \`${context.sha.substring(0, 7)}\` | ${new Date().toISOString()} |
---
<sub>🤖 This comment was automatically generated by the deployment workflow.</sub>`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.body.includes(commentIdentifier)
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
deploy-prod:
name: Deploy to Production
runs-on: ubuntu-latest
environment: Production
# ONLY run for main branch pushes or PRs targeting main
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.base_ref == 'main')
permissions:
deployments: write
pull-requests: write
steps:
- name: Debug Secrets and Environment
run: |
echo "=== DEBUGGING PRODUCTION DEPLOYMENT ==="
echo "GitHub Ref: ${{ github.ref }}"
echo "GitHub Event: ${{ github.event_name }}"
echo "GitHub Base Ref: ${{ github.base_ref }}"
echo "Environment: Production"
echo ""
echo "=== CHECKING SECRETS ==="
echo "RENDER_SERVICE_ID exists: ${{ secrets.RENDER_SERVICE_ID != '' }}"
echo "RENDER_SERVICE_ID length: ${#RENDER_SERVICE_ID}"
echo "RENDER_SERVICE_ID value: ${{ secrets.RENDER_SERVICE_ID }}"
echo "RENDER_SERVICE_ID (first 10 chars): ${RENDER_SERVICE_ID:0:10}..."
echo ""
echo "RENDER_API_KEY exists: ${{ secrets.RENDER_API_KEY != '' }}"
echo "RENDER_API_KEY length: ${#RENDER_API_KEY}"
echo "RENDER_API_KEY value: ${{ secrets.RENDER_API_KEY }}"
echo "RENDER_API_KEY (first 10 chars): ${RENDER_API_KEY:0:10}..."
echo ""
echo "SITE_URL exists: ${{ secrets.SITE_URL != '' }}"
echo "SITE_URL value: ${{ secrets.SITE_URL }}"
echo ""
echo "=== ENVIRONMENT VARIABLES ==="
env | grep -E "(RENDER|GITHUB)" || true
echo ""
echo "=== TESTING RENDER API ==="
echo "Testing API connection with service ID: ${{ secrets.RENDER_SERVICE_ID }}"
curl -v -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \
"https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}" || true
echo ""
echo "=== LISTING ALL SERVICES (for debugging) ==="
curl -v -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \
"https://api.render.com/v1/services?limit=100" || true
env:
RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
- name: Trigger Render Deploy
id: deploy
uses: JorgeLNJunior/[email protected]
with:
service_id: ${{ secrets.RENDER_SERVICE_ID }}
api_key: ${{ secrets.RENDER_API_KEY }}
wait_deploy: true
github_deployment: true
deployment_environment: Production
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const deployUrl = '${{ secrets.SITE_URL }}';
const environment = 'Production';
const commentIdentifier = `<!-- deployment-bot:${environment} -->`;
const comment = `${commentIdentifier}
### 🚀 Production Preview Deployment Ready!
Your changes have been successfully deployed to the ${environment.toLowerCase()} preview environment.
**Preview URL:** ${deployUrl}
| Status | Environment | Commit | Time |
|--------|-------------|--------|------|
| ✅ Success | ${environment} | \`${context.sha.substring(0, 7)}\` | ${new Date().toISOString()} |
⚠️ **Note:** This is a preview deployment for the production environment. The actual production deployment will occur after merge.
---
<sub>🤖 This comment was automatically generated by the deployment workflow.</sub>`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.body.includes(commentIdentifier)
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}