codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
245 stars 42 forks source link

Fix certificates globbing from relative paths for `keychain add-certificates` #374

Closed priitlatt closed 10 months ago

priitlatt commented 10 months ago

It is possible to specify custom certificate paths or path patterns for action keychain add-certificates via CLI option --certificate. As this option accepts either path literals, or a glob patterns to match certificates, then relative reference . to current directory should also be an acceptable input. This however results in an error when globbing matches:

>>> list(Path().glob('.'))
Traceback (most recent call last):
  File "/Users/priit/development/nevercode/cli-tools/.venv/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-23-b1f87bcdf599>", line 1, in <cell line: 0>
    list(Path().glob('.'))
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 1094, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour, case_sensitive)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.12.0/lib/python3.12/pathlib.py", line 83, in _make_selector
    pat = pattern_parts[0]
          ~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

To overcome that limitation, just resolve the relative path pattern before attempting glob search. Then the path becomes absolute which can be safely globbed.

Updated actions:

priitlatt commented 10 months ago

Some QA notes:

  1. Adding certs from ., .., etc fails since those are directories.
  2. Default case without specifying custom certificate paths/patterns still works as expected.
  3. Specifying custom relative path works as expected.
  4. Specifying custom relative path pattern works as expected.
  5. Specifying custom absolute path works as expected.
Screenshot ![Screenshot 2023-11-13 at 12 52 53](https://github.com/codemagic-ci-cd/cli-tools/assets/2756611/cb9bc29c-2349-478a-a438-ffb0d10a619e)