Speed up action setup with tarball install and parallel tool installs (#842)

Co-authored-by: UltralyticsAssistant <[email protected]>
This commit is contained in:
Glenn Jocher
2026-07-25 19:16:06 +02:00
committed by GitHub
co-authored by UltralyticsAssistant
parent c11c71a91c
commit 023864fc88
7 changed files with 32 additions and 32 deletions
+11 -11
View File
@@ -113,17 +113,17 @@ runs:
env:
INPUTS_SPELLING: ${{ inputs.spelling }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
GITHUB_SHA: ${{ github.sha }}
run: |
echo "::group::Install Dependencies"
trap 'echo "::endgroup::"' EXIT
# Install from current git branch if testing in ultralytics/actions repo, otherwise from GitHub main branch
# Source tarballs install ~2x faster than git+ URLs, which clone the repository first. Test the current commit
# in the ultralytics/actions repo, otherwise install main.
if [ "$GITHUB_REPOSITORY" = "ultralytics/actions" ]; then
echo "Installing from git branch: $GITHUB_REF"
packages="git+https://github.com/ultralytics/actions@${GITHUB_REF#refs/heads/}"
echo "Installing from commit: $GITHUB_SHA"
packages="https://github.com/ultralytics/actions/archive/${GITHUB_SHA}.tar.gz"
else
# packages="ultralytics-actions"
packages="git+https://github.com/ultralytics/actions@main"
packages="https://github.com/ultralytics/actions/archive/refs/heads/main.tar.gz"
fi
if [ "$INPUTS_SPELLING" = "true" ]; then
@@ -216,18 +216,18 @@ runs:
run: |
echo "::group::Run Prettier"
trap 'echo "::endgroup::"' EXIT
npm install -g [email protected] prettier-plugin-sh
npm install -g [email protected]
curl -fsSL "https://github.com/mvdan/sh/releases/download/v3.13.1/shfmt_v3.13.1_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')" -o "$(npm prefix -g)/bin/shfmt"
chmod +x "$(npm prefix -g)/bin/shfmt"
ultralytics-actions-update-markdown-code-blocks
npx prettier --write --list-different --print-width 120 "**/*.{js,jsx,ts,tsx,css,less,scss,json,yml,yaml,html,vue,svelte}" '!**/*lock.{json,yaml,yml}' '!**/*.lock' '!**/model.json' '!**/*.min.js' '!**/*.min.css'
# Bash file format
if find . -name "*.sh" -type f | grep -q .; then
npx prettier --write --list-different --print-width 120 --plugin=$(npm root -g)/prettier-plugin-sh/lib/index.cjs "**/*.sh"
fi
# Handle Markdown separately
find . -name "*.md" -type f ! -path "*/docs/*" -exec npx prettier --write --list-different --print-width 120 {} +
if [ -d "./docs" ]; then
find ./docs -name "*.md" -type f ! -path "*/reference/*" -exec npx prettier --tab-width 4 --print-width 120 --write --list-different {} +
fi
# Bash last: shfmt exits non-zero when a script fails to parse, which would otherwise skip the formatting above
find . -name "*.sh" -type f -not -path "*/node_modules/*" -not -path "*/.git/*" -exec shfmt -i 2 -sr -bn -ci -l -w {} +
shell: bash
continue-on-error: true
+1 -1
View File
@@ -28,4 +28,4 @@
# ├── test_summarize_pr.py
# └── ...
__version__ = "0.2.39"
__version__ = "0.2.40"
+5 -4
View File
@@ -19,17 +19,18 @@ RUFF_CHECK = [
RUFF_FORMAT = ["ruff", "format", "--line-length=120", "."]
DOCSTRINGS = ["ultralytics-actions-format-python-docstrings", "."]
PRETTIER = """
npm install -g [email protected] prettier-plugin-sh
npm install -g [email protected]
curl -fsSL "https://github.com/mvdan/sh/releases/download/v3.13.1/shfmt_v3.13.1_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')" -o "$(npm prefix -g)/bin/shfmt"
chmod +x "$(npm prefix -g)/bin/shfmt"
ultralytics-actions-update-markdown-code-blocks
npx prettier --write --list-different --print-width 120 "**/*.{js,jsx,ts,tsx,css,less,scss,json,yml,yaml,html,vue,svelte}" '!**/*lock.{json,yaml,yml}' '!**/*.lock' '!**/model.json' '!**/*.min.js' '!**/*.min.css'
if find . -name "*.sh" -type f | grep -q .; then
npx prettier --write --list-different --print-width 120 --plugin=$(npm root -g)/prettier-plugin-sh/lib/index.cjs "**/*.sh"
fi
# Handle Markdown separately
find . -name "*.md" -type f ! -path "*/docs/*" -exec npx prettier --write --list-different --print-width 120 {} +
if [ -d "./docs" ]; then
find ./docs -name "*.md" -type f ! -path "*/reference/*" -exec npx prettier --tab-width 4 --print-width 120 --write --list-different {} +
fi
# Bash last: shfmt exits non-zero when a script fails to parse, which would otherwise skip the formatting above
find . -name "*.sh" -type f -not -path "*/node_modules/*" -not -path "*/.git/*" -exec shfmt -i 2 -sr -bn -ci -l -w {} +
"""
CODESPELL = [
"codespell",
+8 -9
View File
@@ -96,26 +96,25 @@ def format_code_with_ruff(temp_dir):
print(f"ERROR running Python docstring formatter ❌ {e}")
def format_bash_with_prettier(temp_dir):
"""Formats bash script files in the specified directory using prettier."""
def format_bash_with_shfmt(temp_dir):
"""Formats bash script files in the specified directory using shfmt."""
if not next(Path(temp_dir).rglob("*.sh"), None):
return
try:
# Run prettier with explicit config path
# Flags reproduce prettier-plugin-sh output: 2-space indent, spaced redirects, binary ops and cases indented
result = subprocess.run(
"npx prettier --write --print-width=120 --plugin=$(npm root -g)/prettier-plugin-sh/lib/index.cjs ./**/*.sh",
shell=True, # must use shell=True to expand internal $(cmd)
["shfmt", "-i", "2", "-sr", "-bn", "-ci", "-w", str(temp_dir)],
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
print(f"ERROR running prettier-plugin-sh ❌ {result.stderr}")
print(f"ERROR running shfmt ❌ {result.stderr}")
else:
print("Completed bash formatting ✅")
except Exception as e:
print(f"ERROR running prettier-plugin-sh ❌ {e}")
print(f"ERROR running shfmt ❌ {e}")
def process_markdown_string(
@@ -141,7 +140,7 @@ def process_markdown_string(
if python_files_exist:
format_code_with_ruff(temp_dir)
if bash_files_exist:
format_bash_with_prettier(temp_dir)
format_bash_with_shfmt(temp_dir)
update_markdown_file(temp_md, markdown_snapshot, temp_files)
formatted_markdown = temp_md.read_text(encoding="utf-8")
@@ -244,7 +243,7 @@ def main(root_dir=None, process_python=True, process_bash=True, verbose=False):
if process_python:
format_code_with_ruff(temp_dir) # Format Python files
if process_bash:
format_bash_with_prettier(temp_dir) # Format Bash files
format_bash_with_shfmt(temp_dir) # Format Bash files
# Update Markdown files with formatted code blocks
for markdown_file, markdown_content, temp_files in all_temp_files:
+2 -2
View File
@@ -39,9 +39,9 @@ runs:
echo "::group::Install ultralytics-actions"
if [ "$GITHUB_REPOSITORY" = "ultralytics/actions" ]; then
echo "Installing from commit: $GITHUB_SHA"
packages="git+https://github.com/ultralytics/actions@${GITHUB_SHA}"
packages="https://github.com/ultralytics/actions/archive/${GITHUB_SHA}.tar.gz"
else
packages="git+https://github.com/ultralytics/actions@main"
packages="https://github.com/ultralytics/actions/archive/refs/heads/main.tar.gz"
fi
if [ "$(uname)" = "Darwin" ]; then
uv pip install --system --break-system-packages $packages
+2 -2
View File
@@ -55,9 +55,9 @@ runs:
echo "::group::Install ultralytics-actions"
if [ "$GITHUB_REPOSITORY" = "ultralytics/actions" ]; then
echo "Installing from commit: $GITHUB_SHA"
packages="git+https://github.com/ultralytics/actions@${GITHUB_SHA}"
packages="https://github.com/ultralytics/actions/archive/${GITHUB_SHA}.tar.gz"
else
packages="git+https://github.com/ultralytics/actions@main"
packages="https://github.com/ultralytics/actions/archive/refs/heads/main.tar.gz"
fi
if [ "$(uname)" = "Darwin" ]; then
uv pip install --system --break-system-packages $packages
+3 -3
View File
@@ -6,7 +6,7 @@ from unittest.mock import mock_open, patch
from actions.update_markdown_code_blocks import (
add_indentation,
extract_code_blocks,
format_bash_with_prettier,
format_bash_with_shfmt,
generate_temp_filename,
main,
process_markdown_file,
@@ -110,11 +110,11 @@ def test():
def test_format_bash_skips_when_no_shell_files(tmp_path):
"""Test bash formatter skips Prettier when no shell snippets were extracted."""
"""Test bash formatter skips shfmt when no shell snippets were extracted."""
(tmp_path / "snippet.py").write_text("print('ok')", encoding="utf-8")
with patch("subprocess.run") as mock_run:
format_bash_with_prettier(tmp_path)
format_bash_with_shfmt(tmp_path)
mock_run.assert_not_called()