From 4fdb707fd75a97ecf5aae002000c54f9b0ca90e4 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Wed, 22 Jul 2026 12:56:17 +0200 Subject: [PATCH 1/3] Add PR comment step to codex-preview workflow Posts per-page preview links (or a blanket fallback for snippet/CSV-only PRs) as a PR comment after a successful Codex deploy, matching the behaviour already present in docs-deploy.yml. - Per-page links: strips docs/ prefix and .md extension, links to https://codex.elastic.dev${PATH_PREFIX}/${path} - Snippet/CSV-only PRs: posts a blanket comment with the index URL - No docs changes: comment step is skipped (deploy.result != success) Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/codex-preview.yml | 115 ++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/.github/workflows/codex-preview.yml b/.github/workflows/codex-preview.yml index 8814310b..2757cd22 100644 --- a/.github/workflows/codex-preview.yml +++ b/.github/workflows/codex-preview.yml @@ -185,6 +185,121 @@ jobs: log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, }) + comment: + if: needs.deploy.result == 'success' + needs: + - build + - deploy + runs-on: ubuntu-latest + permissions: + contents: none + id-token: none + deployments: none + pull-requests: write + steps: + - name: Comment preview links on PR + continue-on-error: true + uses: actions/github-script@v9 + env: + PATH_PREFIX: ${{ needs.build.outputs.path_prefix }} + with: + # language=js + script: | + const title = '## 🔍 Preview links for changed Codex pages' + const { owner, repo } = context.repo; + const prNumber = context.payload.pull_request.number; + + const files = await github.paginate(github.rest.pulls.listFiles, { + owner, repo, pull_number: prNumber + }); + + const changedMdFiles = files + .map(f => f.filename) + .filter(i => i.endsWith('.md')) + .filter(i => !i.includes('/_snippets/')); + + if (changedMdFiles.length === 0) { + const hasSnippetOrCsv = files + .map(f => f.filename) + .some(f => f.includes('/_snippets/') || f.endsWith('.csv')); + if (!hasSnippetOrCsv) return; + + const previewUrl = `https://codex.elastic.dev${process.env.PATH_PREFIX}`; + const body = [ + title, + '', + 'This PR only changes snippets or data files. No direct page links are available.', + `[Browse the full preview](${previewUrl})`, + ].join('\n'); + + const { data: comments } = await github.rest.issues.listComments({ + owner, repo, issue_number: prNumber + }); + const existing = comments.find(c => + c.user.type === 'Bot' && + c.body.startsWith(title) + ); + if (existing) { + await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); + } else { + await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body }); + } + return; + } + + const escapeMarkdown = (s) => s.replace(/([[\]()\\])/g, '\\$1'); + const toMarkdownLink = (file) => { + const path = file + .replace(/^docs\//, '') + .replace(/\/index.md$/, '') + .replace(/\.md$/, ''); + return `[${escapeMarkdown(file)}](https://codex.elastic.dev${process.env.PATH_PREFIX}/${path})`; + } + + const links = changedMdFiles.map(toMarkdownLink) + + const body = [ + title, + ...links.slice(0, 10).map(i => `- ${i}`), + ] + + if (links.length > 10) { + body.push('
'); + body.push(' More links … '); + body.push(''); + for (const link of links.slice(10, 100)) { + body.push(`- ${link}`); + } + body.push(''); + body.push('
'); + } + + if (links.length > 100) { + body.push(''); + body.push(` In total, ${links.length} files changed. `); + } + + const { data: comments } = await github.rest.issues.listComments({ + owner, repo, issue_number: prNumber + }); + const existing = comments.find(c => + c.user.type === 'Bot' && + c.body.startsWith(title) + ); + if (existing) { + await github.rest.issues.updateComment({ + owner, repo, + comment_id: existing.id, + body: body.join('\n'), + }); + } else { + await github.rest.issues.createComment({ + owner, repo, + issue_number: prNumber, + body: body.join('\n'), + }); + } + update-link-index: needs: - build From 7ae5a4773609cd811f3081a7812b84072b8e8b1f Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri-Benedetti Date: Wed, 22 Jul 2026 13:03:11 +0200 Subject: [PATCH 2/3] Update .github/workflows/codex-preview.yml Co-authored-by: Jan Calanog --- .github/workflows/codex-preview.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/codex-preview.yml b/.github/workflows/codex-preview.yml index 2757cd22..2a6bbff0 100644 --- a/.github/workflows/codex-preview.yml +++ b/.github/workflows/codex-preview.yml @@ -192,9 +192,6 @@ jobs: - deploy runs-on: ubuntu-latest permissions: - contents: none - id-token: none - deployments: none pull-requests: write steps: - name: Comment preview links on PR From b25e7d6d7e5cbe7e1fa6a55383a850d1efeea590 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Wed, 22 Jul 2026 13:07:16 +0200 Subject: [PATCH 3/3] Use check job's changed-files output instead of API call Address review feedback: the check job already has the list of changed files via tj-actions/changed-files. Expose all_changed_files as a job output, pass it to comment via env var, and split on spaces instead of paginating the pulls.listFiles API. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/codex-preview.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codex-preview.yml b/.github/workflows/codex-preview.yml index 2a6bbff0..df65694a 100644 --- a/.github/workflows/codex-preview.yml +++ b/.github/workflows/codex-preview.yml @@ -41,6 +41,7 @@ jobs: runs-on: ubuntu-slim outputs: any_modified: ${{ steps.check-files.outputs.any_modified }} + all_changed_files: ${{ steps.check-files.outputs.all_changed_files }} steps: - name: Checkout # Checkout is needed to get changed files when the event is not a pull request @@ -188,6 +189,7 @@ jobs: comment: if: needs.deploy.result == 'success' needs: + - check - build - deploy runs-on: ubuntu-latest @@ -199,6 +201,7 @@ jobs: uses: actions/github-script@v9 env: PATH_PREFIX: ${{ needs.build.outputs.path_prefix }} + ALL_CHANGED_FILES: ${{ needs.check.outputs.all_changed_files }} with: # language=js script: | @@ -206,18 +209,14 @@ jobs: const { owner, repo } = context.repo; const prNumber = context.payload.pull_request.number; - const files = await github.paginate(github.rest.pulls.listFiles, { - owner, repo, pull_number: prNumber - }); + const files = (process.env.ALL_CHANGED_FILES || '').split(' ').filter(Boolean); const changedMdFiles = files - .map(f => f.filename) .filter(i => i.endsWith('.md')) .filter(i => !i.includes('/_snippets/')); if (changedMdFiles.length === 0) { const hasSnippetOrCsv = files - .map(f => f.filename) .some(f => f.includes('/_snippets/') || f.endsWith('.csv')); if (!hasSnippetOrCsv) return;