From 6aa9ab2491481320753ce9382a6f616fd08f3473 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Tue, 28 Nov 2023 09:18:39 +0200 Subject: [PATCH 1/2] feat: auto-summary for PRs --- .github/workflows/annotate_pr.yml | 58 +++++++++++++++++++++++++++++++ package.json | 1 + scripts/annotate-pr | 11 ++++++ 3 files changed, 70 insertions(+) create mode 100644 .github/workflows/annotate_pr.yml create mode 100755 scripts/annotate-pr diff --git a/.github/workflows/annotate_pr.yml b/.github/workflows/annotate_pr.yml new file mode 100644 index 0000000000..1171369c35 --- /dev/null +++ b/.github/workflows/annotate_pr.yml @@ -0,0 +1,58 @@ +name: Annotate PR + +on: + pull_request: + branches: [beta] + types: [opened, synchronize, reopened, edited] + paths: + - 'synsets/**/*.xml' + +jobs: + update-comment: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 # Fetches the last 2 commits + + - name: List all changed synsets + id: diff + run: | + CHANGED_FILES=$(git diff --name-only beta...${{ github.head_ref }} -- 'synsets/**/*.xml') + echo "Changed synsets:" + echo "$CHANGED_FILES" + echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV + if [ -z "$CHANGED_FILES" ]; then + echo "No changes in synsets folder. Skipping the rest of the job." + exit 78 + fi + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + + - name: Install dependencies + uses: bahmutov/npm-install@v1 + with: + useLockFile: false + + - name: Generate Comment File + run: scripts/annotate-pr ${{ env.CHANGED_FILES }} > comment-body.md + + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Summary of Changes + + - name: Create or Update Comment + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body-path: 'comment-body.md' + edit-mode: replace diff --git a/package.json b/package.json index 8f05108739..e2f87f799b 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "prepare": "husky install", + "annotate:pr": "scripts/annotate-pr", "format": "scripts/format", "lint": "scripts/lint-synset" }, diff --git a/scripts/annotate-pr b/scripts/annotate-pr new file mode 100755 index 0000000000..91eed0159e --- /dev/null +++ b/scripts/annotate-pr @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +if [ $# -eq 0 ]; then + changed_files=$(git diff --name-only beta synsets) +else + changed_files="$*" +fi + +isv suggestions annotate $changed_files From 9694f42320f2e94de88cf93f49416b08900bedec Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Tue, 28 Nov 2023 09:25:15 +0200 Subject: [PATCH 2/2] ci: skip lint for non-relevant commits --- .github/workflows/lint.yml | 2 ++ scripts/lint-synset | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 52b890bbb5..9136a22f22 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,3 +38,5 @@ jobs: - name: Run lint run: npm run lint -- ${{ steps.the_changes.outputs.all_changed_files }} + env: + CI: true diff --git a/scripts/lint-synset b/scripts/lint-synset index 44dd43d419..2d8a85f510 100755 --- a/scripts/lint-synset +++ b/scripts/lint-synset @@ -9,7 +9,9 @@ lint_synset() { cd "$(dirname "$0")/.." if [ $# -eq 0 ]; then - find synsets -type f -name "*.xml" -exec $0 {} \; + if [ -z "$CI" ]; then + find synsets -type f -name "*.xml" -exec $0 {} \; + fi else for file in "$@"; do lint_synset "$file"