add test line, updatew #19
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 unique 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) | |
# Read the existing README content | |
contributor_found=false | |
while IFS= read -r line; do | |
echo "$line" >> "$temp_file" | |
# Check for the Contributors section | |
if [[ "$line" == "## Contributors" ]]; then | |
contributor_found=true | |
# Skip existing contributors | |
echo "" >> "$temp_file" # Add a blank line before new contributors | |
fi | |
done < README.md | |
# Append new unique contributors only if they are not already in the existing list | |
while IFS= read -r contributor; do | |
# Check if the contributor already exists in the existing contributors | |
if ! grep -q "$contributor" "$temp_file"; then | |
echo "$contributor" >> "$temp_file" | |
fi | |
done <<< "${{ env.contributors }}" | |
# If the Contributors section was found, add a closing comment (if needed) | |
if [ "$contributor_found" = true ]; then | |
echo "## " >> "$temp_file" | |
fi | |
# 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" || echo "No changes to commit" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |