diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..3cf65df --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,170 @@ +name: CI +# release: (release title) +# dispatch (all): Manual release for $target_release_tag +# dispatch (specified): Manual release for $target_release_tag (subproject: $target_subproject) +run-name: |- + ${{ github.event_name == 'workflow_dispatch' && format('Manual release for {0}{1}', inputs.target_release_tag, inputs.target_subproject && format(' (subproject: {0})', inputs.target_subproject) || '') || '' }} +on: + push: + paths: + - "*.gradle" + - "gradle.properties" + - "src/**" + - "versions/**" + - ".github/**" + release: + types: + - published + pull_request: + workflow_dispatch: + inputs: + target_subproject: + description: |- + The subproject name(s) of the specified Minecraft version to be released, seperated with ",". + By default all subprojects will be released. + type: string + required: false + default: '' + target_release_tag: + description: |- + The tag of the release you want to append the artifact to. + type: string + required: true +jobs: + show_action_parameters: + runs-on: ubuntu-latest + steps: + - name: Show action parameters + run: | + cat < $GITHUB_STEP_SUMMARY + ## Action Parameters + - target_subproject: \`${{ inputs.target_subproject }}\` + - target_release_tag: \`${{ inputs.target_release_tag }}\` + EOF + generate_matrix: + if: ${{ github.event_name != 'pull_request' }} + uses: ./.github/workflows/generate_matrix.yml + with: + target_subproject: ${{ inputs.target_subproject }} + validate_target_subproject: + runs-on: ubuntu-latest + steps: + - name: Checkout the sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Validate target subproject + if: ${{ github.event_name == 'workflow_dispatch' }} + # ubuntu-22.04 uses Python 3.10.6 + run: python3 .github/workflows/scripts/validate_subproject.py + env: + TARGET_SUBPROJECT: ${{ inputs.target_subproject }} + # Ensure the input release tag is valid. + validate_release: + runs-on: ubuntu-latest + steps: + - name: Get github release information + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: cardinalby/git-get-release-action@1.2.5 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag: ${{ inputs.target_release_tag }} + prepare_build_info: + if: ${{ !startsWith(github.event.ref, 'refs/tags/') }} + runs-on: ubuntu-latest + outputs: + build_publish: ${{ steps.build_info.outputs.build_publish }} + build_target_subprojects: ${{ steps.subprojects.outputs.subprojects }} + build_version_type: ${{ steps.build_info.outputs.build_version_type }} + publish_channel: ${{ steps.build_info.outputs.publish_channel }} + publish_target_release_tag: ${{ steps.build_info.outputs.publish_target_release_tag }} + steps: + - name: Checkout the sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Determining build info + id: build_info + run: | + if [ ${{ github.event_name }} == 'push' ] + then + build_publish=true + build_version_type=BETA + publish_channel=dev + elif [ ${{ github.event_name }} == 'release' ] + then + build_publish=true + build_version_type=RELEASE + publish_channel=stable + publish_target_release_tag=${{ github.event.ref }} + elif [ ${{ github.event_name }} == 'pull_request' ] + then + build_publish=false + build_version_type=PULL_REQUEST + elif [ ${{ github.event_name }} == 'workflow_dispatch' ] + then + build_publish=true + build_version_type=RELEASE + publish_channel=stable + publish_target_release_tag=${{ inputs.target_release_tag }} + else + echo Unknown github event name $GITHUB_EVENT_NAME + exit 1 + fi + + echo "build_publish=$build_publish" >> $GITHUB_OUTPUT + echo "build_version_type=$build_version_type" >> $GITHUB_OUTPUT + echo "publish_channel=$publish_channel" >> $GITHUB_OUTPUT + echo "publish_target_release_tag=$publish_target_release_tag" >> $GITHUB_OUTPUT + + cat < $GITHUB_STEP_SUMMARY + ## Determining build info + - build_publish: \`$build_publish\` + - build_version_type: \`$build_version_type\` + - publish_channel: \`$publish_channel\` + - publish_target_release_tag: \`$publish_target_release_tag\` + EOF + - name: Determining subprojects + id: subprojects + run: python3 .github/workflows/scripts/determining_subproject.py + env: + TARGET_SUBPROJECT: ${{ github.event.inputs.target_subproject }} + prepare_publish_info: + if: ${{ needs.prepare_build_info.outputs.build_publish == 'true' }} + runs-on: ubuntu-latest + needs: + - prepare_build_info + outputs: + publish_channel: ${{ needs.prepare_build_info.outputs.publish_channel }} + publish_target_release_tag: ${{ needs.prepare_build_info.outputs.publish_target_release_tag }} + steps: + - name: Checkout the sources + uses: actions/checkout@v4 + build: + if: ${{ contains(github.event.head_commit.message, '[build skip]') == false }} + needs: + - prepare_build_info + - validate_target_subproject + - validate_release + uses: ./.github/workflows/build.yml + secrets: inherit + with: + build_publish: ${{ needs.prepare_build_info.outputs.build_publish }} + build_version_type: ${{ needs.prepare_build_info.outputs.build_version_type }} + target_subproject: ${{ needs.prepare_build_info.outputs.build_target_subprojects }} + publish: + if: ${{ github.event_name != 'pull_request' }} + strategy: + matrix: ${{ fromJson(needs.generate_matrix.outputs.matrix) }} + needs: + - build + - generate_matrix + - prepare_publish_info + uses: ./.github/workflows/publish.yml + secrets: inherit + with: + publish_channel: ${{ needs.prepare_publish_info.outputs.publish_channel }} + publish_mc_ver: ${{ matrix.mc_ver }} + publish_platform: ${{ matrix.platform }} + publish_target_release_tag: ${{ needs.prepare_publish_info.outputs.publish_target_release_tag }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d2a33c..9d4528e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,53 +1,74 @@ -name: build -on: [ pull_request, push ] - +name: step.build +on: + workflow_call: + inputs: + build_publish: + type: string + required: true + build_version_type: + type: string + required: true + target_subproject: + description: see CI.yml, leave it empty to build all + type: string + required: false + default: '' jobs: build: - strategy: - matrix: - # Use these Java versions - java: [ 17 ] - # and run on both Linux and Windows - os: [ ubuntu-20.04 ] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - - name: checkout repository - uses: actions/checkout@v3 + - name: Checkout the sources + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v3 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: ${{ matrix.java }} - - name: Cache Gradle packages - uses: actions/cache@v3 + distribution: 'temurin' + java-version: 21 + - name: Cache gradle files + if: ${{ inputs.build_version_type != 'PULL_REQUEST' }} + uses: actions/cache@v4 with: path: | ~/.gradle/caches - ./.gradle/loom-caches ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - - name: make gradle wrapper executable - run: chmod +x ./gradlew - - name: preprocessResources - env: - BUILD_TYPE: "BETA" - run: ./gradlew preprocessResources - - name: build - env: - BUILD_TYPE: "BETA" - run: ./gradlew build - - name: Find correct JAR - id: findjar - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} + ./.gradle/loom-cache + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener', 'settings.json') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Build with gradle run: | - output="$(find fabricWrapper/build/libs/ ! -name "*-dev.jar" ! -name "*-sources.jar" -type f -printf "%f\n")" - echo "jarname=$output" >> $GITHUB_OUTPUT - - name: capture build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} - uses: actions/upload-artifact@v3 + chmod +x gradlew + if [ -z "${{ inputs.target_subproject }}" ]; then + echo "Building all subprojects" + ./gradlew build + else + args=$(echo "${{ inputs.target_subproject }}" | tr ',' '\n' | sed 's/$/:build/' | paste -sd ' ') + echo "Building with arguments=$args" + ./gradlew $args + fi + env: + BUILD_TYPE: ${{ inputs.build_version_type }} + - name: Upload artifacts + uses: actions/upload-artifact@v4 with: - name: ${{ steps.findjar.outputs.jarname }} - path: | - fabricWrapper/build/libs/*.jar \ No newline at end of file + name: build-artifacts + path: versions/*/build/libs/ + summary: + runs-on: ubuntu-22.04 + needs: + - build + steps: + - name: Checkout the sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: build-artifacts + - name: Make build summary + # ubuntu-22.04 uses Python 3.10.6 + run: python3 .github/workflows/scripts/summary.py diff --git a/.github/workflows/generate_matrix.yml b/.github/workflows/generate_matrix.yml new file mode 100644 index 0000000..0993a55 --- /dev/null +++ b/.github/workflows/generate_matrix.yml @@ -0,0 +1,29 @@ +name: step.generate_matrix +on: + workflow_call: + inputs: + target_subproject: + description: see CI.yml, for generating matrix entries + type: string + required: false + default: '' + outputs: + matrix: + description: The generated run matrix + value: ${{ jobs.generate_matrix.outputs.matrix }} +jobs: + generate_matrix: + runs-on: ubuntu-22.04 + steps: + - name: Checkout the sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Generate matrix + id: generate_matrix + # ubuntu-22.04 uses Python 3.10.6 + run: python3 .github/workflows/scripts/matrix.py + env: + TARGET_SUBPROJECT: ${{ inputs.target_subproject }} + outputs: + matrix: ${{ steps.generate_matrix.outputs.matrix }} \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3d245b7..4ed59cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,76 +1,120 @@ -name: Publish Release +name: step.publish on: - release: - types: - - published + workflow_call: + inputs: + publish_channel: + type: string + required: true + publish_mc_ver: + type: string + required: true + publish_platform: + type: string + required: true + publish_target_release_tag: + description: |- + The tag of the release you want to append the artifact to. + type: string + required: true jobs: - build: - strategy: - matrix: - java: [ 17 ] - os: [ ubuntu-20.04 ] - runs-on: ${{ matrix.os }} + publish: + runs-on: ubuntu-latest + # Allow the mod publish step to add assets to release + # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token + permissions: + contents: write steps: - - name: checkout repository - uses: actions/checkout@v3 + - name: Checkout the sources + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v3 + - name: Download build artifacts + uses: actions/download-artifact@v4 with: - distribution: 'adopt' - java-version: ${{ matrix.java }} - - name: Cache Gradle packages - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ./.gradle/loom-caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - - name: make gradle wrapper executable - run: chmod +x ./gradlew - - name: preprocessResources + name: build-artifacts + path: build-artifacts + - name: Get git info + id: get_git_info + run: | + short_sha=$(echo ${GITHUB_SHA} | cut -c1-7) + commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l) + echo "short_sha=$short_sha" >> $GITHUB_OUTPUT + echo "commit_count=$commit_count" >> $GITHUB_OUTPUT + - name: Get github release information + if: ${{ github.event_name == 'workflow_dispatch' }} + id: get_release + uses: cardinalby/git-get-release-action@1.2.5 env: - BUILD_TYPE: "RELEASE" - run: ./gradlew preprocessResources - - name: build + GITHUB_TOKEN: ${{ github.token }} + with: + tag: ${{ github.event.inputs.publish_target_release_tag }} + - name: Read Properties mod info + id: mod_info + uses: christian-draeger/read-properties@1.1.1 + with: + path: gradle.properties + properties: 'mod.name mod.version' + - name: Prepare file information + id: file_info + run: | + shopt -s extglob + FILE_PATHS=$(ls ${{ format('build-artifacts/{0}-{1}/build/libs/!(*-@(dev|sources|javadoc)).jar', inputs.publish_mc_ver, inputs.publish_platform) }}) + + if (( ${#FILE_PATHS[@]} != 1 )); then + echo "Error: Found ${#FILE_PATHS[@]} files, expected exactly 1" + exit 1 + else + FILE_PATH=${FILE_PATHS[0]} + fi + + FILE_NAME=$(basename $FILE_PATH) + FILE_HASH=$(sha256sum $FILE_PATH | awk '{ print $1 }') + echo "path=$FILE_PATH" >> $GITHUB_OUTPUT + echo "name=$FILE_NAME" >> $GITHUB_OUTPUT + echo "hash=$FILE_HASH" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + - name: Prepare changelog + if: ${{ inputs.publish_channel == 'stable' }} + uses: actions/github-script@v7 + id: changelog_release + with: + script: return process.env.CHANGELOG + result-encoding: string env: - BUILD_TYPE: "RELEASE" - run: ./gradlew build + CHANGELOG: |- + ${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }} + + ------- + + Build Information + + - File name: `${{ steps.file_info.outputs.name }}` + - SHA-256: `${{ steps.file_info.outputs.hash }}` + - Built from: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - name: Publish Minecraft Mods - uses: Kir-Antipov/mc-publish@v3.2 + if: ${{ inputs.publish_channel == 'stable' }} + uses: Kir-Antipov/mc-publish@v3.3 with: - modrinth-id: SFO4Ca80 - modrinth-token: ${{ secrets.MODRINTH }} - - curseforge-id: 525510 - curseforge-token: ${{ secrets.CF_API_TOKEN }} - +# modrinth-id: +# modrinth-token: ${{ secrets.MODRINTH_API_TOKEN }} +# curseforge-id: +# curseforge-token: ${{ secrets.CF_API_TOKEN }} + github-tag: ${{ inputs.publish_target_release_tag }} github-token: ${{ secrets.GITHUB_TOKEN }} - - files-primary: fabricWrapper/build/libs/!(*-@(dev|sources|javadoc)).jar - files-secondary: fabricWrapper/build/tmp/submods/META-INF/jars/!(*-@(dev|sources|javadoc)).jar - - name: '' + github-generate-changelog: true + files: ${{ steps.file_info.outputs.path }} + name: ${{ format('{0} {1}.{2} for Minecraft {3} ({4})', steps.mod_info.outputs.mod-name, steps.mod_info.outputs.mod-version, steps.get_git_info.outputs.commit_count, inputs.publish_mc_ver, inputs.publish_platform) }} + version: ${{ format('mc-{0}-{1}-v{2}.{3}', inputs.publish_mc_ver, inputs.publish_platform, steps.mod_info.outputs.mod-version, steps.get_git_info.outputs.commit_count) }} version-type: release - changelog: ${{ github.event.release.body }} - - loaders: fabric + github-changelog: ${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }} + modrinth-changelog: ${{ steps.changelog.outputs.result }} + curseforge-changelog: ${{ steps.changelog.outputs.result }} + loaders: | + ${{ inputs.publish_platform }} game-versions: | - 1.14.4 - 1.15.2 - 1.16.5 - 1.17.1 - 1.18.2 - 1.19.2 - 1.19.3 - 1.19.4 - 1.20.1 - 1.20.2 - 1.20.4 - - version-resolver: any - - retry-attempts: 3 - retry-delay: 10000 \ No newline at end of file + ${{ inputs.publish_mc_ver }} + game-version-filter: any + dependencies: | + malilib(optional) + retry-attempts: 2 + retry-delay: 10000 diff --git a/.github/workflows/scripts/common.py b/.github/workflows/scripts/common.py new file mode 100644 index 0000000..def4ced --- /dev/null +++ b/.github/workflows/scripts/common.py @@ -0,0 +1,86 @@ +""" +Common functions +""" +__author__ = 'Hendrix_Shen' + +import json +from typing import Dict, List, Set + +__PLATFORM_MAPPING: dict = { + 'fabric': 'Fabric', + 'forge': 'Forge', + 'neoforge': 'NeoForge', + 'quilt': 'Quilt' +} + + +def get_mc_vers(subproject_dict: Dict[str, List[str]]) -> List[str]: + mc_vers: Set[str] = set() + + for subproject in subproject_dict: + for mc_ver in subproject_dict[subproject]: + mc_vers.add(mc_ver) + + return sorted(list(mc_vers)) + + +def get_subproject_dict() -> Dict[str, List[str]]: + with open('settings.json') as f: + settings: dict = json.load(f) + + projects: Dict[str, List[str]] = {} + + for version in settings['versions']: + module: Module = Module.of(version) + + if module.platform() not in projects: + projects[module.platform()] = [] + + projects[module.platform()].append(module.mc_ver()) + + for platform in projects: + projects[platform] = sorted(list(set(projects[platform]))) + + return projects + + +def pretty_platform(platform: str) -> str: + return __PLATFORM_MAPPING.get(platform, '* Unknown *') + + +def read_prop(file_name: str, key: str) -> str: + with open(file_name) as prop: + return next(filter( + lambda x: x.split('=', 1)[0].strip() == key, + prop.readlines() + )).split('=', 1)[1].lstrip() + + +class Module: + __mc_ver: str + __platform: str + + def __init__(self, mc_ver: str, platform: str) -> None: + self.__mc_ver = mc_ver + self.__platform = platform + + @staticmethod + def of(module_name: str) -> 'Module': + s = module_name.split('-') + + if len(s) == 2: + return Module(s[0], s[1]) + else: + return Module('unknown', 'unknown') + + def platform(self) -> str: + return self.__platform + + def mc_ver(self) -> str: + return self.__mc_ver + + def pretty_platform(self) -> str: + return pretty_platform(self.__platform) + + def get_str(self) -> str: + return f'{self.__mc_ver}-{self.__platform}' diff --git a/.github/workflows/scripts/determining_subproject.py b/.github/workflows/scripts/determining_subproject.py new file mode 100644 index 0000000..94c390b --- /dev/null +++ b/.github/workflows/scripts/determining_subproject.py @@ -0,0 +1,31 @@ +__author__ = 'Hendrix_Shen' + +import os +from typing import List, Dict + +import common + + +def main(): + target_subproject_env = os.environ.get('TARGET_SUBPROJECT', '') + target_subprojects = list(filter(None, target_subproject_env.split(',') if target_subproject_env != '' else [])) + subproject_dict: Dict[str, List[str]] = common.get_subproject_dict() + gradle_subprojects: List[str] = [] + + for target_subproject in target_subprojects: + for platform in subproject_dict: + if target_subproject in subproject_dict[platform]: + gradle_subprojects.append('{}-{}'.format(target_subproject, platform)) + + result: str = ','.join(gradle_subprojects) + + with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f: + f.write('## Determining subprojects\n') + f.write('- subprojects={}\n'.format(result)) + + with open(os.environ['GITHUB_OUTPUT'], 'w') as f: + f.write('- subprojects={}\n'.format(result)) + + +if __name__ == '__main__': + main() diff --git a/.github/workflows/scripts/matrix.py b/.github/workflows/scripts/matrix.py new file mode 100644 index 0000000..cfc99b6 --- /dev/null +++ b/.github/workflows/scripts/matrix.py @@ -0,0 +1,49 @@ +""" +Modified from github.com/Fallen-Breath/fabric-mod-template +Originally authored by Fallen_Breath + +A script to scan through the versions directory and collect all folder names as the subproject list, +then output a json as the github action include matrix +""" +__author__ = 'Hendrix_Shen' + +import json +import os +from typing import Dict, List + +import common + + +def main(): + # target_subproject_env = os.environ.get('TARGET_SUBPROJECT', '') + target_subproject_env = '' + target_subprojects = list(filter(None, target_subproject_env.split(',') if target_subproject_env != '' else [])) + print('target_subprojects: {}'.format(target_subprojects)) + subproject_dict: Dict[str, List[str]] = common.get_subproject_dict() + matrix: Dict[str, List[Dict[str, str]]] = {'include': []} + + if len(target_subprojects) == 0: + for platform in subproject_dict: + for mc_ver in subproject_dict[platform]: + matrix['include'].append({ + 'platform': platform, + 'mc_ver': mc_ver + }) + else: + for platform in subproject_dict: + for mc_ver in subproject_dict[platform]: + if mc_ver in target_subprojects: + matrix['include'].append({ + 'platform': platform, + 'mc_ver': mc_ver + }) + + with open(os.environ['GITHUB_OUTPUT'], 'w') as f: + f.write('matrix={}\n'.format(json.dumps(matrix))) + + print('matrix:') + print(json.dumps(matrix, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/.github/workflows/scripts/summary.py b/.github/workflows/scripts/summary.py new file mode 100644 index 0000000..de64dc6 --- /dev/null +++ b/.github/workflows/scripts/summary.py @@ -0,0 +1,89 @@ +""" +Modified from github.com/Fallen-Breath/fabric-mod-template +Originally authored by Fallen_Breath + +A script to scan through all valid mod jars in build-artifacts.zip/$version/build/libs, +and generate an artifact summary table for that to GitHub action step summary +""" +__author__ = 'Hendrix_Shen' + +import functools +import glob +import hashlib +import json +import os +from typing import List, Dict + +import common + + +def get_sha256_hash(file_path: str) -> str: + sha256_hash = hashlib.sha256() + + with open(file_path, 'rb') as f: + for buf in iter(functools.partial(f.read, 4096), b''): + sha256_hash.update(buf) + + return sha256_hash.hexdigest() + + +def get_file_info(file_paths: List[str], subproject: str, warnings: List[str]) -> dict: + if len(file_paths) == 0: + file_name = '*not found*' + file_size = 0 + sha256 = '*N/A*' + else: + file_name = '`{}`'.format(os.path.basename(file_paths[0])) + file_size = '{} B'.format(os.path.getsize(file_paths[0])) + sha256 = '`{}`'.format(get_sha256_hash(file_paths[0])) + if len(file_paths) > 1: + warnings.append( + 'Found too many build files in subproject {}: {}'.format(subproject, ', '.join(file_paths))) + + return { + 'file_name': file_name, + 'file_size': file_size, + 'sha256': sha256 + } + + +def main(): + target_subproject_env = os.environ.get('TARGET_SUBPROJECT', '') + target_subprojects = list(filter(None, target_subproject_env.split(',') if target_subproject_env != '' else [])) + print('target_subprojects: {}'.format(target_subprojects)) + subproject_dict: Dict[str, List[str]] = common.get_subproject_dict() + + with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f: + warnings = [] + modules: List[common.Module] = [] + + for platform in subproject_dict: + for mc_ver in subproject_dict[platform]: + if len(target_subprojects) > 0 and mc_ver not in target_subprojects: + print('Skipping {}-{}'.format(mc_ver, platform)) + continue + + modules.append(common.Module(mc_ver, platform)) + + modules = sorted(list(set(modules)), key=lambda m: (m.mc_ver(), m.platform())) + f.write('## Build Artifacts Summary\n\n') + f.write('| Minecraft | Platform | File | Size | SHA-256 |\n') + f.write('| --- | --- |--- | --- | --- |\n') + + for module in modules: + file_paths = glob.glob('build-artifacts/{}/build/libs/*.jar'.format(module.get_str())) + file_paths = list( + filter(lambda fp: not fp.endswith('-sources.jar') and not fp.endswith('-javadoc.jar'), file_paths)) + file_info = get_file_info(file_paths, 'magiclib-wrapper', warnings) + f.write('| {} | {} | {} | {} | {} |\n'.format(module.mc_ver(), module.pretty_platform(), + file_info.get('file_name'), file_info.get('file_size'), + file_info.get('sha256'))) + + if len(warnings) > 0: + f.write('\n### Warnings\n\n') + for warning in warnings: + f.write('- {}\n'.format(warning)) + + +if __name__ == '__main__': + main() diff --git a/.github/workflows/scripts/validate_subproject.py b/.github/workflows/scripts/validate_subproject.py new file mode 100644 index 0000000..6920a3f --- /dev/null +++ b/.github/workflows/scripts/validate_subproject.py @@ -0,0 +1,26 @@ +""" +A script to valid TARGET_SUBPROJECT. +""" +__author__ = 'Hendrix_Shen' + +import os +import sys +from typing import List + +import common + + +def main(): + target_subproject_env = os.environ.get('TARGET_SUBPROJECT', '') + target_subprojects = list(filter(None, target_subproject_env.split(',') if target_subproject_env != '' else [])) + subproject_dict: dict = common.get_subproject_dict() + mc_ver: List[str] = common.get_mc_vers(subproject_dict) + + for subproject in target_subprojects: + if subproject not in mc_ver: + print('Could not found subproject {} in any platform!'.format(subproject)) + sys.exit(1) + + +if __name__ == '__main__': + main()