-
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (116 loc) · 3.46 KB
/
release.yml
File metadata and controls
138 lines (116 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Release
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build:
name: Build (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
exe: cvecli.exe
asset: windows
- os: ubuntu-latest
exe: cvecli
asset: linux
- os: macos-latest
exe: cvecli
asset: macos
steps:
- uses: actions/checkout@v4
- name: Set version
shell: bash
run: |
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
printf '%s\n' "${GITHUB_REF_NAME#v}" > VERSION
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: "requirements.txt"
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build binary
shell: bash
run: |
add_data="VERSION:."
if [ "${{ runner.os }}" = "Windows" ]; then
add_data="VERSION;."
fi
pyinstaller --noconfirm --clean --onefile \
--name cvecli \
--add-data "$add_data" \
cve_search_cli.py
- name: Package release artifact
shell: bash
run: |
python - <<'PY'
import hashlib
import os
import pathlib
import zipfile
version = os.environ["VERSION"]
asset = os.environ["ASSET"]
exe = os.environ["EXE"]
repo = pathlib.Path(".").resolve()
dist_exe = repo / "dist" / exe
if not dist_exe.exists():
raise SystemExit(f"missing built binary: {dist_exe}")
zip_name = f"cvecli-{version}-{asset}.zip"
zip_path = repo / zip_name
def sha256_file(path: pathlib.Path) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
for chunk in iter(lambda: f.read(1024 * 1024), b""):
h.update(chunk)
return h.hexdigest()
files = [
(dist_exe, exe),
(repo / "README.md", "README.md"),
(repo / "LICENSE", "LICENSE"),
]
with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for src, arc in files:
zf.write(src, arcname=arc)
sha = sha256_file(zip_path)
(repo / "checksums.txt").write_text(f"{sha} {zip_name}\n", encoding="utf-8")
print(f"Wrote {zip_name} and checksums.txt")
PY
env:
ASSET: ${{ matrix.asset }}
EXE: ${{ matrix.exe }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset }}
path: |
cvecli-${{ env.VERSION }}-${{ matrix.asset }}.zip
checksums.txt
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Merge checksums
run: |
cat artifacts/**/checksums.txt > checksums.txt
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/**/*.zip
checksums.txt