Preview README changes for 2/merge by @CRThaze #2
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 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: Render helm docs inside the README.md | |
| uses: losisin/helm-docs-github-action@v1 | |
| with: | |
| git-push: false | |
| - name: Check for README changes | |
| id: check-changes | |
| run: | | |
| if git diff --quiet ${{ github.event.pull_request.head.ref }} -- 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 HEAD -- 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 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const diff = `${{ steps.diff.outputs.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 | |
| } | |
| } | |
| `); | |
| } |