Skip to content

Commit 7a09587

Browse files
Copilotshai-almog
andauthored
fix material icons automation (#4761)
Agent-Logs-Url: https://github.com/codenameone/CodenameOne/sessions/09ed0e92-f319-4f2e-8fbc-ff44ed2c1a9e Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>
1 parent ad4164e commit 7a09587

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

.github/scripts/update_material_icons.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
)
2323
MATERIAL_CSS_URL = "https://fonts.googleapis.com/icon?family=Material+Icons"
2424

25-
CONSTANT_DOC = " /// Material design icon font character code see\\n /// https://www.material.io/resources/icons/ for full list\\n"
25+
CONSTANT_DOC = (
26+
" /// Material design icon font character code see\n"
27+
" /// https://www.material.io/resources/icons/ for full list\n"
28+
)
2629
CONSTANT_RE = re.compile(r"^\s*public static final char MATERIAL_")
2730
SENTINEL = " private static Font materialDesignFont;"
2831

@@ -67,6 +70,10 @@ def generate_constants_block(entries: list[tuple[str, str]]) -> str:
6770
return "\n".join(lines) + "\n"
6871

6972

73+
def is_material_constant_doc_line(line: str) -> bool:
74+
return line.lstrip().startswith("///")
75+
76+
7077
def update_fontimage(constants_block: str, check_only: bool) -> bool:
7178
source = FONT_IMAGE_PATH.read_text(encoding="utf-8")
7279
lines = source.splitlines(keepends=True)
@@ -76,6 +83,8 @@ def update_fontimage(constants_block: str, check_only: bool) -> bool:
7683
for i, line in enumerate(lines):
7784
if start_idx is None and CONSTANT_RE.match(line):
7885
start_idx = i
86+
while start_idx > 0 and is_material_constant_doc_line(lines[start_idx - 1]):
87+
start_idx -= 1
7988
if line.strip("\n") == SENTINEL:
8089
end_idx = i
8190
break

.github/workflows/material-icons-update.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Material Icons Update
22

33
on:
44
schedule:
5+
# Weekly on Mondays at 06:00 UTC.
56
- cron: '0 6 * * 1'
67
workflow_dispatch:
78
pull_request:
@@ -10,6 +11,7 @@ on:
1011
- '.github/scripts/update_material_icons.py'
1112

1213
permissions:
14+
actions: write
1315
contents: write
1416
pull-requests: write
1517

@@ -32,6 +34,7 @@ jobs:
3234

3335
- name: Create pull request
3436
if: github.event_name != 'pull_request'
37+
id: create-pull-request
3538
uses: peter-evans/create-pull-request@v7
3639
with:
3740
commit-message: "Update Material Icons font and FontImage constants"
@@ -49,6 +52,18 @@ jobs:
4952
dependencies
5053
automation
5154
55+
- name: Trigger PR CI for generated branch
56+
if: github.event_name != 'pull_request' && steps.create-pull-request.outputs.pull-request-number != ''
57+
uses: actions/github-script@v7
58+
with:
59+
script: |
60+
await github.rest.actions.createWorkflowDispatch({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
workflow_id: 'pr.yml',
64+
ref: 'automation/material-icons-update'
65+
});
66+
5267
- name: Build update preview for PR validation
5368
if: github.event_name == 'pull_request'
5469
run: |

.github/workflows/pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: PR CI
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- master

0 commit comments

Comments
 (0)