git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] ci: new github-action for git-l10n code review

From
Jiang Xin <worldhello.net@gmail.com>
Date
Aug 22, 2021, 16:13 UTC
Message-ID
<20210822161325.22038-2-worldhello.net@gmail.com>
In-Reply-To
<20210822161325.22038-1-worldhello.net@gmail.com>
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Git l10n uses github pull request for code review. A helper program "git-po-helper" can be used to check typos in ".po" files, validate syntax, and check commit message. It would be convenient to integrate this helper program to CI and add comments in pull request.

The new github-action workflow is added in ".github/workflows/l10n.yml", which is disabled by default. To turn it on for the git-l10n related repositories, such as "git-l10n/git-po", we can add a new branch named "ci-config" and create a simple shell script at "ci/config/allow-l10n" in this branch.

The new l10n workflow listens to two types of github events: push and pull_request.

For a push event, it will scan commits one by one. If a commit does not look like a l10n commit (no file in "po/" has been changed), it will immediately fail without checking for further commits. While for a pull_request event, all new introduced commits will be scanned.

"git-po-helper" will generate two kinds of suggestions, errors and warnings. A l10n contributor should try to fix all the errors, and should pay attention to the warnings. All the errors and warnings will be reported in the last step of the l10n workflow as two message groups. For a pull_request event, will create additional comments in pull request to report the result.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
 .github/workflows/l10n.yml | 143 +++++++++++++++++++++++++++++++++++++
 1 file changed, 143 insertions(+)
 create mode 100644 .github/workflows/l10n.yml
