Skip to content

Commit 7edc006

Browse files
committed
Added MacOS build CI
1 parent 7ffc17c commit 7edc006

1 file changed

Lines changed: 68 additions & 99 deletions

File tree

.github/workflows/release.yml

Lines changed: 68 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -11,139 +11,108 @@ permissions:
1111

1212
jobs:
1313
build:
14-
name: Build (${{ matrix.asset_suffix }})
15-
runs-on: ${{ matrix.runs_on }}
14+
name: Build (${{ matrix.os }})
15+
runs-on: ${{ matrix.os }}
16+
1617
strategy:
1718
fail-fast: false
1819
matrix:
1920
include:
20-
- runs_on: windows-latest
21-
asset_suffix: windows-x64
22-
add_data: "VERSION;."
23-
exe_name: cvecli.exe
24-
- runs_on: ubuntu-latest
25-
asset_suffix: linux-x64
26-
add_data: "VERSION:."
27-
exe_name: cvecli
28-
- runs_on: macos-13
29-
asset_suffix: macos-x64
30-
add_data: "VERSION:."
31-
exe_name: cvecli
32-
- runs_on: macos-14
33-
asset_suffix: macos-arm64
34-
add_data: "VERSION:."
35-
exe_name: cvecli
21+
- os: windows-latest
22+
exe: cvecli.exe
23+
asset: windows
24+
- os: ubuntu-latest
25+
exe: cvecli
26+
asset: linux
27+
- os: macos-latest
28+
exe: cvecli
29+
asset: macos
3630

3731
steps:
38-
- name: Checkout
39-
uses: actions/checkout@v4
32+
- uses: actions/checkout@v4
4033

41-
- name: Derive version
42-
id: version
34+
- name: Set version
4335
shell: bash
4436
run: |
45-
tag="${GITHUB_REF_NAME}"
46-
version="${tag#v}"
47-
echo "version=$version" >> "$GITHUB_OUTPUT"
48-
printf '%s\n' "$version" > VERSION
37+
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
38+
printf '%s\n' "${GITHUB_REF_NAME#v}" > VERSION
4939
50-
- name: Set up Python
40+
- name: Setup Python
5141
uses: actions/setup-python@v5
5242
with:
5343
python-version: "3.12"
44+
cache: "pip"
45+
cache-dependency-path: "requirements.txt"
5446

