Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/lifecycle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ jobs:

- id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py
name: Construct matrices
env:
PR_COMMENT_BODY: ${{ github.event.comment.body }}
run: |
import os
import json
import re

build_matrix = {"include": []}
run_matrix = {"version": []}
Expand Down Expand Up @@ -168,12 +171,21 @@ jobs:
]

dirs_to_filter = []
mc_versions = []

match os.getenv('GITHUB_EVENT_NAME'):
case 'pull_request':
if "${{ steps.filter.outcome }}" == "success":
# Filter matrices based on the detected changes
dirs_to_filter = json.loads('${{ steps.filter.outputs.changes }}')
comment_body = os.getenv('PR_COMMENT_BODY')
print("PR-comment:", comment_body)
if comment_body:
pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]) in ([1-9_]*[1-9])'
match = re.search(pattern, comment_body)
if match:
mc_versions = [ match.group(1) ]
dirs_to_filter = [ match.group(2) ]

case 'workflow_dispatch':
input_dirs = '${{ github.event.inputs.dirs }}'
Expand All @@ -193,8 +205,8 @@ jobs:
build_matrix['include'], run_matrix['version'] = build_data, run_data

if dirs_to_filter:
build_matrix['include'].extend([item for item in build_data if item["dir"] in dirs_to_filter])
mc_versions = [item.get("mc") for item in build_matrix["include"] if "mc" in item]
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)])
mc_versions = mc_versions if mc_versions else [item.get("mc") for item in build_matrix["include"] if "mc" in item]
run_matrix['version'].extend([item for item in run_data if item["mc"] in mc_versions])

with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/new-mc-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
permissions:
contents: write
pull-requests: write
actions: write

steps:
- name: Checkout repository
Expand Down Expand Up @@ -44,12 +45,13 @@ jobs:
if: steps.git-check.outputs.changes == 'true' && env.LATEST_VERSION != ''
uses: peter-evans/create-pull-request@v7
with:
# TODO: check if this works from the cron job, but it does not work from workflow_dispatch
author: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
assignees: [ okafke ]
reviewers: [ okafke ]
assignees: okafke
#reviewers: okafke
commit-message: "feat: ${{ env.LATEST_VERSION }}"
delete-branch: true
token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }}
branch: version-${{ env.LATEST_VERSION }}
title: "feat: ${{ env.LATEST_VERSION }}"
body: "This PR updates files for Minecraft version ${{ env.LATEST_VERSION }}."
body: "Automatic commit: build and run ${{ env.LATEST_VERSION }} in ${{ env.LATEST_VERSION_DIR }}"
6 changes: 3 additions & 3 deletions check-for-new-mc-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def check_latest_mc_version():
print("New Release found!")
env_file = os.getenv('GITHUB_ENV')
if env_file:
with open(env_file, 'a') as f:
f.write(f"LATEST_VERSION={latest_release}\n")
if current_major != major or current_minor != minor:
curr_dir = prepare_new_dir(curr_dir, latest_release, major, minor, patch, lex)

modify_file(__file__, lambda c: modify_script_file(c, curr_dir, major, minor, patch))
modify_lifecycle(curr_dir, latest_release, lex)
with open(env_file, 'a') as f:
f.write(f"LATEST_VERSION={latest_release}\n")
f.write(f"LATEST_VERSION_DIR={curr_dir}\n")
else:
raise FileNotFoundError("Failed to find GITHUB_ENV file!")

Expand Down