diff --git a/.github/workflows/macos_install.yml b/.github/workflows/macos_install.yml new file mode 100644 index 0000000..3d38b64 --- /dev/null +++ b/.github/workflows/macos_install.yml @@ -0,0 +1,39 @@ +--- +name: Install Mac OS solc-select + +defaults: + run: + # To load bashrc + shell: bash -ieo pipefail {0} + +on: + pull_request: + branches: [master, dev] + schedule: + # run CI every day even if no PRs/merges occur + - cron: '0 12 * * *' + +jobs: + build: + name: Install test + runs-on: macos-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: 3.6 + + - name: Install all solc versions + run: | + python3 setup.py develop + solc-select install all + - name: Test minimum release + run: | + solc-select use 0.3.6 + - name: Test 0.8.0 + run: | + solc-select use 0.8.0 \ No newline at end of file diff --git a/.github/workflows/ubuntu_install.yml b/.github/workflows/ubuntu_install.yml new file mode 100644 index 0000000..e8e385a --- /dev/null +++ b/.github/workflows/ubuntu_install.yml @@ -0,0 +1,41 @@ +--- +name: Install Linux solc-select + +defaults: + run: + # To load bashrc + shell: bash -ieo pipefail {0} + +on: + pull_request: + branches: [master, dev] + schedule: + # run CI every day even if no PRs/merges occur + - cron: '0 12 * * *' + + +jobs: + build: + name: Install Ubuntu test + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: 3.6 + + - name: Install all solc versions + run: | + sudo python3 setup.py develop + solc-select install all + solc-select install all + - name: Test minimum release + run: | + solc-select use 0.4.0 + - name: Test 0.8.0 + run: | + solc-select use 0.8.0 \ No newline at end of file diff --git a/solc_select/__main__.py b/solc_select/__main__.py index 7e08f4a..3b75b27 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -45,7 +45,7 @@ def solc_select(): versions = args.get(INSTALL_VERSIONS) if versions == []: print("Available versions to install:") - for version in sorted(get_installable_versions()): + for version in get_installable_versions(): print(version) else: install_artifacts(args.get(INSTALL_VERSIONS)) diff --git a/solc_select/solc_select.py b/solc_select/solc_select.py index 025650c..6d04c41 100644 --- a/solc_select/solc_select.py +++ b/solc_select/solc_select.py @@ -4,6 +4,7 @@ import re import sys import urllib.request +from distutils.version import StrictVersion home_dir = os.path.expanduser("~") solc_select_dir = f"{home_dir}/.solc-select" @@ -35,10 +36,11 @@ def current_version(): def installed_versions(): - return [f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir))] + return [ + f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir)) if f.startswith("solc-") + ] -# TODO: accept versions in range def install_artifacts(versions): releases = get_available_versions() @@ -47,7 +49,7 @@ def install_artifacts(versions): if versions and version not in versions: continue - url = f"https://binaries.soliditylang.org/{soliditylang_platform()}/{artifact}" + url = get_url(version, artifact) artifact_file = f"{artifacts_dir}/solc-{version}" print(f"Installing '{version}'...") urllib.request.urlretrieve(url, artifact_file) @@ -58,6 +60,18 @@ def install_artifacts(versions): print(f"Version '{version}' installed.") +def is_older_linux(version): + return soliditylang_platform() == "linux-amd64" and StrictVersion(version) <= StrictVersion( + "0.4.10" + ) + + +def get_url(version, artifact): + if is_older_linux(version): + return f"https://raw.githubusercontent.com/crytic/solc/master/linux/amd64/{artifact}" + return f"https://binaries.soliditylang.org/{soliditylang_platform()}/{artifact}" + + def switch_global_version(version): if version in installed_versions(): with open(f"{solc_select_dir}/global-version", "w") as f: @@ -74,8 +88,8 @@ def switch_global_version(version): def valid_version(version): - # check that it matches .. match = re.search(r"^(\d+).(\d+).(\d+)$", version) + if match is None: raise argparse.ArgumentTypeError(f"Invalid version '{version}'.") return version @@ -88,17 +102,31 @@ def valid_install_arg(arg): def get_installable_versions(): - return set(get_available_versions()) - set(installed_versions()) + installable = list(set(get_available_versions()) - set(installed_versions())) + installable.sort(key=StrictVersion) + return installable def get_available_versions(): url = f"https://binaries.soliditylang.org/{soliditylang_platform()}/list.json" list_json = urllib.request.urlopen(url).read() - return json.loads(list_json)["releases"] + available_releases = json.loads(list_json)["releases"] + if soliditylang_platform() == "linux-amd64": + available_releases.update(get_additional_linux_versions()) + return available_releases + + +def get_additional_linux_versions(): + if soliditylang_platform() == "linux-amd64": + # This is just to be dynamic, but figure out a better way to do this. + url = "https://raw.githubusercontent.com/crytic/solc/list-json/linux/amd64/list.json" + github_json = urllib.request.urlopen(url).read() + return json.loads(github_json)["releases"] + return [] def soliditylang_platform(): - if sys.platform == "linux": + if sys.platform.startswith("linux"): platform = "linux-amd64" elif sys.platform == "darwin": platform = "macosx-amd64"