1010 runs-on : ubuntu-latest
1111 permissions :
1212 pull-requests : write
13+ deployments : write
1314 steps :
1415 - uses : actions/checkout@v4
1516
@@ -23,11 +24,39 @@ jobs:
2324
2425 - name : Deploy to Netlify (Production)
2526 if : github.event_name == 'push' && github.ref == 'refs/heads/main'
26- run : npx netlify-cli deploy --dir=public --prod
27+ id : production
28+ run : |
29+ OUTPUT=$(npx netlify-cli deploy --dir=public --prod --json)
30+ DEPLOY_URL=$(echo "$OUTPUT" | jq -r '.deploy_url')
31+ echo "deploy_url=$DEPLOY_URL" >> "$GITHUB_OUTPUT"
2732 env :
2833 NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
2934 NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
3035
36+ - name : Register production deployment
37+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
38+ uses : actions/github-script@v7
39+ with :
40+ script : |
41+ const deployment = await github.rest.repos.createDeployment({
42+ owner: context.repo.owner,
43+ repo: context.repo.repo,
44+ ref: context.sha,
45+ environment: 'production',
46+ auto_merge: false,
47+ required_contexts: [],
48+ transient_environment: false,
49+ production_environment: true,
50+ });
51+ await github.rest.repos.createDeploymentStatus({
52+ owner: context.repo.owner,
53+ repo: context.repo.repo,
54+ deployment_id: deployment.data.id,
55+ state: 'success',
56+ environment_url: 'https://easypdf-lite.netlify.app',
57+ log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
58+ });
59+
3160 - name : Deploy to Netlify (Preview)
3261 if : github.event_name == 'pull_request'
3362 id : preview
3968 NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
4069 NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
4170
71+ - name : Register preview deployment
72+ if : github.event_name == 'pull_request'
73+ uses : actions/github-script@v7
74+ with :
75+ script : |
76+ const url = '${{ steps.preview.outputs.deploy_url }}';
77+ const deployment = await github.rest.repos.createDeployment({
78+ owner: context.repo.owner,
79+ repo: context.repo.repo,
80+ ref: context.payload.pull_request.head.sha,
81+ environment: 'preview',
82+ auto_merge: false,
83+ required_contexts: [],
84+ transient_environment: true,
85+ production_environment: false,
86+ });
87+ await github.rest.repos.createDeploymentStatus({
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ deployment_id: deployment.data.id,
91+ state: 'success',
92+ environment_url: url,
93+ log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
94+ });
95+
4296 - name : Update PR description with preview URL
4397 if : github.event_name == 'pull_request'
4498 uses : actions/github-script@v7
@@ -57,13 +111,11 @@ jobs:
57111 let body = pr.body || '';
58112
59113 if (body.includes(marker)) {
60- // Replace existing preview block
61114 body = body.replace(
62115 new RegExp(`${marker}[\\s\\S]*$`),
63116 previewBlock
64117 );
65118 } else {
66- // Append preview block
67119 body = body.trimEnd() + '\n\n' + previewBlock;
68120 }
69121
0 commit comments