Skip to content

Update dependency ruby to v3.4.10 #327

Update dependency ruby to v3.4.10

Update dependency ruby to v3.4.10 #327

name: Auto-approve last_reviewed_only PRs
on:
pull_request:
branches: [main]
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
auto-approve:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR is last_reviewed_only
id: check
run: |
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
DIFF=$(git diff "$BASE" "$HEAD" --unified=0 || true)
ALLOWED_PATTERN='^[[:space:]]*(last_reviewed_on|reviewed_on):[[:space:]]*([0-9]{4}-[0-9]{2}-[0-9]{2})[[:space:]]*$'
ALLOWED_COUNT=0
# Calculate max allowed date (1 year from today)
MAX_DATE=$(date -d "+1 year" +%Y-%m-%d 2>/dev/null || date -v+1y +%Y-%m-%d 2>/dev/null || echo "")
if [[ -z "$MAX_DATE" ]]; then
echo "Error: Unable to calculate max date. Using fallback validation."
MAX_DATE_EPOCH=$(($(date +%s) + 31536000))
else
MAX_DATE_EPOCH=$(date -d "$MAX_DATE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$MAX_DATE" +%s 2>/dev/null || echo "")
fi
while IFS= read -r line; do
[[ "$line" == ---* ]] && continue
[[ "$line" == +++* ]] && continue
if [[ "$line" == -* ]] || [[ "$line" == +* ]]; then
content="${line:1}"
if [[ "$content" =~ ^[[:space:]]*$ ]]; then
continue
fi
if [[ "$content" =~ $ALLOWED_PATTERN ]]; then
# Extract the date value (captured in BASH_REMATCH[2])
DATE_VALUE="${BASH_REMATCH[2]}"
# Only validate dates from additions (lines starting with +)
if [[ "$line" == +* ]]; then
# Validate date can be parsed
DATE_EPOCH=$(date -d "$DATE_VALUE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$DATE_VALUE" +%s 2>/dev/null || echo "")
if [[ -z "$DATE_EPOCH" ]]; then
echo "Invalid date format: '$DATE_VALUE'. Date must be a valid YYYY-MM-DD date."
echo "allowed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Check if date is more than 1 year in the future
if [[ -n "$MAX_DATE_EPOCH" ]]; then
if [[ "$DATE_EPOCH" -gt "$MAX_DATE_EPOCH" ]]; then
echo "Date '$DATE_VALUE' is more than 1 year in the future. Maximum allowed date: $MAX_DATE"
echo "allowed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
else
# Fallback: compare with current date + 1 year in seconds
CURRENT_EPOCH=$(date +%s)
MAX_FUTURE_EPOCH=$((CURRENT_EPOCH + 31536000))
if [[ "$DATE_EPOCH" -gt "$MAX_FUTURE_EPOCH" ]]; then
echo "Date '$DATE_VALUE' is more than 1 year in the future."
echo "allowed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
fi
((ALLOWED_COUNT++)) || true
else
echo "Changing Content other than last_reviewed_on, Auto-approve disabled, please get peer reviewed"
echo "allowed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
done <<< "$DIFF"
if [[ "$ALLOWED_COUNT" -eq 0 ]]; then
echo "No last_reviewed_on / reviewed_on changes found."
echo "allowed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "allowed=true" >> "$GITHUB_OUTPUT"
echo "Last_reviewed_only PR detected ($ALLOWED_COUNT change(s))."
- name: Approve PR and add label
if: steps.check.outputs.allowed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr review "${{ github.event.pull_request.number }}" --approve --body "Auto-approved: only \`last_reviewed_on\` / \`reviewed_on\` date updates."
gh pr edit "${{ github.event.pull_request.number }}" --add-label "reviewed and review date changed only" 2>/dev/null || (gh label create "reviewed and review date changed only" --color "0E8A16" --description "PR only updates last_reviewed date" --force && gh pr edit "${{ github.event.pull_request.number }}" --add-label "reviewed and review date changed only")
gh pr comment "${{ github.event.pull_request.number }}" --body "✅ **Auto-approved** — this PR only updates \`last_reviewed_on\` / \`reviewed_on\` dates; no doc content changes."