Skip to content

Refactor error handling in CustomDjangoCache #945

Refactor error handling in CustomDjangoCache

Refactor error handling in CustomDjangoCache #945

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 }}
- 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 AUTHORS.md
git commit -m "Add ${{ github.event.pull_request.user.login }} to AUTHORS.md"
git push origin ${{ github.head_ref }}