diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index db2a5e6..6bf2016 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -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": []} @@ -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 }}' @@ -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: diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml index 98bf68c..b4195a2 100644 --- a/.github/workflows/new-mc-version.yml +++ b/.github/workflows/new-mc-version.yml @@ -10,6 +10,7 @@ jobs: permissions: contents: write pull-requests: write + actions: write steps: - name: Checkout repository @@ -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 }}" diff --git a/check-for-new-mc-versions.py b/check-for-new-mc-versions.py index cf0d9cf..4ba7d4c 100644 --- a/check-for-new-mc-versions.py +++ b/check-for-new-mc-versions.py @@ -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!")