Skip to content

Preview README changes for 11/merge by @CRThaze #20

Preview README changes for 11/merge by @CRThaze

Preview README changes for 11/merge by @CRThaze #20

name: Preview README changes
run-name: Preview README changes for ${{ github.ref_name }} by @${{ github.actor }}
on:
pull_request:
paths:
- charts/s3proxy/Chart.yaml
- charts/s3proxy/values.yaml
- README.md.gotmpl
- README.md
jobs:
preview-readme:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Save HEAD SHA before helm-docs
id: save-sha
run: |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Render helm docs inside the README.md
uses: losisin/helm-docs-github-action@v1
with:
git-push: false
output-file: ../../README.md
template-files: README.md.gotmpl
- name: Check for README changes
id: check-changes
run: |
if git diff --quiet ${{ steps.save-sha.outputs.sha }} -- README.md
then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Generate diff
id: diff
if: steps.check-changes.outputs.has_changes == 'true'
run: |
echo 'diff<<EOF' >> $GITHUB_OUTPUT
git diff ${{ steps.save-sha.outputs.sha }} -- README.md >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Find and hide outdated comments
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComments = comments.data.filter(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('<!-- helm-docs-preview -->')
);
for (const comment of botComments) {
await github.graphql(`
mutation {
minimizeComment(input: {
subjectId: "${comment.node_id}",
classifier: OUTDATED
}) {
clientMutationId
}
}
`);
}
- name: Post README changes as comment
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/github-script@v7
env:
DIFF_CONTENT: ${{ steps.diff.outputs.diff }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get the diff from the environment variable to avoid JavaScript syntax issues
const diff = process.env.DIFF_CONTENT;
// Use 4 backticks for the outer fence to safely contain any triple backticks in the diff
const body = `<!-- helm-docs-preview -->
## 📝 README.md Preview
The following changes to \`README.md\` will be applied when this PR is merged:
<details>
<summary>Click to expand diff</summary>
\`\`\`\`diff
${diff}
\`\`\`\`
</details>
> **Note**: This is an automated preview generated by \`helm-docs\`. The changes will be automatically applied upon merge.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
- name: Hide outdated comments when no changes
if: steps.check-changes.outputs.has_changes == 'false'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComments = comments.data.filter(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('<!-- helm-docs-preview -->')
);
for (const comment of botComments) {
await github.graphql(`
mutation {
minimizeComment(input: {
subjectId: "${comment.node_id}",
classifier: OUTDATED
}) {
clientMutationId
}
}
`);
}