-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (107 loc) · 4.34 KB
/
Copy pathrelease.yml
File metadata and controls
126 lines (107 loc) · 4.34 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
name: Release CLI Files
on:
push:
branches:
- main
paths:
- "mnl_factory/scripts/ver.py"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
env:
BEFORE_SHA: ${{ github.event.before }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect CLI version change
id: version_check
run: |
GITHUB_OUTPUT_PATH="${GITHUB_OUTPUT}" python - <<'PY'
import os
import re
import subprocess
from pathlib import Path
def extract_version(text: str) -> str:
match = re.search(r"__VER__\s*=\s*['\"]([^'\"]+)['\"]", text)
if not match:
raise SystemExit("Unable to find __VER__ in mnl_factory/scripts/ver.py")
return match.group(1)
current_path = Path("mnl_factory/scripts/ver.py")
current_version = extract_version(current_path.read_text())
before_sha = os.environ.get("BEFORE_SHA", "")
previous_version = ""
changed = True
if before_sha and before_sha != "0000000000000000000000000000000000000000":
result = subprocess.run(
["git", "show", f"{before_sha}:mnl_factory/scripts/ver.py"],
capture_output=True,
text=True,
)
if result.returncode == 0 and result.stdout.strip():
previous_version = extract_version(result.stdout)
changed = previous_version != current_version
with open(os.environ["GITHUB_OUTPUT_PATH"], "a", encoding="utf-8") as f:
f.write(f"version={current_version}\n")
f.write(f"previous_version={previous_version}\n")
f.write(f"changed={'true' if changed else 'false'}\n")
PY
- name: Stop when ver.py changed without version bump
if: steps.version_check.outputs.changed != 'true'
run: |
echo "ver.py changed, but __VER__ stayed at ${{ steps.version_check.outputs.version }}."
echo "Skipping CLI release."
- name: Validate r1setup fallback version
if: steps.version_check.outputs.changed == 'true'
run: |
EXPECTED_VERSION="${{ steps.version_check.outputs.version }}"
FALLBACK_VERSION="$(python - <<'PY'
import re
from pathlib import Path
content = Path("mnl_factory/scripts/r1setup").read_text()
match = re.search(r'CLI_VERSION = "([^"]+)"', content)
if not match:
raise SystemExit("Unable to find fallback CLI_VERSION in r1setup")
print(match.group(1))
PY
)"
if [[ "${FALLBACK_VERSION}" != "${EXPECTED_VERSION}" ]]; then
echo "r1setup fallback version (${FALLBACK_VERSION}) does not match ver.py (${EXPECTED_VERSION})."
exit 1
fi
- name: Create release assets
if: steps.version_check.outputs.changed == 'true'
run: |
VERSION="${{ steps.version_check.outputs.version }}"
TAG_NAME="v${VERSION}"
echo "📦 Creating complete repository archive..."
git archive --format=tar.gz --prefix="r1setup-${TAG_NAME}/" HEAD > "r1setup-${TAG_NAME}.tar.gz"
mkdir -p cli-files
cp mnl_factory/scripts/r1setup cli-files/
cp mnl_factory/scripts/ver.py cli-files/
cp mnl_factory/scripts/update.py cli-files/
- name: Create or update GitHub release
if: steps.version_check.outputs.changed == 'true'
run: |
VERSION="${{ steps.version_check.outputs.version }}"
TAG_NAME="v${VERSION}"
ASSETS=(
"r1setup-${TAG_NAME}.tar.gz"
"cli-files/r1setup"
"cli-files/ver.py"
"cli-files/update.py"
)
if gh release view "${TAG_NAME}" >/dev/null 2>&1; then
echo "Release ${TAG_NAME} already exists. Uploading refreshed assets."
gh release upload "${TAG_NAME}" "${ASSETS[@]}" --clobber
else
gh release create "${TAG_NAME}" \
"${ASSETS[@]}" \
--target "${GITHUB_SHA}" \
--title "Release ${TAG_NAME}" \
--notes "Automated CLI release for ${TAG_NAME}"
fi