new file mode 100644
@@ -0,0 +1,156 @@
+name: git-l10n
+
+on: [push, pull_request_target]
+
+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'
+ - name: Fetch missing commits
+ id: fetch-commits
+ run: |
+ if test "${{ github.event_name }}" = "pull_request_target"
+ then
+ base=${{ github.event.pull_request.base.sha }}
+ head=${{ github.event.pull_request.head.sha }}
+ else
+ base=${{ github.event.before }}
+ head=${{ github.event.after }}
+ fi
+ for commit in $base $head
+ do
+ if echo $commit | grep -q "^00*$"
+ then
+ continue
+ fi
+ if ! git rev-parse --verify --end-of-options "$commit^{commit}" --
+ then
+ git fetch origin $commit
+ fi
+ done
+ echo "::set-output name=base::$base"
+ echo "::set-output name=head::$head"
+
+ - 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
+ - name: Run git-po-helper
+ id: check-commits
+ run: |
+ exit_code=0
+ git-po-helper check-commits \
+ --github-action \
+ --github-action-event "${{ github.event_name }}" -- \
+ ${{ steps.fetch-commits.outputs.base }}..${{ steps.fetch-commits.outputs.head }} \
+ >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_target"
+ 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_target"
+ 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_target'
+ 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_target'
+ 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: Final report
+ 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