Update contributors list, updated #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 from Git history | |
contributors=$(git log --format='%aN <%aE>' | sort -u | awk '{printf "- **%s** - [GitHub Profile](https://github.com/%s)\n", $1, $1}') | |
echo "contributors<<EOF" >> $GITHUB_ENV | |
echo "$contributors" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Update README.md | |
run: | | |
# Create a temporary file to hold the new README content | |
temp_file=$(mktemp) | |
# Track existing contributors | |
declare -A contributor_set | |
# Read the existing README content and populate the contributor_set | |
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" | |
# Populate the associative array with existing contributors | |
while read -r contributor; do | |
contributor_set["$contributor"]=1 | |
done <<< "$existing_contributors" | |
fi | |
done < README.md | |
# Append new contributors only if not already in the set | |
while read -r contributor; do | |
# Check if the contributor already exists in the set | |
if [[ -z "${contributor_set[$contributor]}" ]]; then | |
echo "$contributor" >> "$temp_file" | |
contributor_set["$contributor"]=1 # Add to the set | |
fi | |
done <<< "$contributors" | |
# 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 }} |