Skip to content

Commit a5f1c86

Browse files
authored
CM-22808 - Build CLI executable (#112)
1 parent 223b0fd commit a5f1c86

File tree

5 files changed

+252
-19
lines changed

5 files changed

+252
-19
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build executable version of CLI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ ubuntu-20.04, macos-11, windows-2019 ]
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
defaults:
18+
run:
19+
shell: bash
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Set up Python 3.7
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: '3.7'
31+
32+
- name: Setup Poetry
33+
uses: snok/install-poetry@v1
34+
35+
- name: Install dependencies
36+
run: poetry install
37+
38+
- name: Build executable
39+
run: poetry run pyinstaller pyinstaller.spec
40+
41+
- name: Test executable
42+
run: ./dist/cycode --version
43+
44+
- uses: actions/upload-artifact@v3
45+
with:
46+
name: cycode-cli-${{ matrix.os }}
47+
path: dist

cycode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.0' # placeholder. Will be filled automatically on poetry build from Git Tag
1+
__version__ = '0.0.0' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag

poetry.lock

Lines changed: 133 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyinstaller.spec

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
# Run `poetry run pyinstaller pyinstaller.spec` to generate the binary.
3+
4+
5+
block_cipher = None
6+
7+
INIT_FILE_PATH = os.path.join('cycode', '__init__.py')
8+
9+
# save the prev content of __init__ file
10+
with open(INIT_FILE_PATH, 'r', encoding='UTF-8') as file:
11+
prev_content = file.read()
12+
13+
import dunamai as _dunamai
14+
VERSION_PLACEHOLDER = '0.0.0'
15+
CLI_VERSION = _dunamai.get_version('cycode', first_choice=_dunamai.Version.from_git).serialize(
16+
metadata=False, bump=True, style=_dunamai.Style.Pep440
17+
)
18+
19+
# write version from Git Tag to freeze the value and don't depend on Git
20+
with open(INIT_FILE_PATH, 'w', encoding='UTF-8') as file:
21+
file.write(prev_content.replace(VERSION_PLACEHOLDER, CLI_VERSION))
22+
23+
a = Analysis(
24+
['cycode/cli/main.py'],
25+
pathex=[],
26+
binaries=[],
27+
datas=[('cycode/cli/config.yaml', 'cycode/cli'), ('cycode/cyclient/config.yaml', 'cycode/cyclient')],
28+
hiddenimports=[],
29+
hookspath=[],
30+
hooksconfig={},
31+
runtime_hooks=[],
32+
excludes=['tests'],
33+
win_no_prefer_redirects=False,
34+
win_private_assemblies=False,
35+
cipher=block_cipher,
36+
noarchive=False,
37+
)
38+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
39+
40+
exe = EXE(
41+
pyz,
42+
a.scripts,
43+
a.binaries,
44+
a.zipfiles,
45+
a.datas,
46+
[],
47+
name='cycode',
48+
debug=False,
49+
bootloader_ignore_signals=False,
50+
strip=False,
51+
upx=True,
52+
upx_exclude=[],
53+
runtime_tmpdir=None,
54+
console=True,
55+
disable_windowed_traceback=False,
56+
argv_emulation=False,
57+
target_arch=None,
58+
codesign_identity=None,
59+
entitlements_file=None,
60+
)
61+
62+
# rollback the prev content of the __init__ file
63+
with open(INIT_FILE_PATH, 'w', encoding='UTF-8') as file:
64+
file.write(prev_content)

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cycode"
3-
version = "0.0.0" # placeholder. Will be filled automatically on poetry build from Git Tag
3+
version = "0.0.0" # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
44
description = "Perform secrets/iac scans for your sources using Cycode's engine"
55
keywords=["secret-scan", "cycode", "devops", "token", "secret", "security", "cycode", "code"]
66
authors = ["Cycode <support@cycode.com>"]
@@ -26,12 +26,11 @@ classifiers = [
2626
cycode = "cycode.cli.main:main_cli"
2727

2828
[tool.poetry.dependencies]
29-
python = "^3.7"
29+
python = ">=3.7,<3.12"
3030
click = ">=8.1.0,<8.2.0"
3131
colorama = ">=0.4.3,<0.5.0"
3232
pyyaml = ">=6.0,<7.0"
3333
marshmallow = ">=3.8.0,<3.9.0"
34-
typing = ">=3.7.4.3,<3.8.0.0"
3534
pathspec = ">=0.8.0,<0.9.0"
3635
gitpython = ">=3.1.30,<3.2.0"
3736
arrow = ">=0.17.0,<0.18.0"
@@ -47,8 +46,12 @@ pytest-mock = ">=3.10.0,<3.11.0"
4746
coverage = ">=7.2.3,<7.3.0"
4847
responses = ">=0.23.1,<0.24.0"
4948

50-
# poetry self add "poetry-dynamic-versioning[plugin]"
49+
[tool.poetry.group.executable.dependencies]
50+
pyinstaller = ">=5.11.0,<5.12.0"
51+
dunamai = ">=1.16.1,<1.17.0"
52+
5153
[tool.poetry-dynamic-versioning]
54+
# poetry self add "poetry-dynamic-versioning[plugin]"
5255
enable = true
5356
strict = true
5457
bump = true

0 commit comments

Comments
 (0)