5547
- name: Install dependencies
56-
shell: bash
5748
run: |
58-
python -m pip install --upgrade pip
59-
python -m pip install -r requirements.txt
60-
python -m pip install pyinstaller
49+
pip install --upgrade pip
50+
pip install -r requirements.txt
51+
pip install pyinstaller
6152
62-
- name: Build binary (PyInstaller)
53+
- name: Build binary
6354
shell: bash
6455
run: |
65-
pyinstaller --noconfirm --clean --onefile --name cvecli --add-data "${{ matrix.add_data }}" cve_search_cli.py
56+
add_data="VERSION:."
57+
if [ "${{ runner.os }}" = "Windows" ]; then
58+
add_data="VERSION;."
59+
fi
60+
pyinstaller --noconfirm --clean --onefile \
61+
--name cvecli \
62+
--add-data "$add_data" \
63+
cve_search_cli.py
6664
67-
- name: Package + checksums
65+
- name: Package release artifact
6866
shell: bash
6967
run: |
70-
python - <<'PY'
71-
import hashlib
72-
import os
73-
import pathlib
74-
import zipfile
75-
from datetime import datetime
76-
77-
version = os.environ["VERSION"]
78-
suffix = os.environ["ASSET_SUFFIX"]
79-
exe_name = os.environ["EXE_NAME"]
80-
81-
repo = pathlib.Path(".").resolve()
82-
dist = repo / "dist"
83-
exe_path = dist / exe_name
84-
if not exe_path.exists():
85-
raise SystemExit(f"missing built binary: {exe_path}")
86-
87-
zip_name = f"cvecli-{version}-{suffix}.zip"
88-
sha_name = f"SHA256SUMS-{suffix}.txt"
89-
90-
def sha256_file(path: pathlib.Path) -> str:
91-
h = hashlib.sha256()
92-
with path.open("rb") as f:
93-
for chunk in iter(lambda: f.read(1024 * 1024), b""):
94-
h.update(chunk)
95-
return h.hexdigest()
96-
97-
files_for_zip = [
98-
(exe_path, exe_name),
99-
(repo / "LICENSE", "LICENSE"),
100-
(repo / "README.md", "README.md"),
101-
]
102-
103-
with zipfile.ZipFile(zip_name, "w", compression=zipfile.ZIP_DEFLATED) as zf:
104-
for src, arc in files_for_zip:
105-
zf.write(src, arcname=arc)
106-
107-
lines = []
108-
lines.append(f"{sha256_file(exe_path)} {exe_name}")
109-
lines.append(f"{sha256_file(pathlib.Path(zip_name))} {zip_name}")
110-
pathlib.Path(sha_name).write_text("\n".join(lines) + "\n", encoding="ascii")
111-
print(f"Wrote {zip_name} and {sha_name} at {datetime.utcnow().isoformat()}Z")
112-
PY
113-
env:
114-
VERSION: ${{ steps.version.outputs.version }}
115-
ASSET_SUFFIX: ${{ matrix.asset_suffix }}
116-
EXE_NAME: ${{ matrix.exe_name }}
117-
118-
- name: Upload artifacts
68+
mkdir -p release
69+
70+
ZIP_NAME="cvecli-${VERSION}-${{ matrix.asset }}.zip"
71+
72+
cp "dist/${{ matrix.exe }}" release/
73+
cp README.md release/
74+
cp LICENSE release/
75+
76+
cd release
77+
zip -r "../$ZIP_NAME" .
78+
79+
cd ..
80+
81+
python - <<'EOF'
82+
import hashlib, pathlib, os
83+
84+
file = pathlib.Path("$ZIP_NAME")
85+
sha = hashlib.sha256(file.read_bytes()).hexdigest()
86+
87+
with open("checksums.txt", "a") as f:
88+
f.write(f"{sha} {file.name}\n")
89+
EOF
90+
91+
- name: Upload artifact
11992
uses: actions/upload-artifact@v4
12093
with:
121-
name: release-${{ matrix.asset_suffix }}
94+
name: ${{ matrix.asset }}
12295
path: |
123-
dist/${{ matrix.exe_name }}
124-
cvecli-${{ steps.version.outputs.version }}-${{ matrix.asset_suffix }}.zip
125-
SHA256SUMS-${{ matrix.asset_suffix }}.txt
96+
cvecli-${{ env.VERSION }}-${{ matrix.asset }}.zip
97+
checksums.txt
12698
12799
release:
128-
name: Create GitHub Release
100+
name: Create Release
129101
runs-on: ubuntu-latest
130102
needs: build
103+
131104
steps:
132-
- name: Download artifacts
133-
uses: actions/download-artifact@v4
105+
- uses: actions/download-artifact@v4
134106
with:
135-
path: release_assets
107+
path: artifacts
136108

137-
- name: Consolidate checksums
138-
shell: bash
109+
- name: Merge checksums
139110
run: |
140-
set -euo pipefail
141-
find release_assets -type f -name "SHA256SUMS-*.txt" -print0 | sort -z | xargs -0 cat > SHA256SUMS.txt
111+
cat artifacts/**/checksums.txt > checksums.txt
142112
143-
- name: Publish GitHub Release assets
113+
- name: Publish GitHub Release
144114
uses: softprops/action-gh-release@v2
145115
with:
146116
files: |
147-
release_assets/**/cvecli*
148-
release_assets/**/SHA256SUMS-*.txt
149-
SHA256SUMS.txt
117+
artifacts/**/*.zip
118+
checksums.txt

0 commit comments

Comments
 (0)