diff --git a/.github/release.sh b/.github/release.sh index c1af584..9070a06 100755 --- a/.github/release.sh +++ b/.github/release.sh @@ -1,36 +1,40 @@ -#!/usr/bin/env bash -# Copyright (c) 2021-2022 José Manuel Barroso Galindo - -set -euo pipefail - -git add dont_download.sh -git commit -m "BOT: New dont_download.sh" > /dev/null 2>&1 || true -git fetch origin main - -set +e -CHANGES="$(git diff main:dont_download.sh origin/main:dont_download.sh | sed '/^[+-]export COMMIT/d' | sed '/^+++/d' | sed '/^---/d' | grep '^[+-]' | wc -l)" -set -e - -if [ ${CHANGES} -ge 1 ] ; then - echo "There are changes to push." - echo - git push origin main - - if ! gh release list | grep -q "latest" ; then - gh release create "latest" || true - sleep 15s - fi - - md5sum "dont_download.zip" > "dont_download.zip.md5" - - gh release upload "latest" "dont_download.zip" --clobber - gh release upload "latest" "dont_download.zip.md5" --clobber - gh release upload "latest" "src/downloader.zip" --clobber - - echo - echo "New dont_download.sh can be used." - echo "::set-output name=NEW_RELEASE::yes" -else - echo "Nothing to be updated." - echo "::set-output name=NEW_RELEASE::no" -fi +#!/usr/bin/env python3 +# Copyright (c) 2021-2024 José Manuel Barroso Galindo + +import subprocess +import os + +subprocess.run(['git', 'add', 'dont_download.sh'], check=True) +subprocess.run(['git', 'commit', '-m', 'BOT: New dont_download.sh'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + +subprocess.run(['git', 'fetch', 'origin', 'main'], check=True) + +diff_cmd = "git diff main:dont_download.sh origin/main:dont_download.sh" +filter_cmd = "grep '^[+-]' | grep -v 'export COMMIT' | grep -v '^\+\+\+' | grep -v '^---'" +changes = subprocess.getoutput(f"{diff_cmd} | {filter_cmd} | wc -l") + +if int(changes) >= 1: + print("There are changes to push:\n") + print(changes) + print() + subprocess.run(['git', 'push', 'origin', 'main'], check=True) + + has_latest = subprocess.run(['gh', 'release', 'list'], capture_output=True, text=True) + if "latest" not in has_latest.stdout: + subprocess.run(['gh', 'release', 'create', 'latest'], stderr=subprocess.DEVNULL) + + time.sleep(15) + + subprocess.run(['md5sum', 'dont_download.zip', '>', 'dont_download.zip.md5'], shell=True) + + subprocess.run(['gh', 'release', 'upload', 'latest', 'dont_download.zip', '--clobber'], check=True) + subprocess.run(['gh', 'release', 'upload', 'latest', 'dont_download.zip.md5', '--clobber'], check=True) + subprocess.run(['gh', 'release', 'upload', 'latest', 'src/downloader.zip', '--clobber'], check=True) + + print("\nNew dont_download.sh can be used.") + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + f.write("NEW_RELEASE=yes\n") +else: + print("Nothing to be updated.") + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + f.write("NEW_RELEASE=no\n")