Time: 79 ms (100.00%) | Memory: 32.5 MB (100.00%) - LeetSync #120
This file contains hidden or 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 Co-Author | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| add-coauthor: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 2 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "actions@github.com" | |
| - name: Add co-author to latest commit | |
| run: | | |
| OWNER_NAME="Joshua Dierickse" | |
| OWNER_EMAIL="joshua.dierickse@gmail.com" | |
| # Get last commit message | |
| MSG=$(git log -1 --pretty=%B) | |
| AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') | |
| # If author or co-author not already included, amend commit | |
| if [ "$AUTHOR_EMAIL" != "$OWNER_EMAIL" ] && ! echo "$MSG" | grep -q "Co-authored-by: $OWNER_NAME"; then | |
| git commit --amend \ | |
| -m "$MSG" \ | |
| -m "Co-authored-by: $OWNER_NAME <$OWNER_EMAIL>" \ | |
| --no-edit | |
| git push --force | |
| fi |