|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build (${{ matrix.asset_suffix }}) |
| 15 | + runs-on: ${{ matrix.runs_on }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + 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 |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Derive version |
| 42 | + id: version |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + tag="${GITHUB_REF_NAME}" |
| 46 | + version="${tag#v}" |
| 47 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 48 | + printf '%s\n' "$version" > VERSION |
| 49 | +
|
| 50 | + - name: Set up Python |
| 51 | + uses: actions/setup-python@v5 |
| 52 | + with: |
| 53 | + python-version: "3.12" |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + python -m pip install --upgrade pip |
| 59 | + python -m pip install -r requirements.txt |
| 60 | + python -m pip install pyinstaller |
| 61 | +
|
| 62 | + - name: Build binary (PyInstaller) |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + pyinstaller --noconfirm --clean --onefile --name cvecli --add-data "${{ matrix.add_data }}" cve_search_cli.py |
| 66 | +
|
| 67 | + - name: Package + checksums |
| 68 | + shell: bash |
| 69 | + 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 |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: release-${{ matrix.asset_suffix }} |
| 122 | + path: | |
| 123 | + dist/${{ matrix.exe_name }} |
| 124 | + cvecli-${{ steps.version.outputs.version }}-${{ matrix.asset_suffix }}.zip |
| 125 | + SHA256SUMS-${{ matrix.asset_suffix }}.txt |
| 126 | +
|
| 127 | + release: |
| 128 | + name: Create GitHub Release |
| 129 | + runs-on: ubuntu-latest |
| 130 | + needs: build |
| 131 | + steps: |
| 132 | + - name: Download artifacts |
| 133 | + uses: actions/download-artifact@v4 |
| 134 | + with: |
| 135 | + path: release_assets |
| 136 | + |
| 137 | + - name: Consolidate checksums |
| 138 | + shell: bash |
| 139 | + run: | |
| 140 | + set -euo pipefail |
| 141 | + find release_assets -type f -name "SHA256SUMS-*.txt" -print0 | sort -z | xargs -0 cat > SHA256SUMS.txt |
| 142 | +
|
| 143 | + - name: Publish GitHub Release assets |
| 144 | + uses: softprops/action-gh-release@v2 |
| 145 | + with: |
| 146 | + files: | |
| 147 | + release_assets/**/cvecli* |
| 148 | + release_assets/**/SHA256SUMS-*.txt |
| 149 | + SHA256SUMS.txt |
0 commit comments