Skip to content

Commit

Permalink
correct errors
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 8, 2025
1 parent 5a51a18 commit fd05ff7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .github/get_jars_sizes.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
11 changes: 7 additions & 4 deletions .github/workflows/jar_sizes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand Down

0 comments on commit fd05ff7

Please sign in to comment.