Skip to content

updating github environments #18

updating github environments

updating github environments #18

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:
name: Deploy to ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'Production' || 'Development' }}
runs-on: ubuntu-latest
environment: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'Production' || 'Development' }}
permissions:
deployments: write
pull-requests: write
steps:
- name: Set environment name
id: set-env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]] || [[ "${{ github.base_ref }}" == "main" ]]; then
echo "env_name=Production" >> $GITHUB_OUTPUT
echo "env_lower=production" >> $GITHUB_OUTPUT
else
echo "env_name=Development" >> $GITHUB_OUTPUT
echo "env_lower=development" >> $GITHUB_OUTPUT
fi
- name: Debug - Check Service ID
run: |
echo "Environment: ${{ steps.set-env.outputs.env_name }}"
echo "Service ID length: ${#RENDER_SERVICE_ID}"
echo "Service ID is set: $([[ -n "$RENDER_SERVICE_ID" ]] && echo "Yes" || echo "No")"
env:
RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
- 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: ${{ steps.set-env.outputs.env_name }}
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 = '${{ steps.set-env.outputs.env_name }}';
const commentIdentifier = `<!-- deployment-bot:${environment} -->`;
const comment = `${commentIdentifier}
### 🚀 ${environment === 'Production' ? 'Production Preview' : 'Preview'} Deployment Ready!
Your changes have been successfully deployed to the ${environment.toLowerCase()} ${environment === 'Production' ? 'preview ' : ''}environment.
**Preview URL:** ${deployUrl}
| Status | Environment | Commit | Time |
|--------|-------------|--------|------|
| ✅ Success | ${environment} | \`${context.sha.substring(0, 7)}\` | ${new Date().toISOString()} |
${environment === 'Production' ? '⚠️ **Note:** This is a preview deployment for the production environment. The actual production deployment will occur after merge.\n\n' : ''}---
<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
});
}