[Discounts] REST API #828
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: 'Preview comment' | |
on: | |
pull_request: ~ | |
workflow_call: | |
inputs: | |
project: | |
description: 'The project to build (dev doc, user doc)' | |
default: '' | |
required: false | |
type: string | |
jobs: | |
post-preview-links: | |
name: 'Post preview links for changed files' | |
runs-on: ubuntu-latest | |
permissions: | |
# Needed to manage the comment | |
pull-requests: write | |
# Needed to checkout private repositories | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Create comment for changed files | |
run: | | |
file_limit=100 | |
build_url="https://ez-systems-developer-documentation--${{ github.event.pull_request.number }}.com.readthedocs.build/${{inputs.project}}en/${{ github.event.pull_request.number }}/" | |
md_change_list=$(git diff --name-only HEAD "origin/$GITHUB_BASE_REF" -- docs/ | grep -E "^docs\/.*\.md$" | sed -E "s|^docs/(.*)\.md$|- [docs/\1.md](${build_url}\1/)|") | |
par_change_list=''; | |
for par_file in $(git diff --diff-filter=A --name-only "origin/$GITHUB_BASE_REF" HEAD -- docs/api/php_api/php_api_reference/ | grep -E '^docs\/.*\.html$'); do | |
fqcn=$(grep -o 'data-copy-value=".*">Copy FQCN' $par_file | sed 's|E|§E§|' | sed -E 's|data-copy-value="(.*)">.*|\1|' | sed 's|\\|\\\\|g') | |
link=$(echo $par_file | sed -E "s|^docs/(.*\.html)$|- [\`${fqcn}\`](${build_url}\1)|") | |
par_change_list=$(echo -e "$par_change_list\n$link") | |
done | |
par_change_list=$(echo "$par_change_list" | sed '1d' | sed 's|§E§|\\E|g') | |
change_count=$(( $(echo "$md_change_list" | wc -l) + $(echo "$par_change_list" | wc -l) )) | |
if [[ -z "$md_change_list$par_change_list" ]] ; then | |
comment="Preview of modified files: no change to preview." | |
elif [[ $change_count -gt $file_limit ]] ; then | |
comment="Preview of modified files: Too many files modified in a single PR, preview link list is skipped. ($change_count files >h; $file_limit)" | |
else | |
comment="# Preview of modified files" | |
if [[ -n "$md_change_list" ]]; then | |
comment="$comment\n\nPreview of modified Markdown:\n\n$md_change_list" | |
fi | |
if [[ -n "$par_change_list" ]]; then | |
comment="$comment\n\nPreview of addition to PHP API Reference:\n\n$par_change_list" | |
fi | |
fi | |
echo -e "$comment" > comment.md | |
- name: Find comment | |
id: find-comment | |
uses: peter-evans/find-comment@v3 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: 'Preview of modified files' | |
- name: Create or update comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: comment.md | |
edit-mode: replace |