Authors are pilots of kolibri #943
Workflow file for this run
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: 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' | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Git and checkout PR's branch | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git fetch origin refs/pull/${{ github.event.number }}/head:pr | |
git checkout pr | |
- 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 add AUTHORS.md | |
git commit -m "Add ${{ github.event.pull_request.user.login }} to AUTHORS.md" | |
git push git@github.com:github.com/${{ github.event.pull_request.user.login }}/kolibri.git pr:${{ github.head_ref }} |