Adds serverless changelog for May 5, 2025 #109
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment on removed .md files | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
detect-removed-markdown: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const prNumber = context.payload.pull_request.number; | |
// Get all files in the PR | |
const { data: files } = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: prNumber | |
}); | |
// Filter for removed .md files | |
const removedMd = files | |
.filter(f => f.status === 'removed' && f.filename.endsWith('.md')) | |
.map(f => `- \`${f.filename}\``); | |
// Filter for renamed .md files | |
const renamedMd = files | |
.filter(f => f.status === 'renamed' && f.filename.endsWith('.md')) | |
.map(f => `- \`${f.previous_filename}\` → \`${f.filename}\``); | |
// Create a comment if there are any removed or renamed files | |
if (removedMd.length > 0 || renamedMd.length > 0) { | |
// Build sections based on what changes were detected | |
const sections = []; | |
// Add removed files section if there are any | |
if (removedMd.length > 0) { | |
sections.push( | |
removedMd.length === 1 | |
? "The following Markdown file was **removed** in this PR:" | |
: `The following ${removedMd.length} Markdown files were **removed** in this PR:`, | |
...removedMd, | |
"" | |
); | |
} | |
// Add renamed files section if there are any | |
if (renamedMd.length > 0) { | |
sections.push( | |
renamedMd.length === 1 | |
? "The following Markdown file was **renamed** in this PR:" | |
: `The following ${renamedMd.length} Markdown files were **renamed** in this PR:`, | |
...renamedMd, | |
"" | |
); | |
} | |
// Prepare comment body | |
const body = [ | |
"## :warning: Markdown file changes detected", | |
"", | |
...sections, | |
"### Action Required", | |
"", | |
"We currently do not have an easy way to implement redirects for removed or renamed files. If possible, please:", | |
"", | |
"- Keep files whenever possible and hide them from the TOC by using [`hidden`](https://elastic.github.io/docs-builder/configure/content-set/navigation/#hidden-files)", | |
"- Add a notice at the top of the file indicating that the page has moved with a link to the new location", | |
"- Ensure you've updated `redirects.yml` accordingly if files must be removed or renamed", | |
"", | |
"Thank you!" | |
].join("\n"); | |
// Post the comment on the PR | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body | |
}); | |
console.log("Comment added about renamed or removed Markdown files"); | |
} else { | |
console.log("No Markdown files were removed in this PR"); | |
} |