Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ jobs:
run: bash actions/release/test_update_changelog.sh
- name: Test check_test_files.py
run: bash actions/test-sdist/test_check_test_files.sh
- name: Test parse_diff.sh
run: bash actions/pre-commit-autoupdate/test_parse_diff.sh

test_pre_commit_autoupdate:
if: github.event_name != 'schedule' || github.repository == 'Calysto/maintainer_tools'
Expand Down
14 changes: 1 addition & 13 deletions actions/pre-commit-autoupdate/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,7 @@ runs:
FULL_BRANCH="${BRANCH}-${SUFFIX}"

# Parse updated packages from diff
UPDATES=""
CURRENT_REPO=""
OLD_REV=""
while IFS= read -r line; do
if [[ "$line" == " "* ]] && [[ "$line" =~ repo:[[:space:]]+(.*) ]]; then
CURRENT_REPO=$(basename "${BASH_REMATCH[1]}")
elif [[ "$line" =~ ^-[[:space:]]+rev:[[:space:]]+(.*) ]]; then
OLD_REV="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^\+[[:space:]]+rev:[[:space:]]+(.*) ]]; then
NEW_REV="${BASH_REMATCH[1]}"
UPDATES="${UPDATES}- ${CURRENT_REPO}: \`${OLD_REV}\` → \`${NEW_REV}\`"$'\n'
fi
done < <(git diff .pre-commit-config.yaml)
UPDATES=$(git diff .pre-commit-config.yaml | bash "${{ github.action_path }}/parse_diff.sh" -)

BODY=""
if [ -n "$UPDATES" ]; then
Expand Down
22 changes: 22 additions & 0 deletions actions/pre-commit-autoupdate/parse_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Parse a git diff of .pre-commit-config.yaml and emit a markdown list of updates.
# Usage: parse_diff.sh <diff-file>
# Outputs lines of the form: "- <repo>: `<old>` → `<new>`"
set -euo pipefail

DIFF_FILE="${1:--}"

CURRENT_REPO=""
OLD_REV=""
while IFS= read -r line; do
if [[ "$line" == " "* ]] && [[ "$line" =~ repo:[[:space:]]+(.*) ]]; then
CURRENT_REPO=$(basename "${BASH_REMATCH[1]}")
elif [[ "$line" =~ ^-[[:space:]]+rev:[[:space:]]+(.*) ]]; then
OLD_REV="${BASH_REMATCH[1]//\'/}"
OLD_REV="${OLD_REV//\"/}"
elif [[ "$line" =~ ^\+[[:space:]]+rev:[[:space:]]+(.*) ]]; then
NEW_REV="${BASH_REMATCH[1]//\'/}"
NEW_REV="${NEW_REV//\"/}"
echo "- ${CURRENT_REPO}: \`${OLD_REV}\` → \`${NEW_REV}\`"
fi
done < <(cat "$DIFF_FILE")
49 changes: 49 additions & 0 deletions actions/pre-commit-autoupdate/test_parse_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT="$(cd "$(dirname "$0")" && pwd)/parse_diff.sh"
FAIL=0

check() {
local desc="$1"
local expected="$2"
local actual="$3"
if [ "$actual" = "$expected" ]; then
echo "OK: $desc"
else
echo "FAIL: $desc"
echo " expected: $expected"
echo " actual: $actual"
FAIL=1
fi
}

# Simulate a git diff with three repos using no quotes, single quotes, and double quotes
DIFF=$(cat <<'EOF'
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.4.0
+ rev: v4.5.0
- repo: https://github.com/psf/black
- rev: '23.1.0'
+ rev: '23.3.0'
- repo: https://github.com/PyCQA/flake8
- rev: "6.0.0"
+ rev: "6.1.0"
EOF
)

ACTUAL=$(echo "$DIFF" | bash "$SCRIPT" -)

check "no-quotes version" \
"- pre-commit-hooks: \`v4.4.0\` → \`v4.5.0\`" \
"$(echo "$ACTUAL" | grep pre-commit-hooks)"

check "single-quoted version" \
"- black: \`23.1.0\` → \`23.3.0\`" \
"$(echo "$ACTUAL" | grep black)"

check "double-quoted version" \
"- flake8: \`6.0.0\` → \`6.1.0\`" \
"$(echo "$ACTUAL" | grep flake8)"

exit $FAIL
Loading