diff --git a/.github/get_jars_sizes.py b/.github/get_jars_sizes.py index 3d5a91cb..19c404bf 100644 --- a/.github/get_jars_sizes.py +++ b/.github/get_jars_sizes.py @@ -1,11 +1,20 @@ import json import requests +import argparse def get_file_size(url): response = requests.head(url, allow_redirects=True) if 'Content-Length' not in response.headers: raise Exception(f"Unable to find size of {url}") return int(response.headers['Content-Length']) + +# Parse command-line arguments +parser = argparse.ArgumentParser(description="Get file sizes and save them to a target file.") +parser.add_argument('target_file', type=str, help="Path to the target file where results will be saved.") +args = parser.parse_args() + +# Assign the target file from the command-line argument +target_file = args.target_file fname="src/main/resources/availableDLVersions.json" @@ -20,3 +29,7 @@ def get_file_size(url): if jar in jar_dict.keys: continue jar_dict[jar] = get_file_size(jar) + + +with open(target_file, "w") as ff: + json.dump(jar_dict) diff --git a/.github/workflows/jar_sizes.yml b/.github/workflows/jar_sizes.yml index 4bb7b1dd..f1e561f3 100644 --- a/.github/workflows/jar_sizes.yml +++ b/.github/workflows/jar_sizes.yml @@ -8,6 +8,10 @@ on: - .github/workflows/jar_sizes.yml - .github/get_jar_sizes.py workflow_dispatch: + + +env: + FPATH: "src/main/resources/jar_sizes.json" jobs: build-and-run: runs-on: ubuntu-latest @@ -16,14 +20,13 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - # Step 2: Set up Python environment - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.11' # Specify the Python version + python-version: '3.11' - name: Get file sizes and generate JSON - run: python .github/get_jar_sizes.py + run: python .github/get_jar_sizes.py ${{ env.FPATH }} - name: Commit and push changes run: | @@ -33,7 +36,7 @@ jobs: # Only commit/push if there are changes if [ -n "$(git status --porcelain)" ]; then - git add src/main/resources/sizes.json + git add ${{ env.FPATH }} git commit -m "Update file sizes" git push else