AleksaC / circleci-cli-py

pip installable CircleCI CLI binary
MIT License
4 stars 4 forks source link

circleci: Bad CPU type in executable #12

Open carlos-santos-anchor opened 5 days ago

carlos-santos-anchor commented 5 days ago

Hello 👋

I'm having a weird issue using pre-commit and this validator, and I' not sure if it's a mis-config or something else.

CircleCI Config Validation..................................................Failed
- hook id: circle-ci-validator
- exit code: 126

env: circleci: Bad CPU type in executable

Looking into the exit code: 126 it looks like the executable does not have execution permissions.

But I'm not sure what have changed.

Does anyone have an idea of what could be the root cause?

Thanks.


Here's my config of .pre-commit-config.yaml:

  - repo: https://github.com/AleksaC/circleci-cli-py
    rev: b6ca7f04421b627192e232b22ffc0f33e9571700  # frozen: v0.1.30549
    hooks:
      - id: circle-ci-validator

I'm using the latest released tag v0.1.30549

The same happens with the latest commit

AleksaC commented 5 days ago

Hi @carlos-santos-anchor, thanks for reporting the issue!

I'm guessing you're using apple silicon. You need Rosetta to make it work since it's using amd64 binaries. I would like to add support for arm processors, but I'm not sure when will I have time to do so.

carlos-santos-anchor commented 5 days ago

That makes sense @AleksaC . I didn't even thought about that 😓

From what I'm seeing in the code, this doesn't look like a huge effort, maybe I could try it out one of these days.

Confirm me if this would be enough:

We're using circleci-cli_0.1.30549_darwin_amd64.tar.gz but we should be using circleci-cli_0.1.30549_darwin_arm64.tar.gz.

So looking into the code, these are the images we're using, and we would need to do a slight change to, not just compare the sys.platform, but also which processor.

Would platform.processor() work? Mixed with platform.system()?

e.g. running on arm M3:

>>> platform.processor()
'arm'
>>> platform.system()
'Darwin'
>>>

also in linux:

>>> platform.processor()
'x86_64'
>>> platform.system()
'Linux'

And then we could have something like this:

ARCHIVE_SHA256 = {
    "linux": (
        "circleci-cli_0.1.30549_linux_amd64.tar.gz",
        "807c98f96a54b2d63e54a068e215eac2af9c529f59529ad6474c4d73d8caf93c",
    ),
    "darwin-x86_64": (
        "circleci-cli_0.1.30549_darwin_amd64.tar.gz",
        "924e3f3cd375902cb564f9becebe6e98faaab319456375214885b44150628779",
    ),
+    "darwin-arm": (
+        "circleci-cli_0.1.30549_darwin_arm64.tar.gz",
+        "15a0ee5c8578617f160dab264c5cb7baeb7d5869ea30b49a02805c083b2afa97",
+    ),
    "win32": (
        "circleci-cli_0.1.30549_windows_amd64.zip",
        "0c554a10d3d8cb7a4d330c6d4f9a0b218e830dd45175d8f2d743abd338842364",
    ),
}

Of course, also adding the ARM variants for Linux

AleksaC commented 5 days ago

Yep, I used platform.machine() in similar projects. I don't remember why, so I compared the two on a couple machines I have access to. On one of my linux servers I get:

>>> platform.machine()
'x86_64'

vs

>>> platform.processor()
''

So I'm guessing that platform.machine is more reliable.

Either way if you get a chance to submit a PR I'd be glad to merge it.