Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ on:
type: string
default: 'false'
required: false
disable-comments:
description: 'Disable comments'
type: boolean
default: false
required: false

permissions:
id-token: write
deployments: write
contents: read
pull-requests: read
pull-requests: write

jobs:
match:
Expand Down Expand Up @@ -231,6 +236,81 @@ jobs:
aws cloudfront create-invalidation \
--distribution-id EKT7LT5PM8RKS \
--paths "${PATH_PREFIX}" "${PATH_PREFIX}/*"

- name: Comment on PR
continue-on-error: true
if: inputs.disable-comments != 'true' && env.MATCH == 'true' && steps.deployment.outputs.result && steps.check-files.outputs.all_changed_files
uses: actions/github-script@v7
env:
ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
with:
script: |
const title = '## 🔍 Preview links for changed docs'
const changedMdFiles = process.env.ALL_CHANGED_FILES
.split(/\s+/)
.filter(i => i.endsWith('.md'))
.filter(i => !i.includes('/_snippets/'));

if (changedMdFiles.length === 0) {
return;
}

const toLink = (file) => {
const path = file
.replace('docs/', '')
.replace('/index.md', '')
.replace('.md', '');
return `[${file}](https://docs-v3-preview.elastic.dev${process.env.PATH_PREFIX}/${path})`;
}

const links = changedMdFiles.map(toLink)

const body = [
title,
...links.slice(0, 10).map(i => `- ${i}`),
]

if (links.length > 10) {
body.push('<details>');
body.push('<summary>Full list of changed files</summary>');
body.push('');
for (const link of links.slice(10, 100)) {
body.push(`- ${link}`);
}
body.push('');
body.push('</details>');
}

if (links.length > 100) {
body.push('');
body.push(`<sub>In total, ${links.length} files changed.</sub>`);
}

const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.payload.pull_request.number;

// Post or update a single bot comment
const { data: comments } = await github.rest.issues.listComments({
owner, repo, issue_number
});
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,
body:body.join('\n'),
});
}

- name: Update Link Index
if: |
Expand Down
2 changes: 2 additions & 0 deletions docs/testing/req.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ applies_to:

# Requirements

test

Current version: **9.0.0**

| `applies_to` | result |
Expand Down
Loading