From 1fe2dcab23e523255172c9cfbefd4a5c78274e7b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 25 Aug 2024 22:30:38 +0200 Subject: [PATCH] Add commenting functionality --- .github/ghprcomment.yaml | 36 ++++++++++++++++++++++ .github/workflows/pr-comment.yml | 52 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 10 ++++++ 3 files changed, 98 insertions(+) create mode 100644 .github/ghprcomment.yaml create mode 100644 .github/workflows/pr-comment.yml diff --git a/.github/ghprcomment.yaml b/.github/ghprcomment.yaml new file mode 100644 index 00000000000..9f740d626f8 --- /dev/null +++ b/.github/ghprcomment.yaml @@ -0,0 +1,36 @@ +- jobName: Checkstyle + message: | + Your code currently does not meet [JabRef's code guidelines](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html). + We use [Checkstyle](https://checkstyle.sourceforge.io/) to identify issues. + The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR. + Please carefully follow [the setup guide for the codestyle](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html). + Afterwards, please [run checkstyle locally](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html#run-checkstyle) and fix the issues. + + + You can check review dog's comments at the tab "Files changed" of your pull request. +- jobName: OpenRewrite + message: | + Your code currently does not meet JabRef's code guidelines. + We use [OpenRewrite](https://docs.openrewrite.org/) to ensure "modern" Java coding practices. + The issues found can be **automatically fixed**. + Please execute the gradle task *`rewriteRun`*, check the results, commit, and push. + + You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite". +- jobName: Modernizer + message: | + Your code currently does not meet JabRef's code guidelines. + We use [Gradle Modernizer Plugin](https://github.com/andygoossens/gradle-modernizer-plugin#gradle-modernizer-plugin) to ensure "modern" Java coding practices. + Please fix the detected errors, commit, and push. + + You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "Modernizer". +- jobName: Markdown + message: | + You modified Markdown (`*.md`) files and did not meet JabRef's rules for consistently formatted Markdown files. + To ensure consistent styling, we have [markdown-lint](https://github.com/DavidAnson/markdownlint) in place. + [Markdown lint's rules](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#rules) help to keep our Markdown files consistent within this repository and consistent with the Markdown files outside here. + + You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "Markdown". +- jobName: CHANGELOG.md + message: | + While the PR was in progress, a new version of JabRef has been released. + You have to merge `upstream/main` and move your entry in `CHANGELOG.md` up to the section `## [Unreleased]`. diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml new file mode 100644 index 00000000000..565c2aae114 --- /dev/null +++ b/.github/workflows/pr-comment.yml @@ -0,0 +1,52 @@ +# Description: This workflow is triggered when the "Check" workflow completes. +# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code. +# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ +# Based on https://github.com/spring-projects/spring-security/pull/15477/files +--- +name: Comment on PR + +on: + workflow_run: + workflows: ["Tests"] + types: + - completed + +jobs: + comment: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + pull-requests: write + timeout-minutes: 10 + steps: + - name: Download PR number + uses: actions/download-artifact@v4 + with: + name: pr_number + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + - name: Read pr_number.txt + id: read-pr_number + run: | + PR_NUMBER=$(cat pr_number.txt) + echo "Read PR number $PR_NUMBER" + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT + - name: Checkout + if: ${{ steps.read-pr_number.outputs.pr_number != '' }} + uses: actions/checkout@v4 + with: + fetch-depth: '0' + show-progress: 'false' + token: ${{ secrets.GITHUB_TOKEN }} + - name: jbang + if: ${{ steps.read-pr_number.outputs.pr_number != '' }} + uses: jbangdev/jbang-action@v0.117.1 + with: + script: ghprcomment@koppor/ghprcomment + scriptargs: "-r koppor/workflow-comment-test -p ${{ steps.read-pr_number.outputs.pr_number }} -w ${{ github.event.workflow_run.id }}" + trust: https://github.com/koppor/ghprcomment/ + env: + GITHUB_OAUTH: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 73881d4b843..3edf09d599c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -363,3 +363,13 @@ jobs: with: script: | core.setFailed('Pull requests should come from a branch other than "main"\n\nšŸ‘‰ Please read https://devdocs.jabref.org/contributing again carefully. šŸ‘ˆ') + + upload-pr-number: + runs-on: ubuntu-latest + steps: + - name: Create pr_number.txt + run: echo "${{ github.event.number }}" > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt