forked from gongahkia/haus
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (133 loc) · 4.74 KB
/
Copy pathrelease.yml
File metadata and controls
158 lines (133 loc) · 4.74 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Poor-CLI Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
python-dist:
name: Build Python Distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build wheel and sdist
run: python -m build
- name: Validate distributions
run: twine check dist/*
- name: Upload Python distributions
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/*
if-no-files-found: error
tui-binaries:
name: Build TUI (${{ matrix.asset_suffix }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
asset_suffix: linux-x86_64
archive_format: tar.gz
binary_name: poor-cli-tui
- os: macos-13
asset_suffix: macos-x86_64
archive_format: tar.gz
binary_name: poor-cli-tui
- os: macos-14
asset_suffix: macos-arm64
archive_format: tar.gz
binary_name: poor-cli-tui
- os: windows-latest
asset_suffix: windows-x86_64
archive_format: zip
binary_name: poor-cli-tui.exe
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Build Rust TUI
run: cargo build --manifest-path poor-cli-tui/Cargo.toml --release --locked
- name: Package release archive
env:
ARCHIVE_FORMAT: ${{ matrix.archive_format }}
ASSET_SUFFIX: ${{ matrix.asset_suffix }}
BINARY_NAME: ${{ matrix.binary_name }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GITHUB_REF: ${{ github.ref }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
run: |
python - <<'PY'
import hashlib
import os
import tarfile
import zipfile
from pathlib import Path
archive_format = os.environ["ARCHIVE_FORMAT"]
asset_suffix = os.environ["ASSET_SUFFIX"]
binary_name = os.environ["BINARY_NAME"]
ref_name = os.environ.get("GITHUB_REF_NAME", "")
ref_value = os.environ.get("GITHUB_REF", "")
run_number = os.environ.get("GITHUB_RUN_NUMBER", "local")
release_label = ref_name if ref_value.startswith("refs/tags/") else f"snapshot-{run_number}"
binary_path = Path("poor-cli-tui") / "target" / "release" / binary_name
if not binary_path.is_file():
raise SystemExit(f"Missing built binary: {binary_path}")
output_dir = Path("release-artifacts")
output_dir.mkdir(parents=True, exist_ok=True)
if archive_format == "zip":
archive_name = f"poor-cli-tui-{release_label}-{asset_suffix}.zip"
archive_path = output_dir / archive_name
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as bundle:
bundle.write(binary_path, arcname=binary_name)
else:
archive_name = f"poor-cli-tui-{release_label}-{asset_suffix}.tar.gz"
archive_path = output_dir / archive_name
with tarfile.open(archive_path, "w:gz") as bundle:
bundle.add(binary_path, arcname=binary_name)
digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
checksum_path = output_dir / f"{archive_name}.sha256"
checksum_path.write_text(f"{digest} {archive_name}\n", encoding="utf-8")
PY
- name: Upload TUI artifacts
uses: actions/upload-artifact@v4
with:
name: tui-${{ matrix.asset_suffix }}
path: release-artifacts/*
if-no-files-found: error
publish-release:
name: Publish GitHub Release
if: startsWith(github.ref, 'refs/tags/')
needs:
- python-dist
- tui-binaries
runs-on: ubuntu-latest
steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: release-assets
merge-multiple: true
- name: Build consolidated checksums
run: |
cat release-assets/*.sha256 > release-assets/SHA256SUMS
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
files: release-assets/*
generate_release_notes: true