Skip to content

Python hello

Python hello #5

Workflow file for this run

name: Add new contributor to AUTHORS.md
on:
pull_request:
types: [opened]
jobs:
check_contributor_exists:
runs-on: ubuntu-latest
outputs:
is_contributor_in_file: ${{ steps.check_contributor_step.outputs.exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: .
- name: Check if contributor already exists
id: check_contributor_step
run: |
exists=$(grep -c -F "${{ github.event.pull_request.user.login }}" AUTHORS.md || true)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
add_contributor:
runs-on: ubuntu-latest
needs: check_contributor_exists
if: needs.check_contributor_exists.outputs.is_contributor_in_file == 'false'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get contributor's full name and append to AUTHORS.md file
run: |
username=${{ github.event.pull_request.user.login }}
full_name=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/users/$username" | jq -r '.name')
if [[ "$full_name" == "" || "$full_name" == "null" ]]; then
full_name='-'
fi
echo "| $full_name | $username |" >> AUTHORS.md
- name: Commit and push changes to the contributor's PR branch
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Update AUTHORS.md"
git push origin ${{ github.head_ref }}