Skip to content

Commit 5de7205

Browse files
committed
fix: Fetch hub-restyled to a temporary file during release.
Instead of downloading hub-restyled to the repository tree where it might be accidentally committed, the release script now downloads it to a temporary file if it's not already available in the PATH or the script directory.
1 parent 2735bd7 commit 5de7205

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

.github/workflows/release-deploy.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ jobs:
4848
- name: Link ci-tools
4949
if: github.repository == 'TokTok/ci-tools'
5050
run: ln -s .. third_party/ci-tools
51-
- name: Download hub-restyled
52-
run: |
53-
mkdir -p third_party/ci-tools/tools
54-
curl -sSL https://raw.githubusercontent.com/TokTok/hs-github-tools/master/tools/hub-restyled -o third_party/ci-tools/tools/hub-restyled
55-
chmod +x third_party/ci-tools/tools/hub-restyled
5651
- name: Create GitHub actions identity
5752
run: third_party/ci-tools/tools/use_github_actions_identity.sh
5853
- name: Set up git upstream remote

tools/create_release.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import argparse
55
import os
66
import re
7+
import shutil
78
import subprocess # nosec
9+
import tempfile
810
from dataclasses import dataclass
911

12+
import requests
1013
import create_tarballs
1114
import sign_release_assets
1215
import sign_tag
@@ -619,9 +622,29 @@ def stage_restyled(self, version: str, parent: stage.Stage) -> None:
619622
with stage.Stage("Restyled", "Applying restyled fixes", parent=parent) as s:
620623
script_dir = os.path.dirname(os.path.realpath(__file__))
621624
hub_restyled = os.path.join(script_dir, "hub-restyled")
625+
626+
downloaded = False
622627
if not os.path.exists(hub_restyled):
623-
hub_restyled = "hub-restyled"
624-
subprocess.run([hub_restyled], check=True) # nosec
628+
path_version = shutil.which("hub-restyled")
629+
if path_version:
630+
hub_restyled = path_version
631+
else:
632+
s.progress("Downloading hub-restyled")
633+
url = "https://raw.githubusercontent.com/TokTok/hs-github-tools/master/tools/hub-restyled"
634+
r = requests.get(url, timeout=60)
635+
r.raise_for_status()
636+
with tempfile.NamedTemporaryFile(delete=False) as f:
637+
f.write(r.content)
638+
hub_restyled = f.name
639+
os.chmod(hub_restyled, 0o755)
640+
downloaded = True
641+
642+
try:
643+
subprocess.run([hub_restyled], check=True) # nosec
644+
finally:
645+
if downloaded:
646+
os.unlink(hub_restyled)
647+
625648
if self.git.is_clean():
626649
raise s.fail("Failed to apply restyled changes")
627650
self.git.add(".")

0 commit comments

Comments
 (0)