Skip to content

Commit

Permalink
fix: Update contributor workflow to improve README.md handling and br…
Browse files Browse the repository at this point in the history
…anch detection
  • Loading branch information
MAVRICK-1 committed Feb 8, 2025
1 parent 274d14d commit d7bd0a8
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/add-contributor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Add new contributors to readme.md
name: Add new contributors to README.md

on:
workflow_dispatch:
Expand All @@ -9,12 +9,13 @@ on:

jobs:
contrib-readme-job:
if: github.event.pull_request.merged == true && github.repository_owner == 'kubestellar' # Only run for merged PRs in 'kubestellar'
if: github.event.pull_request.merged == true && github.repository_owner == 'kubestellar'
runs-on: ubuntu-latest
name: A job to automate contributors in README
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -26,39 +27,36 @@ jobs:
readme_path: README.md
use_username: false
columns_per_row: 6
collaborators: all # Avoids permission issue
collaborators: all
commit_message: "docs(contributor): contrib-readme-action has updated readme"
auto_detect_branch_protection: false # Avoids branch protection issues
auto_detect_branch_protection: false
pr_title_on_protected: "docs(contributor): contributors readme action update"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for a few seconds
run: sleep 5

- name: Fetch All Remote Branches
run: |
git fetch --all
git fetch --prune --all
echo "Fetched all remote branches"
- name: Detect the Branch Created by the Action
id: get-branch
run: |
# Debug: Show all branches to understand the issue
echo "Available branches:"
git branch --all --sort=-committerdate --format='%(refname:short)'
# Find the branch created by the contributors-readme-action
CURRENT_BRANCH=$(git branch --all --sort=-committerdate --format='%(refname:short)' | grep "contributors-readme-action" | head -n 1)
# Strip 'origin/' from the branch name if it exists
CURRENT_BRANCH_CLEAN=${CURRENT_BRANCH#origin/}
echo "CURRENT_BRANCH=$CURRENT_BRANCH_CLEAN" >> $GITHUB_ENV
echo "Branch created by action: $CURRENT_BRANCH_CLEAN"
# Stop if branch is empty
if [ -z "$CURRENT_BRANCH_CLEAN" ]; then
echo "No branch created by action. Skipping remaining steps."
echo "SKIP_REMAINING=true" >> $GITHUB_ENV
else
echo "CURRENT_BRANCH=$CURRENT_BRANCH_CLEAN" >> $GITHUB_ENV
echo "Branch created by action: $CURRENT_BRANCH_CLEAN"
fi
- name: Configure Git
Expand All @@ -67,18 +65,19 @@ jobs:
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Checkout Action-Created Branch
if: env.SKIP_REMAINING != 'true'
run: |
git checkout -t origin/${{ env.CURRENT_BRANCH }} || git checkout -B ${{ env.CURRENT_BRANCH }} origin/${{ env.CURRENT_BRANCH }}
- name: Amend Commit with Signed-off-by
if: env.SKIP_REMAINING != 'true'
run: |
# Checkout the branch properly
git checkout -B ${{ env.CURRENT_BRANCH }} origin/${{ env.CURRENT_BRANCH }}
git commit --amend --no-edit --signoff || echo "No changes to amend"
- name: Push Changes Back to Remote Branch
if: env.SKIP_REMAINING != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Push the amended commit back to the remote branch
git push --force-with-lease origin ${{ env.CURRENT_BRANCH }}

0 comments on commit d7bd0a8

Please sign in to comment.