I have been trying to automate and to update the authors.md whenever there is a new pull request and update it using the github action and below is the code for it
name: Add Contributor to AUTHORS.md
on:
pull_request:
types:
- opened
- synchronize
jobs:
add_contributor:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check if contributor already exists
id: check_contributor
run: |
exists=$(grep -c -F "$GITHUB_ACTOR" AUTHORS.md)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> $GITHUB_ENV
else
echo "exists=false" >> $GITHUB_ENV
fi
- name: Get contributor's full name
id: get_full_name
if: steps.check_contributor.outputs.exists == 'false'
run: |
username=$GITHUB_ACTOR
access_token=$GITHUB_TOKEN
full_name=$(curl -s -H "Authorization: token $access_token" "https://api.github.com/users/$username" | jq -r '.name')
if [[ -z "$full_name" ]]; then
full_name=$username
fi
echo "full_name=$full_name" >> $GITHUB_ENV
- name: Append contributor to AUTHORS.md
id: append_contributor
if: steps.check_contributor.outputs.exists == 'false'
run: |
echo "| $full_name | $GITHUB_ACTOR |" >> AUTHORS.md
- name: Commit and push changes
if: steps.check_contributor.outputs.exists == 'false'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add AUTHORS.md
git commit -m "Add $GITHUB_ACTOR to AUTHORS.md"
git push
but the github action is failing at the line exists=$(grep -c -F "$GITHUB_ACTOR" AUTHORS.md)
, can someone help and tell me how to resolve it
error i am getting
Run exists=$(grep -c -F "$GITHUB_ACTOR" AUTHORS.md)
Error: Process completed with exit code 1.
UPDATES:
name: Add Contributor to AUTHORS.md
on:
pull_request:
types:
- opened
- synchronize
jobs:
add_contributor:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check if contributor already exists
id: check_contributor
run: |
exists=$(grep -c -F "$GITHUB_ACTOR" AUTHORS.md)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Get contributor's full name
id: get_full_name
if: steps.check_contributor.outputs.exists == 'false'
run: |
username=$GITHUB_ACTOR
access_token=$GITHUB_TOKEN
full_name=$(curl -s -H "Authorization: token $access_token" "https://api.github.com/users/$username" | jq -r '.name')
if [[ -z "$full_name" ]]; then
full_name=$username
fi
echo "full_name=$full_name" >> $GITHUB_OUTPUT
- name: Append contributor to AUTHORS.md
id: append_contributor
if: steps.check_contributor.outputs.exists == 'false'
run: |
full_name=${{ steps.get_full_name.outputs.full_name }}
echo "| $full_name | $GITHUB_ACTOR |" >> AUTHORS.md
- name: Commit and push changes
if: steps.check_contributor.outputs.exists == 'false'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add AUTHORS.md
git commit -m "Add $GITHUB_ACTOR to AUTHORS.md"
git push
try to do some changes and also tried set+x method it is not working so removed it .
also tried to store to github outputs