Skip to content

Commit 18b97ac

Browse files
authored
Merge pull request #12934 from ethereum/non-english-prs
feat: add non-English PR flagging workflow
2 parents 1c82df3 + 7e1ab4b commit 18b97ac

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
});

src/scripts/crowdin/translations/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const createLocaleTranslationPR = (
7373
.toLowerCase()
7474
const timestamp = new Date().toISOString().replace(/[^0-9]/g, "")
7575

76-
const branchName = `${month}-${locale}-${timestamp}`
76+
const branchName = `crowdin-${month}-${locale}-${timestamp}`
7777
const message = `chore: import translations for ${locale}`
7878
const startingBranch = execSync("git branch --show-current", {
7979
encoding: "utf-8",

0 commit comments

Comments
 (0)