Skip to content

Commit 32f8db7

Browse files
authored
action to comment PR-s touching scripts
auto-comment PR-s touching scripts with explained diff showing changes to KEYS_TO_IGNORE in translation_check.py
1 parent 40355f7 commit 32f8db7

2 files changed

Lines changed: 172 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Keys change check
2+
3+
on:
4+
pull_request_target:
5+
paths:
6+
- '.github/workflows/**.py'
7+
8+
9+
jobs:
10+
keys-change-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Get Pull Request
15+
uses: actions/checkout@v4
16+
with:
17+
path: pr
18+
ref: ${{github.event.pull_request.head.ref}}
19+
repository: ${{github.event.pull_request.head.repo.full_name}}
20+
21+
- name: Get OpenRCT2 develop (for en-GB.txt)
22+
uses: actions/checkout@v4
23+
with:
24+
repository: OpenRCT2/OpenRCT2
25+
ref: develop
26+
path: OpenRCT2
27+
28+
- name: Checkout translations before PR changes (for comparsion)
29+
uses: actions/checkout@v4
30+
with:
31+
path: master
32+
ref: ${{github.event.pull_request.head.ref}}
33+
repository: ${{github.event.pull_request.head.repo.full_name}}
34+
fetch-depth: 0
35+
36+
- name: Checkout commit before branch changes
37+
id: merge-base-commit
38+
run: |
39+
echo "head sha: ${{github.event.pull_request.head.sha}}"
40+
cd master
41+
git remote add upstream https://github.com/${{github.repository}}
42+
git fetch upstream
43+
merge_base=$(git merge-base refs/remotes/upstream/master HEAD)
44+
echo "merge base sha: ${merge_base}"
45+
git checkout $merge_base
46+
echo "merge_base=$merge_base" >> $GITHUB_OUTPUT
47+
cd ..
48+
49+
- name: Print debug stuff
50+
run: |
51+
echo ${{steps.merge-base-commit.outputs.merge_base}}
52+
echo ${{github.event.pull_request.head.sha}}
53+
echo ${{steps.merge-base-commit.outputs.merge_base == github.event.pull_request.head.sha}}
54+
55+
- name: Remove master
56+
if: ${{ steps.merge-base-commit.outputs.merge_base == github.event.pull_request.head.sha }}
57+
run: rm -rf master
58+
59+
- name: Checkout upstream master as master
60+
uses: actions/checkout@v4
61+
if: ${{ steps.merge-base-commit.outputs.merge_base == github.event.pull_request.head.sha }}
62+
with:
63+
ref: master
64+
path: master
65+
66+
- name: Set up Python 3.12
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: '3.12'
70+
71+
- name: Checkout upstream master (in order to use the newest version of the script)
72+
uses: actions/checkout@v4
73+
with:
74+
path: upstream_master
75+
ref: master
76+
77+
- name: Run checks
78+
run: python upstream_master/.github/workflows/keys_change_check.py
79+
80+
- id: get-comment-body
81+
run: |
82+
delimiter=$(openssl rand -hex 8)
83+
{
84+
echo "body<<$delimiter"
85+
cat result.md
86+
echo "$delimiter"
87+
} >> $GITHUB_OUTPUT
88+
89+
- name: Create PR comment
90+
uses: peter-evans/create-or-update-comment@v4
91+
with:
92+
issue-number: ${{github.event.pull_request.number}}
93+
body: ${{ steps.get-comment-body.outputs.body }}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import importlib.util
2+
3+
print("keys_change_check.py script text output")
4+
5+
"""
6+
Load modules to compare and en-GB.txt file
7+
"""
8+
module_path = 'pr/.github/workflows/translation_check.py'
9+
module_name = 'keys_pr'
10+
module_spec = importlib.util.spec_from_file_location(module_name, module_path)
11+
keys_pr_module = importlib.util.module_from_spec(module_spec)
12+
module_spec.loader.exec_module(keys_pr_module)
13+
14+
module_path = 'master/.github/workflows/translation_check.py'
15+
module_name = 'keys_master'
16+
module_spec = importlib.util.spec_from_file_location(module_name, module_path)
17+
keys_master_module = importlib.util.module_from_spec(module_spec)
18+
module_spec.loader.exec_module(keys_master_module)
19+
20+
keys_list_old = keys_master_module.KEYS_TO_IGNORE
21+
keys_list_new = keys_pr_module.KEYS_TO_IGNORE
22+
23+
OPENRCT2_EN_GB_FILE = "OpenRCT2/data/language/en-GB.txt"
24+
25+
result_file = open("result.md", "w")
26+
27+
result = "**Comparing changes**\n\n"
28+
result += "`KEYS_TO_IGNORE` in `translation_check.py` - list items expanded using `develop` version of `en-GB.txt`\n\n"
29+
30+
result += "```diff\n"
31+
"""
32+
use github codeblock diff style
33+
"""
34+
35+
counter_add = 0
36+
counter_rem = 0
37+
38+
for line in open(OPENRCT2_EN_GB_FILE):
39+
if line[0:8] in keys_list_old and line[0:8] in keys_list_new:
40+
result += (" "+line) # =
41+
if line[0:8] in keys_list_old and line[0:8] not in keys_list_new:
42+
result += ("- "+line)
43+
counter_rem += 1
44+
if line[0:8] not in keys_list_old and line[0:8] in keys_list_new:
45+
result += ("+ "+line)
46+
counter_add += 1
47+
if line[0:8] in keys_list_new:
48+
keys_list_new.remove(line[0:8])
49+
if line[0:8] in keys_list_old:
50+
keys_list_old.remove(line[0:8])
51+
52+
result += "\n"
53+
54+
result += " "+30*"-"+"\n"
55+
56+
result += "+ "+str(counter_add)+" keys\n"
57+
result += "- "+str(counter_rem)+" keys\n"
58+
59+
result += " "+30*"="+"\n"+"\n"
60+
61+
for compared_side_name, compared_side_keys in [('MASTER', keys_list_old), ('PR', keys_list_new)]:
62+
result += compared_side_name
63+
result += " KEYS NOT FOUND IN en-GB.txt"
64+
result += "\n"
65+
66+
for key in compared_side_keys:
67+
result += "! "+key
68+
result += "\n"
69+
70+
result += "\n "+30*"-"+"\n"
71+
result += "! "+str(len(compared_side_keys))+" keys\n"
72+
result += " "+30*"="+"\n\n"
73+
74+
75+
result += "```"
76+
result += "\n\n\n"
77+
78+
result_file.write(result)
79+
result_file.close()

0 commit comments

Comments
 (0)