Skip to content

Adding Get-Tree.ps1 & Get-Tree.md #52

Adding Get-Tree.ps1 & Get-Tree.md

Adding Get-Tree.ps1 & Get-Tree.md #52

name: Update Credits List
on:
pull_request:
types: [closed]
branches: [master]
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (no commit)'
required: false
default: 'false'
jobs:
update_credits:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build new CREDITS.md content
id: build
shell: bash
run: |
set -euo pipefail
echo "Collecting commit data..."
git fetch --all
git log --pretty=format:'%H|%an|%ae|%ad' --date=iso --reverse > commits_full.log
declare -A commit_count
declare -A last_date
declare -A last_hash
while IFS='|' read -r hash name email date; do
if [[ -z "$name" || -z "$email" || -z "$date" ]]; then
continue
fi
# Determine GitHub profile
if [[ "$email" =~ ^[0-9]+@users\.noreply\.github\.com$ ]]; then
username="@${email%%@*}"
elif [[ "$email" =~ \+([^@]+)@users\.noreply\.github\.com$ ]]; then
username="@${BASH_REMATCH[1]}"
else
username="@unknown"
fi
key="$name|$username"
commit_count["$key"]=$(( ${commit_count["$key"]:-0} + 1 ))
# Keep latest date and hash
if [[ -z "${last_date["$key"]+x}" || "$date" > "${last_date["$key"]-}" ]]; then
last_date["$key"]="$date"
last_hash["$key"]="$hash"
fi
done < commits_full.log
temp="CREDITS.tmp"
> "$temp"
for key in "${!commit_count[@]}"; do
IFS='|' read -r name username <<< "$key"
date="${last_date[$key]}"
hash="${last_hash[$key]}"
total="${commit_count[$key]}"
file=$(git show --pretty=format: --name-only "$hash" | head -n 1)
[[ -z "$file" ]] && file="/unknown" || file="/$file"
# Cross-platform date formatting
if date --version >/dev/null 2>&1; then
date_fmt=$(date -d "$date" +"%Y-%m-%d %H:%M")
else
date_fmt=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$date" +"%Y-%m-%d %H:%M")
fi
echo "| $name | $username | $date_fmt | $total | $file |" >> "$temp"
done
sort -r -k3 "$temp" > "$temp.sorted"
{
echo "# Credits"
echo ""
echo "| Contributor | Profile | Last Commit Date | Total Commits | Last Description/Path |"
echo "|-------------|---------|------------------|----------------|-------------------------|"
cat "$temp.sorted"
echo ""
echo "<!-- This file is automatically updated by workflow. Additions will appear below. -->"
} > CREDITS.md
- name: Show diff
run: git diff CREDITS.md || true
- name: Commit and push if not dry-run
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry_run != 'true' }}
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add CREDITS.md
git stash --include-untracked
git pull --rebase
git stash pop || true
if git diff --quiet; then
echo "No changes to commit."
else
git add CREDITS.md
git commit -m "Automated update of CREDITS.md"
git push
fi
env:
GITHUB_TOKEN: ${{ secrets.AWSR }}