|
| 1 | +name: Show generated code in PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - edited |
| 7 | + - opened |
| 8 | + - synchronize |
| 9 | + - converted_to_draft |
| 10 | + - ready_for_review |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 17 | + steps: |
| 18 | + - name: Cancel Previous Runs |
| 19 | + uses: styfle/cancel-workflow-action@0.9.1 |
| 20 | + with: |
| 21 | + access_token: ${{ github.token }} |
| 22 | + |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v3 |
| 25 | + |
| 26 | + - name: Set up JDK 11 |
| 27 | + uses: actions/setup-java@v4 |
| 28 | + with: |
| 29 | + distribution: 'temurin' |
| 30 | + java-version: '11' |
| 31 | + |
| 32 | + - name: Configure Git User |
| 33 | + run: | |
| 34 | + git config --global user.email "actions@github.com" |
| 35 | + git config --global user.name "GitHub Actions" |
| 36 | +
|
| 37 | + - name: Run Gradle task |
| 38 | + run: ./gradlew :core:processKDocsMain |
| 39 | + |
| 40 | + - name: Check for changes in generated sources |
| 41 | + id: git-diff |
| 42 | + run: echo "::set-output name=changed::$(if git diff --quiet './core/generated-sources'; then echo 'false'; else echo 'true'; fi)" |
| 43 | + |
| 44 | + - name: Commit and push if changes |
| 45 | + id: git-commit |
| 46 | + if: steps.git-diff.outputs.changed == 'true' |
| 47 | + run: | |
| 48 | + git checkout -b generated-sources/docs-update-${{ github.run_number }} |
| 49 | + git add './core/generated-sources' |
| 50 | + git commit -m "Update generated sources with recent changes" |
| 51 | + git push origin generated-sources/docs-update-${{ github.run_number }} |
| 52 | + echo "::set-output name=commit::$(git rev-parse HEAD)" |
| 53 | +
|
| 54 | + - name: Remove old comments |
| 55 | + uses: actions/github-script@v5 |
| 56 | + if: steps.git-diff.outputs.changed == 'true' |
| 57 | + with: |
| 58 | + # language=js |
| 59 | + script: | |
| 60 | + const issue_number = context.issue.number; |
| 61 | + const {owner, repo} = context.repo; |
| 62 | + |
| 63 | + const comments = await github.rest.issues.listComments({ |
| 64 | + issue_number, |
| 65 | + owner, |
| 66 | + repo, |
| 67 | + }); |
| 68 | + |
| 69 | + const botComments = comments.data.filter( |
| 70 | + (comment) => comment.user.login === 'github-actions[bot]' |
| 71 | + ); |
| 72 | + |
| 73 | + for (const comment of botComments) { |
| 74 | + await github.rest.issues.deleteComment({ |
| 75 | + comment_id: comment.id, |
| 76 | + owner, |
| 77 | + repo, |
| 78 | + }); |
| 79 | + } |
| 80 | +
|
| 81 | + - name: Add comment to PR |
| 82 | + uses: actions/github-script@v5 |
| 83 | + if: steps.git-diff.outputs.changed == 'true' |
| 84 | + with: |
| 85 | + # language=js |
| 86 | + script: | |
| 87 | + github.rest.issues.createComment({ |
| 88 | + issue_number: context.issue.number, |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + body: "Generated sources will be updated after merging this PR.\nPlease inspect the changes in [here](https://github.com/${{ github.repository }}/commit/${{ steps.git-commit.outputs.commit }}).", |
| 92 | + }); |
0 commit comments