diff --git a/.github/workflows/l10n.yml b/.github/workflows/l10n.yml
new file mode 100644
index 0000000000..60f162c121
--- /dev/null
+++ b/.github/workflows/l10n.yml
@@ -0,0 +1,143 @@
+name: git-l10n
+
+on: [push, pull_request]
+
+jobs:
+  ci-config:
+    runs-on: ubuntu-latest
+    outputs:
+      enabled: ${{ steps.check-l10n.outputs.enabled }}
+    steps:
+      - name: try to clone ci-config branch
+        run: |
+          git -c protocol.version=2 clone \
+            --no-tags \
+            --single-branch \
+            -b ci-config \
+            --depth 1 \
+            --no-checkout \
+            --filter=blob:none \
+            https://github.com/${{ github.repository }} \
+            config-repo &&
+          cd config-repo &&
+          git checkout HEAD -- ci/config || : ignore
+      - id: check-l10n
+        name: check whether CI is enabled for l10n
+        run: |
+          enabled=no
+          if test -x config-repo/ci/config/allow-l10n &&
+             config-repo/ci/config/allow-l10n '${{ github.ref }}'
+          then
+            enabled=yes
+          fi
+          echo "::set-output name=enabled::$enabled"
+
+  git-po-helper:
+    needs: ci-config
+    if: needs.ci-config.outputs.enabled == 'yes'
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+      with:
+        fetch-depth: '0'
+    - uses: actions/setup-go@v2
+      with:
+        go-version: ">=1.16"
+    - name: Install git-po-helper
+      run: |
+        go install github.com/git-l10n/git-po-helper@main
+    - name: Install other dependencies
+      run: |
+        sudo apt-get update -q &&
+        sudo apt-get install -q -y gettext
+    - id: check-commits
+      name: Run git-po-helper
+      run: |
+        if test "${{ github.event_name }}" = "pull_request"
+        then
+          commit_from=${{ github.event.pull_request.base.sha }}
+          commit_to=${{ github.event.pull_request.head.sha }}
+        else
+          commit_from=${{ github.event.before }}
+          commit_to=${{ github.event.after }}
+          if ! echo $commit_from | grep -q "^00*$"
+          then
+            if ! git rev-parse "$commit_from^{commit}"
+            then
+              git fetch origin $commit_from
+            fi
+          fi
+        fi
+        exit_code=0
+        git-po-helper check-commits --github-action -- \
+          $commit_from..$commit_to >git-po-helper.out 2>&1 ||
+        exit_code=$?
+        echo "::set-output name=exit_code::$exit_code"
+        has_error_msg=
+        has_warning_msg=
+        if test $exit_code -ne 0
+        then
+          has_error_msg=yes
+          if test "${{ github.event_name }}" = "pull_request"
+          then
+            echo "ERROR_MSG<<EOF" >>$GITHUB_ENV
+            grep -v -e "^level=warning" -e WARNING git-po-helper.out |
+              perl -pe 's/\e\[[0-9;]*m//g' >>$GITHUB_ENV
+            echo "EOF" >>$GITHUB_ENV
+          fi
+        fi
+        if grep -q -e "^level=warning" -e WARNING git-po-helper.out
+        then
+          has_warning_msg=yes
+          if test "${{ github.event_name }}" = "pull_request"
+          then
+            echo "WARNING_MSG<<EOF" >>$GITHUB_ENV
+            grep -v -e "^level=error" -e ERROR git-po-helper.out |
+              perl -pe 's/\e\[[0-9;]*m//g' >>$GITHUB_ENV
+            echo "EOF" >>$GITHUB_ENV
+          fi
+        fi
+        echo "::set-output name=has_error_msg::$has_error_msg"
+        echo "::set-output name=has_warning_msg::$has_warning_msg"
+    - name: Report errors in comment for pull request
+      uses: mshick/add-pr-comment@v1
+      if: steps.check-commits.outputs.has_error_msg == 'yes' && github.event_name == 'pull_request'
+      continue-on-error: true
+      with:
+        repo-token: ${{ secrets.GITHUB_TOKEN }}
+        repo-token-user-login: 'github-actions[bot]'
+        message: |
+          Errors found by git-po-helper in workflow ${{ github.workflow }}:
+          ```
+          ${{ env.ERROR_MSG }}
+          ```
+    - name: Report warnings in comment for pull request
+      uses: mshick/add-pr-comment@v1
+      if: steps.check-commits.outputs.has_warning_msg == 'yes' && github.event_name == 'pull_request'
+      continue-on-error: true
+      with:
+        repo-token: ${{ secrets.GITHUB_TOKEN }}
+        repo-token-user-login: 'github-actions[bot]'
+        message: |
+          Warnings found by git-po-helper in workflow ${{ github.workflow }}:
+          ```
+          ${{ env.WARNING_MSG }}
+          ```
+    - name: Report and quit
+      run: |
+        if test "${{ steps.check-commits.outputs.has_error_msg }}" = "yes"
+        then
+          echo "::group::Errors found by git-po-helper"
+          grep -v -e "^level=warning" -e WARNING git-po-helper.out
+          echo "::endgroup::"
+        fi
+        if test "${{ steps.check-commits.outputs.has_warning_msg }}" = "yes"
+        then
+          echo "::group::Warnings found by git-po-helper"
+          grep -v -e "^level=error" -e ERROR git-po-helper.out
+          echo "::endgroup::"
+        fi
+        if test ${{ steps.check-commits.outputs.exit_code }} -ne 0
+        then
+          exit ${{ steps.check-commits.outputs.exit_code }}
+        fi
-- 
2.33.0
Previous: Jiang XinNext: Bagas Sanjaya
Message 2 of 24 in “ci: new github-action for git-l10n code review”
  1. 0/1 ci: new github-action for git-l10n code reviewJiang Xin, Aug 22, 2021
  2. 1/1 ci: new github-action for git-l10n code reviewJiang Xin, Aug 22, 2021
  3. Bagas SanjayaAug 23, 2021
  4. Jiang XinAug 23, 2021
  5. Johannes SchindelinAug 23, 2021
  6. Junio C HamanoAug 23, 2021
  7. Johannes SchindelinAug 24, 2021
  8. Junio C HamanoAug 24, 2021
  9. Jean-Noël AVILAAug 24, 2021
  10. Jiang XinAug 31, 2021
  11. Jiang XinAug 24, 2021
  12. Junio C HamanoAug 24, 2021
  13. Jiang XinAug 24, 2021
  14. Johannes SchindelinAug 25, 2021
  15. Jiang XinAug 26, 2021
  16. Jeff KingAug 27, 2021
  17. Jiang XinAug 27, 2021
  18. ci: new github-action for git-l10n code reviewJiang Xin, Aug 27, 2021
  19. 1/1 ci: new github-action for git-l10n code reviewJiang Xin, Sep 2, 2021
  20. 0/1 ci: new github-action for git-l10n code reviewJiang Xin, Sep 2, 2021
  21. 0/1 ci: new github-action for git-l10n code reviewJiang Xin, Sep 9, 2021
  22. 1/1 ci: new github-action for git-l10n code reviewJiang Xin, Sep 9, 2021
  23. 1/1 ci: new github-action for git-l10n code reviewJiang Xin, Aug 23, 2021
  24. 0/1 ci: new github-action for git-l10n code reviewJiang Xin, Aug 23, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.