|
| 1 | +name: Check for non-English updates outside of Crowdin |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "public/content/translations/**/*.md" |
| 7 | + - "src/intl/**/*.json" |
| 8 | + - "!src/intl/en/** |
| 9 | +
|
| 10 | +jobs: |
| 11 | + check_branch_name: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Exit early if branch name contains 'crowdin' |
| 15 | + run: | |
| 16 | + if [[ "${{ github.head_ref }}" == *crowdin* ]]; then |
| 17 | + echo "Branch name contains 'crowdin', stopping workflow" |
| 18 | + exit 1 |
| 19 | + fi |
| 20 | + |
| 21 | + check_changes: |
| 22 | + needs: check_branch_name |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + all_changes_include_href: ${{ steps.check.outputs.all_changes_include_href }} |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v2 |
| 29 | + - name: Check changes |
| 30 | + id: check |
| 31 | + run: | |
| 32 | + git fetch origin ${{ github.base_ref }} |
| 33 | + DIFF=$(git diff --no-ext-diff --unified=0 origin/${{ github.base_ref }}..${{ github.head_ref }} -- 'public/content/translations/**/*.md' 'src/intl/**/*.json' '!src/intl/en/**' | grep -E -v '^[-+]href=') |
| 34 | + if [[ -z "$DIFF" ]]; then |
| 35 | + echo "ALL_CHANGES_INCLUDE_HREF=true" >> $GITHUB_ENV |
| 36 | + else |
| 37 | + echo "ALL_CHANGES_INCLUDE_HREF=false" >> $GITHUB_ENV |
| 38 | + fi |
| 39 | + echo "::set-output name=all_changes_include_href::$ALL_CHANGES_INCLUDE_HREF" |
| 40 | +
|
| 41 | + add_label_and_comment: |
| 42 | + needs: check_changes |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: Add label and comment |
| 46 | + uses: actions/github-script@v5 |
| 47 | + with: |
| 48 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 49 | + script: | |
| 50 | + const prNumber = context.issue.number; |
| 51 | + const repo = context.repo; |
| 52 | + const prAuthor = context.payload.pull_request.user.login; |
| 53 | + const allChangesIncludeHref = '${{ needs.check_changes.outputs.all_changes_include_href }}' === 'true'; |
| 54 | + const status = allChangesIncludeHref ? 'question ❓' : 'blocked 🛑'; |
| 55 | + await github.rest.issues.addLabels({ |
| 56 | + ...repo, |
| 57 | + issue_number: prNumber, |
| 58 | + labels: [status, 'non-crowdin translation updates'] |
| 59 | + }); |
| 60 | + const commentWithoutHrefs = `This pull request contains changes to non-English content, which must also be handled through the Crowdin platform instead of only on GitHub.` |
| 61 | + const commentWithHrefs = `This pull request contains changes to non-English content files, which may also need to be handled through the Crowdin platform instead of only on GitHub. |
| 62 | + await github.rest.issues.createComment({ |
| 63 | + ...repo, |
| 64 | + issue_number: prNumber, |
| 65 | + body: ` |
| 66 | + Thank you for your contribution, @${prAuthor}! |
| 67 | + |
| 68 | + ${allChangesIncludeHref ? commentWithHrefs : commentWithoutHrefs} |
| 69 | + |
| 70 | + We value your suggestion, and for any non-English content updates we request that you check out [how to help us translate](https://ethereum.org/en/contributing/translation-program/#help-us-translate), and suggest these updates directly in [our Crowdin project](https://crowdin.com/project/ethereum-org) if possible, where they can be properly reviewed. |
| 71 | + |
| 72 | + Please post here or join [our Discord](https://ethereum.org/discord) if you have questions! |
| 73 | + ` |
| 74 | + }); |
0 commit comments