63
63
needs : build-docs
64
64
runs-on : ubuntu-latest
65
65
66
- if : startsWith(github.ref, 'refs/heads/release')
66
+ # Deploy on PRs targeting release branches
67
+ if : github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')
68
+
69
+ # Prevent multiple deployments from running simultaneously
70
+ concurrency :
71
+ group : deploy-docs-${{ github.base_ref }}
72
+ cancel-in-progress : false
73
+
74
+ env :
75
+ DOCS_BASE_URL : " https://crispy-winner-3jnj38w.pages.github.io"
76
+ DOCS_REPOSITORY : " ai-dynamo/dynamo-docs"
77
+ DOCS_BRANCH : " main"
78
+ DOCS_ARTIFACT_NAME : " dynamo-docs"
67
79
68
80
steps :
69
81
- name : Checkout source repo
@@ -72,22 +84,78 @@ jobs:
72
84
- name : Download documentation artifact
73
85
uses : actions/download-artifact@v4
74
86
with :
75
- name : dynamo-docs -${{ github.run_id }}
76
- path : dynamo-docs
87
+ name : ${{ env.DOCS_ARTIFACT_NAME }} -${{ github.run_id }}
88
+ path : ${{ env.DOCS_ARTIFACT_NAME }}
77
89
78
- - name : Clean potentially stale metadata files
90
+ - name : Clean potentially stale metadata files (but preserve index)
79
91
run : |
80
- rm -f ./dynamo-docs/CNAME
81
- rm -f ./dynamo-docs/_config.yml
82
- rm -f ./dynamo-docs/index.html || true
92
+ rm -f ./${{ env.DOCS_ARTIFACT_NAME }}/CNAME
93
+ rm -f ./${{ env.DOCS_ARTIFACT_NAME }}/_config.yml
94
+ # Don't remove index.html - it's needed for navigation
95
+
96
+ - name : Determine deployment directory
97
+ id : deploy_dir
98
+ run : |
99
+ # For PRs, use consistent directory (latest commit overwrites previous)
100
+ SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-8)
101
+ echo "dir_name=${{ github.base_ref }}/pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
102
+ echo "commit_ref=${{ github.sha }}" >> $GITHUB_OUTPUT
103
+ echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
83
104
84
105
- name : Deploy to internal GitHub Pages
85
106
uses : peaceiris/actions-gh-pages@v3
86
107
with :
87
108
personal_token : ${{ secrets.DOCS_TOKEN }}
88
- external_repository : ai-dynamo/dynamo-docs
89
- publish_branch : main
90
- publish_dir : ./dynamo-docs
91
- destination_dir : ${{ github.ref_name }}
92
- commit_message : ' Deploy documentation from ${{ github.repository }}@${{ github.sha }} (branch: ${{ github.ref_name }})'
109
+ external_repository : ${{ env.DOCS_REPOSITORY }}
110
+ publish_branch : ${{ env.DOCS_BRANCH }}
111
+ publish_dir : ./${{ env.DOCS_ARTIFACT_NAME }}
112
+ destination_dir : ${{ steps.deploy_dir.outputs.dir_name }}
113
+ commit_message : ' Deploy documentation from ${{ github.repository }}@${{ steps.deploy_dir.outputs.commit_ref }} (branch: ${{ steps.deploy_dir.outputs.dir_name }})'
93
114
keep_files : true
115
+
116
+ - name : Comment on PR with docs link
117
+ if : github.event_name == 'pull_request'
118
+ uses : actions/github-script@v7
119
+ with :
120
+ script : |
121
+ const docsUrl = `${{ env.DOCS_BASE_URL }}/${{ steps.deploy_dir.outputs.dir_name }}/`;
122
+ const comment = `## 📚 Documentation Preview
123
+
124
+ **📖 View Latest Documentation:** [${docsUrl}](${docsUrl})
125
+ > **Latest Deployment:**
126
+ > - **Commit:** [\`${{ steps.deploy_dir.outputs.short_sha }}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) *(latest push)*
127
+ > - **Target:** \`${{ github.base_ref }}\`
128
+ > - **Updated:** ${new Date().toLocaleString('en-US', { timeZone: 'UTC', timeStyle: 'short', dateStyle: 'short' })} UTC
129
+ >
130
+ > **Note:** This link always shows the documentation for the latest commit. It may take a few minutes for GitHub Pages to update after each push.
131
+ ---
132
+
133
+ *Auto-updated by the documentation deployment workflow*`;
134
+
135
+ // Find and update existing comment, or create new one
136
+ const { data: comments } = await github.rest.issues.listComments({
137
+ owner: context.repo.owner,
138
+ repo: context.repo.repo,
139
+ issue_number: context.issue.number,
140
+ });
141
+
142
+ const botComment = comments.find(comment =>
143
+ comment.user.type === 'Bot' &&
144
+ comment.body.includes('📚 Documentation Preview')
145
+ );
146
+
147
+ if (botComment) {
148
+ await github.rest.issues.updateComment({
149
+ owner: context.repo.owner,
150
+ repo: context.repo.repo,
151
+ comment_id: botComment.id,
152
+ body: comment
153
+ });
154
+ } else {
155
+ await github.rest.issues.createComment({
156
+ owner: context.repo.owner,
157
+ repo: context.repo.repo,
158
+ issue_number: context.issue.number,
159
+ body: comment
160
+ });
161
+ }
0 commit comments