@@ -8,8 +8,9 @@ name: Deploy Preview
88
99concurrency :
1010 # Use github.event.pull_request.number on pull requests, so it's unique per pull request
11+ # Use github.event.issue.number on issue comments, so it's unique per comment
1112 # Use github.ref on other branches, so it's unique per branch
12- group : ${{ github.workflow }}-${{ github.event.pull_request. number || github.event.issue. number || github.ref }}
13+ group : ${{ github.workflow }}-${{ ( github.event.pull_request && format('PR-{0}', github.event.pull_request. number)) || ( github.event.issue && format('comment-{0}', github.event.issue. number) ) || github.ref }}
1314 cancel-in-progress : true
1415
1516jobs :
@@ -23,10 +24,25 @@ jobs:
2324 echo "::error title=Manual action required for preview::PR from fork can't be deployed as preview to Netlify automatically. Use '/deploy-preview' command in comments to trigger the preview manually."
2425 shell : bash
2526
27+ role-of-commenter :
28+ if : github.event.issue.pull_request
29+ runs-on : ubuntu-latest
30+ steps :
31+ - name : Check if commenter is a member, owner or collaborator
32+ id : commenter-check
33+ env :
34+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
35+ run : |
36+ commenter_role=$(gh api repos/$GITHUB_REPOSITORY/collaborators/${{ github.event.comment.user.login }}/permission --jq '.permission')
37+ echo "commenter_role=$commenter_role" >> "$GITHUB_OUTPUT"
38+ echo "author_association=${{ github.event.comment.author_association }}" >> "$GITHUB_OUTPUT"
39+ shell : bash
40+
2641 build-deploy-preview :
2742 # Deploy a preview only if
2843 # - the PR is not from a fork,
2944 # - requested by PR comment /deploy-preview, from a repo user or github action bot (user id 41898282)
45+ # FIXME: We need to change the way we filter because somehow some MEMBER in API are seen as CONTRIBUTOR in CI
3046 if : >
3147 (
3248 github.event_name == 'pull_request' &&
3652 github.event.issue.pull_request &&
3753 (
3854 github.event.comment.user.id == '41898282' ||
55+ github.event.comment.user.login == 'gordonwoodhull' ||
3956 github.event.comment.author_association == 'MEMBER' ||
4057 github.event.comment.author_association == 'OWNER' ||
4158 github.event.comment.author_association == 'COLLABORATOR'
@@ -102,8 +119,72 @@ jobs:
102119 Deploy from GHA: ${{ github.event.pull_request.title || format('manual from PR {0}', github.event.issue.number) }}
103120 alias : deploy-preview-${{ github.event.pull_request.number || github.event.issue.number }}
104121 # these all default to 'true'
105- enable-pull-request-comment : true
122+ enable-pull-request-comment : false
106123 enable-commit-comment : false
107124 enable-commit-status : true
108125 overwrites-pull-request-comment : false
109126 timeout-minutes : 1
127+
128+ - name : Get changed files
129+ id : changed-files
130+ uses :
tj-actions/[email protected] 131+ with :
132+ files : |
133+ # don't consider modifications on file used for includes for now.
134+ docs/**/[^_]*.qmd
135+ docs/**/[^_]*.md
136+ docs/extensions/listings/*.yml
137+ json : true
138+ escape_json : false
139+
140+ - name : Create custom PR comment
141+ if : github.event.pull_request || github.event.issue.pull_request
142+ uses : actions/github-script@v7
143+ env :
144+ DEPLOY_URL : ${{ steps.netlify-deploy.outputs.deploy-url }}
145+ CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_files }}
146+ with :
147+ github-token : ${{ secrets.GITHUB_TOKEN }}
148+ script : |
149+ const prNumber = context.payload.pull_request?.number || context.payload.issue.number;
150+ const deployUrl = process.env.DEPLOY_URL;
151+ const changedFiles = JSON.parse(process.env.CHANGED_FILES);
152+
153+ let commentBody = `## 📝 Preview Deployment\n\n`;
154+ commentBody += `🔍 Full site preview: [${deployUrl}](${deployUrl})\n\n`;
155+
156+ if (changedFiles.length > 0) {
157+ commentBody += `### 🔄 Modified Documents\n\n`;
158+ changedFiles.forEach(file => {
159+ let fileUrlPath;
160+
161+ // Define a mapping for special files to their corresponding URLs
162+ const specialFileMapping = {
163+ 'docs/extensions/listings/shortcodes-and-filters.yml': 'docs/extensions/index.html',
164+ 'docs/extensions/listings/journal-articles.yml': 'docs/extensions/index.html',
165+ 'docs/extensions/listings/custom-formats.yml': 'docs/extensions/index.html',
166+ 'docs/extensions/listings/revealjs-formats.yml': 'docs/extensions/index.html',
167+ 'docs/extensions/listings/revealjs.yml': 'docs/extensions/index.html'
168+ };
169+
170+ // Check if the file is in the special mapping
171+ if (specialFileMapping[file]) {
172+ fileUrlPath = specialFileMapping[file];
173+ } else if (file.endsWith('.qmd') || file.endsWith('.md')) {
174+ // Convert path to URL (removing file extension and adding appropriate path)
175+ fileUrlPath = file.replace(/\.(qmd|md)$/, '.html');
176+ }
177+
178+ if (fileUrlPath) {
179+ const fileUrl = `${deployUrl}/${fileUrlPath}`;
180+ commentBody += `- [${file}](${fileUrl})\n`;
181+ }
182+ });
183+ }
184+
185+ github.rest.issues.createComment({
186+ issue_number: prNumber,
187+ owner: context.repo.owner,
188+ repo: context.repo.repo,
189+ body: commentBody
190+ });
0 commit comments