Skip to content

Commit f1db09f

Browse files
authored
chore(ci): run matrix based on PR message (#92)
1 parent ead39b5 commit f1db09f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.github/workflows/lifecycle.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ jobs:
8282
8383
- id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py
8484
name: Construct matrices
85+
env:
86+
PR_COMMENT_BODY: ${{ github.event.comment.body }}
8587
run: |
8688
import os
8789
import json
90+
import re
8891
8992
build_matrix = {"include": []}
9093
run_matrix = {"version": []}
@@ -168,12 +171,21 @@ jobs:
168171
]
169172
170173
dirs_to_filter = []
174+
mc_versions = []
171175
172176
match os.getenv('GITHUB_EVENT_NAME'):
173177
case 'pull_request':
174178
if "${{ steps.filter.outcome }}" == "success":
175179
# Filter matrices based on the detected changes
176180
dirs_to_filter = json.loads('${{ steps.filter.outputs.changes }}')
181+
comment_body = os.getenv('PR_COMMENT_BODY')
182+
print("PR-comment:", comment_body)
183+
if comment_body:
184+
pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]) in ([1-9_]*[1-9])'
185+
match = re.search(pattern, comment_body)
186+
if match:
187+
mc_versions = [ match.group(1) ]
188+
dirs_to_filter = [ match.group(2) ]
177189
178190
case 'workflow_dispatch':
179191
input_dirs = '${{ github.event.inputs.dirs }}'
@@ -193,8 +205,8 @@ jobs:
193205
build_matrix['include'], run_matrix['version'] = build_data, run_data
194206
195207
if dirs_to_filter:
196-
build_matrix['include'].extend([item for item in build_data if item["dir"] in dirs_to_filter])
197-
mc_versions = [item.get("mc") for item in build_matrix["include"] if "mc" in item]
208+
build_matrix['include'].extend([item for item in build_data if item["dir"] in dirs_to_filter and (item["mc"] in mc_versions or not mc_versions)])
209+
mc_versions = mc_versions if mc_versions else [item.get("mc") for item in build_matrix["include"] if "mc" in item]
198210
run_matrix['version'].extend([item for item in run_data if item["mc"] in mc_versions])
199211
200212
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:

.github/workflows/new-mc-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }}
5555
branch: version-${{ env.LATEST_VERSION }}
5656
title: "feat: ${{ env.LATEST_VERSION }}"
57-
body: "This PR updates files for Minecraft version ${{ env.LATEST_VERSION }}."
57+
body: "Automatic commit: build and run ${{ env.LATEST_VERSION }} in ${{ env.LATEST_VERSION_DIR }}"

check-for-new-mc-versions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ def check_latest_mc_version():
128128
print("New Release found!")
129129
env_file = os.getenv('GITHUB_ENV')
130130
if env_file:
131-
with open(env_file, 'a') as f:
132-
f.write(f"LATEST_VERSION={latest_release}\n")
133131
if current_major != major or current_minor != minor:
134132
curr_dir = prepare_new_dir(curr_dir, latest_release, major, minor, patch, lex)
135-
136133
modify_file(__file__, lambda c: modify_script_file(c, curr_dir, major, minor, patch))
137134
modify_lifecycle(curr_dir, latest_release, lex)
135+
with open(env_file, 'a') as f:
136+
f.write(f"LATEST_VERSION={latest_release}\n")
137+
f.write(f"LATEST_VERSION_DIR={curr_dir}\n")
138138
else:
139139
raise FileNotFoundError("Failed to find GITHUB_ENV file!")
140140

0 commit comments

Comments
 (0)