Skip to content

Update contributors list, update #12

Update contributors list, update

Update contributors list, update #12

name: Update Contributors
on:
push:
branches:
- main # Change this to your default branch if it's not main
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get contributors
id: contributors
run: |
# Fetch contributors and format them
contributors=$(git log --format='%aN <%aE>' | sort -u | awk '{printf "- **%s** - [GitHub Profile](https://github.com/%s)\n", $1, $1}')
echo "::set-output name=contributors::$contributors"
- name: Update README.md
run: |
# Create a temporary file to hold the new README content
temp_file=$(mktemp)
# Read the existing README content
while IFS= read -r line; do
echo "$line" >> "$temp_file"
# Check for the Contributors section
if [[ "$line" == "## Contributors" ]]; then
# Write existing contributors
existing_contributors=$(sed -n '/## Contributors/,/##/p' README.md | sed '1d;$d')
echo "$existing_contributors" >> "$temp_file"
# Create an associative array to store existing contributors
declare -A contributor_set
# Add existing contributors to the array
while read -r contributor; do
contributor_set["$contributor"]=1
done <<< "$existing_contributors"
# Append new contributors only if not already in the array
while read -r contributor; do
if [[ -z "${contributor_set[$contributor]}" ]]; then
echo "$contributor" >> "$temp_file"
contributor_set["$contributor"]=1 # Add to the set
fi
done <<< "${{ steps.contributors.outputs.contributors }}"
fi
done < README.md
# Move the temp file to the original README
mv "$temp_file" README.md
- name: Commit changes
run: |
git config --local user.email "you@example.com" # replace with your email
git config --local user.name "GitHub Action" # replace with a name you want to use
git add README.md
git commit -m "Update contributors list"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}