From 6e904e4955f55236467578f09f79d27ba02699bd Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Tue, 22 Oct 2024 17:52:33 +0200 Subject: [PATCH 1/2] added "update status to PR" step for gh action bot --- .github/workflows/generated-sources.yml | 60 +++++++++---------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/.github/workflows/generated-sources.yml b/.github/workflows/generated-sources.yml index a6cae497d..d992ffc32 100644 --- a/.github/workflows/generated-sources.yml +++ b/.github/workflows/generated-sources.yml @@ -1,4 +1,8 @@ -name: Show generated code in PR +name: Preview Generated Code + +permissions: + contents: write + statuses: write on: pull_request: @@ -10,16 +14,15 @@ on: - ready_for_review jobs: - build: + build_preview_generated_code: + name: Build Preview of Generated Code + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ github.token }} - - name: Checkout repository uses: actions/checkout@v4 @@ -39,7 +42,7 @@ jobs: - name: Check for changes in generated sources id: git-diff - run: echo "::set-output name=changed::$(if git diff --quiet './core/generated-sources' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'; then echo 'false'; else echo 'true'; fi)" + run: echo "changed=$(if git diff --quiet './core/generated-sources' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'; then echo 'false'; else echo 'true'; fi)" >> $GITHUB_OUTPUT - name: Commit and push if changes id: git-commit @@ -49,44 +52,21 @@ jobs: git add './core/generated-sources' './docs/StardustDocs/snippets' './docs/StardustDocs/topics' git commit -m "Update generated sources with recent changes" git push origin generated-sources/docs-update-${{ github.run_number }} - echo "::set-output name=commit::$(git rev-parse HEAD)" - - - name: Remove old comments - uses: actions/github-script@v7 - if: steps.git-diff.outputs.changed == 'true' - with: - # language=js - script: | - const issue_number = context.issue.number; - const {owner, repo} = context.repo; - - const comments = await github.rest.issues.listComments({ - issue_number, - owner, - repo, - }); - - const botComments = comments.data.filter( - (comment) => comment.user.login === 'github-actions[bot]' - ); - - for (const comment of botComments) { - await github.rest.issues.deleteComment({ - comment_id: comment.id, - owner, - repo, - }); - } + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - name: Add comment to PR + - name: Update status to PR uses: actions/github-script@v7 if: steps.git-diff.outputs.changed == 'true' with: # language=js script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, + await github.rest.repos.createCommitStatus({ owner: context.repo.owner, repo: context.repo.repo, - 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 }}).", + sha: context.payload.pull_request.head.sha, + state: "success", + target_url: "https://github.com/${{ github.repository }}/commit/${{ steps.git-commit.outputs.commit }}", + context: "Generated sources will change, merging this PR", + description: "Check 'Details' to inspect changes ->" }); + From b47dd681066497e76436c08bf5fad1fc12416d95 Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Wed, 23 Oct 2024 17:35:11 +0200 Subject: [PATCH 2/2] small update in the docs regarding the changing behaviour of the gh actions bot --- CONTRIBUTING.md | 2 +- KDOC_PREPROCESSING.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 084566a29..f4cb9add0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,7 +60,7 @@ so do familiarize yourself with the following guidelines. 4. The contributor answers the comments or fixes the proposed PR. 5. The reviewer marks the PR with the word "LGTM." 6. The maintainer could suggest merging the `master` branch to the PR branch a few times due to changes in the `master` branch. -7. If the PR influences generated code/samples, a bot will inform about this in the PR comments. +7. If the PR influences generated code/samples, a bot will inform about this in the PR checks. 8. The maintainer runs TeamCity builds (unit tests and examples as integration tests). 9. TeamCity writes the result (passed or not passed) to the PR checks at the bottom of the proposed PR. 10. If it is possible, maintainers share the details of the failed build with the contributor. diff --git a/KDOC_PREPROCESSING.md b/KDOC_PREPROCESSING.md index 42e532af3..6d787ba45 100644 --- a/KDOC_PREPROCESSING.md +++ b/KDOC_PREPROCESSING.md @@ -58,7 +58,7 @@ This can be seen in action in the `core:processKDocsMain` and `core:changeJarTas To make sure the generated sources can be seen and reviewed on GitHub, since [PR #731](https://github.com/Kotlin/dataframe/pull/731), there's a [GitHub action](.github/workflows/generated-sources.yml) that runs the `core:processKDocsMain` task and -comments the results on the PR. After a PR is merged, [another action](.github/workflows/generated-sources-master.yml) +shows the results in the PR checks. After a PR is merged, [another action](.github/workflows/generated-sources-master.yml) runs on the master branch and commits the generated sources automatically. This way, the generated sources are always up to date with the latest changes in the code. This means you don't have to run and commit the generated sources yourself, though it's