|
8 | 8 | branches: [ main ] |
9 | 9 | types: [completed] |
10 | 10 |
|
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + deployments: write |
| 14 | + issues: write |
| 15 | + pull-requests: write |
| 16 | + statuses: write |
| 17 | + |
11 | 18 | env: |
12 | 19 | NODE_VERSION: '18' |
13 | 20 | VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
@@ -95,16 +102,35 @@ jobs: |
95 | 102 |
|
96 | 103 | - name: Create deployment status |
97 | 104 | uses: actions/github-script@v7 |
| 105 | + continue-on-error: true |
98 | 106 | with: |
99 | 107 | script: | |
100 | | - github.rest.repos.createDeploymentStatus({ |
101 | | - owner: context.repo.owner, |
102 | | - repo: context.repo.repo, |
103 | | - deployment_id: context.payload.deployment?.id || 0, |
104 | | - state: 'success', |
105 | | - environment_url: '${{ steps.deploy.outputs.production_url }}', |
106 | | - description: 'Deployment completed successfully' |
107 | | - }) |
| 108 | + try { |
| 109 | + // Create a deployment record first |
| 110 | + const deployment = await github.rest.repos.createDeployment({ |
| 111 | + owner: context.repo.owner, |
| 112 | + repo: context.repo.repo, |
| 113 | + ref: context.sha, |
| 114 | + environment: 'production', |
| 115 | + description: 'Production deployment', |
| 116 | + auto_merge: false, |
| 117 | + required_contexts: [] |
| 118 | + }); |
| 119 | + |
| 120 | + // Then create the deployment status |
| 121 | + if (deployment.data.id) { |
| 122 | + await github.rest.repos.createDeploymentStatus({ |
| 123 | + owner: context.repo.owner, |
| 124 | + repo: context.repo.repo, |
| 125 | + deployment_id: deployment.data.id, |
| 126 | + state: 'success', |
| 127 | + environment_url: '${{ steps.deploy.outputs.production_url }}', |
| 128 | + description: 'Deployment completed successfully' |
| 129 | + }); |
| 130 | + } |
| 131 | + } catch (error) { |
| 132 | + console.log('Deployment status creation failed:', error.message); |
| 133 | + } |
108 | 134 |
|
109 | 135 | # Post-Deployment Tests |
110 | 136 | post-deploy-tests: |
@@ -152,21 +178,49 @@ jobs: |
152 | 178 | runs-on: ubuntu-latest |
153 | 179 | needs: [deploy-production, post-deploy-tests] |
154 | 180 | if: always() && github.ref == 'refs/heads/main' |
| 181 | + permissions: |
| 182 | + contents: write |
| 183 | + issues: write |
| 184 | + pull-requests: write |
155 | 185 | steps: |
156 | 186 | - name: Notify deployment status |
157 | 187 | uses: actions/github-script@v7 |
| 188 | + continue-on-error: true |
158 | 189 | with: |
159 | 190 | script: | |
160 | | - const status = '${{ needs.deploy-production.result }}' === 'success' && '${{ needs.post-deploy-tests.result }}' === 'success' ? '✅ Success' : '❌ Failed'; |
161 | | - const url = '${{ needs.deploy-production.outputs.production_url }}'; |
162 | | - |
163 | | - github.rest.repos.createCommitComment({ |
164 | | - owner: context.repo.owner, |
165 | | - repo: context.repo.repo, |
166 | | - commit_sha: context.sha, |
167 | | - body: `🚀 **Deployment ${status}** |
| 191 | + try { |
| 192 | + const deployResult = '${{ needs.deploy-production.result }}'; |
| 193 | + const testResult = '${{ needs.post-deploy-tests.result }}'; |
| 194 | + const status = deployResult === 'success' && testResult === 'success' ? '✅ Success' : '❌ Failed'; |
| 195 | + const url = '${{ needs.deploy-production.outputs.production_url }}' || 'URL not available'; |
168 | 196 | |
169 | | - Production URL: ${url} |
| 197 | + const body = `🚀 **Deployment ${status}** |
170 | 198 | |
171 | | - The TOC Simulator has been deployed and is ready for use!` |
172 | | - }) |
| 199 | + **Deployment Result**: ${deployResult} |
| 200 | + **Tests Result**: ${testResult} |
| 201 | + **Production URL**: ${url} |
| 202 | + |
| 203 | + The TOC Simulator deployment process has completed!`; |
| 204 | + |
| 205 | + await github.rest.repos.createCommitComment({ |
| 206 | + owner: context.repo.owner, |
| 207 | + repo: context.repo.repo, |
| 208 | + commit_sha: context.sha, |
| 209 | + body: body |
| 210 | + }); |
| 211 | + |
| 212 | + console.log('Deployment notification sent successfully'); |
| 213 | + } catch (error) { |
| 214 | + console.log('Failed to create deployment notification:', error.message); |
| 215 | + // Try alternative notification method |
| 216 | + try { |
| 217 | + await github.rest.issues.create({ |
| 218 | + owner: context.repo.owner, |
| 219 | + repo: context.repo.repo, |
| 220 | + title: `Deployment Status - ${new Date().toISOString()}`, |
| 221 | + body: `Deployment completed with status: ${{ needs.deploy-production.result }}` |
| 222 | + }); |
| 223 | + } catch (fallbackError) { |
| 224 | + console.log('Fallback notification also failed:', fallbackError.message); |
| 225 | + } |
| 226 | + } |
0 commit comments