Merge branch 'quicker-asan-lsan'
[git.git] / .github / workflows / l10n.yml
blob6c3849658aa061b89ced8e0464b3b580519c3a34
1 name: git-l10n
3 on: [push, pull_request_target]
5 # Avoid unnecessary builds. Unlike the main CI jobs, these are not
6 # ci-configurable (but could be).
7 concurrency:
8   group: ${{ github.workflow }}-${{ github.ref }}
9   cancel-in-progress: true
11 jobs:
12   git-po-helper:
13     if: >-
14       endsWith(github.repository, '/git-po') ||
15       contains(github.head_ref, 'l10n') ||
16       contains(github.ref, 'l10n')
17     runs-on: ubuntu-latest
18     permissions:
19       pull-requests: write
20     steps:
21       - name: Setup base and head objects
22         id: setup-tips
23         run: |
24           if test "${{ github.event_name }}" = "pull_request_target"
25           then
26             base=${{ github.event.pull_request.base.sha }}
27             head=${{ github.event.pull_request.head.sha }}
28           else
29             base=${{ github.event.before }}
30             head=${{ github.event.after }}
31           fi
32           echo base=$base >>$GITHUB_OUTPUT
33           echo head=$head >>$GITHUB_OUTPUT
34       - name: Run partial clone
35         run: |
36           git -c init.defaultBranch=master init --bare .
37           git remote add \
38             --mirror=fetch \
39             origin \
40             https://github.com/${{ github.repository }}
41           # Fetch tips that may be unreachable from github.ref:
42           # - For a forced push, "$base" may be unreachable.
43           # - For a "pull_request_target" event, "$head" may be unreachable.
44           args=
45           for commit in \
46             ${{ steps.setup-tips.outputs.base }} \
47             ${{ steps.setup-tips.outputs.head }}
48           do
49             case $commit in
50             *[^0]*)
51               args="$args $commit"
52               ;;
53             *)
54               # Should not fetch ZERO-OID.
55               ;;
56             esac
57           done
58           git -c protocol.version=2 fetch \
59             --progress \
60             --no-tags \
61             --no-write-fetch-head \
62             --filter=blob:none \
63             origin \
64             ${{ github.ref }} \
65             $args
66       - uses: actions/setup-go@v2
67         with:
68           go-version: '>=1.16'
69       - name: Install git-po-helper
70         run: go install github.com/git-l10n/git-po-helper@main
71       - name: Install other dependencies
72         run: |
73           sudo apt-get update -q &&
74           sudo apt-get install -q -y gettext
75       - name: Run git-po-helper
76         id: check-commits
77         run: |
78           exit_code=0
79           git-po-helper check-commits \
80             --github-action-event="${{ github.event_name }}" -- \
81             ${{ steps.setup-tips.outputs.base }}..${{ steps.setup-tips.outputs.head }} \
82             >git-po-helper.out 2>&1 || exit_code=$?
83           if test $exit_code -ne 0 || grep -q WARNING git-po-helper.out
84           then
85             # Remove ANSI colors which are proper for console logs but not
86             # proper for PR comment.
87             echo "COMMENT_BODY<<EOF" >>$GITHUB_ENV
88             perl -pe 's/\e\[[0-9;]*m//g; s/\bEOF$//g' git-po-helper.out >>$GITHUB_ENV
89             echo "EOF" >>$GITHUB_ENV
90           fi
91           cat git-po-helper.out
92           exit $exit_code
93       - name: Create comment in pull request for report
94         uses: mshick/add-pr-comment@v1
95         if: >-
96           always() &&
97           github.event_name == 'pull_request_target' &&
98           env.COMMENT_BODY != ''
99         with:
100           repo-token: ${{ secrets.GITHUB_TOKEN }}
101           repo-token-user-login: 'github-actions[bot]'
102           message: >
103             ${{ steps.check-commits.outcome == 'failure' && 'Errors and warnings' || 'Warnings' }}
104             found by [git-po-helper](https://github.com/git-l10n/git-po-helper#readme) in workflow
105             [#${{ github.run_number }}](${{ env.GITHUB_SERVER_URL }}/${{ github.repository }}/actions/runs/${{ github.run_id }}):
107             ```
109             ${{ env.COMMENT_BODY }}
111             ```