Skip to content

Commit 66f2477

Browse files
committed
changing environment strategy
1 parent 0f2a71d commit 66f2477

File tree

1 file changed

+85
-26
lines changed

1 file changed

+85
-26
lines changed

.github/workflows/deploy.yml

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,90 @@ concurrency:
1212
cancel-in-progress: false
1313

1414
jobs:
15-
deploy:
16-
name: Deploy to ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'Production' || 'Development' }}
15+
deploy-dev:
16+
name: Deploy to Development
1717
runs-on: ubuntu-latest
18-
environment: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'Production' || 'Development' }}
18+
environment: Development
19+
# ONLY run for dev branch pushes or PRs targeting dev
20+
if: github.ref == 'refs/heads/dev' || (github.event_name == 'pull_request' && github.base_ref == 'dev')
1921
permissions:
2022
deployments: write
2123
pull-requests: write
2224
steps:
23-
- name: Set environment name
24-
id: set-env
25-
run: |
26-
if [[ "${{ github.ref }}" == "refs/heads/main" ]] || [[ "${{ github.base_ref }}" == "main" ]]; then
27-
echo "env_name=Production" >> $GITHUB_OUTPUT
28-
echo "env_lower=production" >> $GITHUB_OUTPUT
29-
else
30-
echo "env_name=Development" >> $GITHUB_OUTPUT
31-
echo "env_lower=development" >> $GITHUB_OUTPUT
32-
fi
25+
- name: Trigger Render Deploy
26+
id: deploy
27+
uses: JorgeLNJunior/[email protected]
28+
with:
29+
service_id: ${{ secrets.RENDER_SERVICE_ID }}
30+
api_key: ${{ secrets.RENDER_API_KEY }}
31+
wait_deploy: true
32+
github_deployment: true
33+
deployment_environment: Development
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
3335

34-
- name: Debug - Check Service ID
35-
run: |
36-
echo "Environment: ${{ steps.set-env.outputs.env_name }}"
37-
echo "Service ID length: ${#RENDER_SERVICE_ID}"
38-
echo "Service ID is set: $([[ -n "$RENDER_SERVICE_ID" ]] && echo "Yes" || echo "No")"
39-
env:
40-
RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
41-
36+
- name: Comment on PR
37+
if: github.event_name == 'pull_request'
38+
uses: actions/github-script@v7
39+
with:
40+
github-token: ${{ secrets.GITHUB_TOKEN }}
41+
script: |
42+
const deployUrl = '${{ secrets.SITE_URL }}';
43+
const environment = 'Development';
44+
const commentIdentifier = `<!-- deployment-bot:${environment} -->`;
45+
46+
const comment = `${commentIdentifier}
47+
### 🚀 Preview Deployment Ready!
48+
49+
Your changes have been successfully deployed to the ${environment.toLowerCase()} environment.
50+
51+
**Preview URL:** ${deployUrl}
52+
53+
| Status | Environment | Commit | Time |
54+
|--------|-------------|--------|------|
55+
| ✅ Success | ${environment} | \`${context.sha.substring(0, 7)}\` | ${new Date().toISOString()} |
56+
57+
---
58+
<sub>🤖 This comment was automatically generated by the deployment workflow.</sub>`;
59+
60+
// Find existing comment
61+
const { data: comments } = await github.rest.issues.listComments({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: context.issue.number,
65+
});
66+
67+
const botComment = comments.find(comment =>
68+
comment.body.includes(commentIdentifier)
69+
);
70+
71+
if (botComment) {
72+
// Update existing comment
73+
await github.rest.issues.updateComment({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
comment_id: botComment.id,
77+
body: comment
78+
});
79+
} else {
80+
// Create new comment
81+
await github.rest.issues.createComment({
82+
issue_number: context.issue.number,
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
body: comment
86+
});
87+
}
88+
89+
deploy-prod:
90+
name: Deploy to Production
91+
runs-on: ubuntu-latest
92+
environment: Production
93+
# ONLY run for main branch pushes or PRs targeting main
94+
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.base_ref == 'main')
95+
permissions:
96+
deployments: write
97+
pull-requests: write
98+
steps:
4299
- name: Trigger Render Deploy
43100
id: deploy
44101
uses: JorgeLNJunior/[email protected]
@@ -47,7 +104,7 @@ jobs:
47104
api_key: ${{ secrets.RENDER_API_KEY }}
48105
wait_deploy: true
49106
github_deployment: true
50-
deployment_environment: ${{ steps.set-env.outputs.env_name }}
107+
deployment_environment: Production
51108
github_token: ${{ secrets.GITHUB_TOKEN }}
52109

53110
- name: Comment on PR
@@ -57,21 +114,23 @@ jobs:
57114
github-token: ${{ secrets.GITHUB_TOKEN }}
58115
script: |
59116
const deployUrl = '${{ secrets.SITE_URL }}';
60-
const environment = '${{ steps.set-env.outputs.env_name }}';
117+
const environment = 'Production';
61118
const commentIdentifier = `<!-- deployment-bot:${environment} -->`;
62119
63120
const comment = `${commentIdentifier}
64-
### 🚀 ${environment === 'Production' ? 'Production Preview' : 'Preview'} Deployment Ready!
121+
### 🚀 Production Preview Deployment Ready!
65122
66-
Your changes have been successfully deployed to the ${environment.toLowerCase()} ${environment === 'Production' ? 'preview ' : ''}environment.
123+
Your changes have been successfully deployed to the ${environment.toLowerCase()} preview environment.
67124
68125
**Preview URL:** ${deployUrl}
69126
70127
| Status | Environment | Commit | Time |
71128
|--------|-------------|--------|------|
72129
| ✅ Success | ${environment} | \`${context.sha.substring(0, 7)}\` | ${new Date().toISOString()} |
73130
74-
${environment === 'Production' ? '⚠️ **Note:** This is a preview deployment for the production environment. The actual production deployment will occur after merge.\n\n' : ''}---
131+
⚠️ **Note:** This is a preview deployment for the production environment. The actual production deployment will occur after merge.
132+
133+
---
75134
<sub>🤖 This comment was automatically generated by the deployment workflow.</sub>`;
76135
77136
// Find existing comment

0 commit comments

Comments
 (0)