Skip to content

Commit

Permalink
add branch creation action
Browse files Browse the repository at this point in the history
  • Loading branch information
hrideshmg committed Oct 21, 2024
1 parent 55bf905 commit 975fb3a
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
contents: write

jobs:
audit-and-merge:
audit:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -70,44 +70,52 @@ jobs:
- name: Get the PR author username
id: pr_user
run: |
PR_USER=${{ github.event.pull_request.user.login }}
echo "The PR was created by $PR_USER"
echo "::set-output name=pr_user::$PR_USER"
echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
echo "The PR was created by $PR_AUTHOR"
- name: Pass the diff and file content to Python validation
run: |
python validate_pixel_update.py changes.txt changed_file_content.txt ${{ steps.pr_user.outputs.pr_user }}
- name: Create a new branch and merge the PR
id: create_branch_and_merge
run: |
PR_USER=${{ steps.pr_user.outputs.pr_user }}
BRANCH_NAME=$PR_USER
COUNT=1
# Check if a branch with the username already exists
while git ls-remote --exit-code --heads origin "refs/heads/$BRANCH_NAME"; do
COUNT=$((COUNT+1))
BRANCH_NAME="${PR_USER}${COUNT}"
done
echo "::set-output name=branch_name::$BRANCH_NAME"
# Create the new branch from the base branch
git checkout -b "$BRANCH_NAME"
# Fetch the PR branch from the fork
git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
git fetch fork ${{ github.event.pull_request.head.ref }}:pr-branch
# Set committer identity to avoid "unknown identity" error
git config user.name "GitHub Action"
git config user.email "[email protected]"
# Merge the PR branch into the new branch
git merge --no-ff pr-branch
- name: Push the new branch to the repository
run: |
BRANCH_NAME=${{ steps.create_branch_and_merge.outputs.branch_name }}
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} "$BRANCH_NAME"
python validate_pixel_update.py changes.txt changed_file_content.txt "$PR_AUTHOR"
# - name: Create a new branch and merge the PR
# id: create_branch_and_merge
# run: |
# PR_USER=${{ steps.pr_user.outputs.pr_user }}
# BRANCH_NAME=$PR_USER
# COUNT=1
#
# # Check if a branch with the username already exists
# while git ls-remote --exit-code --heads origin "refs/heads/$BRANCH_NAME"; do
# COUNT=$((COUNT+1))
# BRANCH_NAME="${PR_USER}${COUNT}"
# done
#
# echo "::set-output name=branch_name::$BRANCH_NAME"
#
# # Create the new branch from the base branch
# git checkout -b "$BRANCH_NAME"
#
# # Fetch the PR branch from the fork
# git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
# git fetch fork ${{ github.event.pull_request.head.ref }}:pr-branch
#
# # Set committer identity to avoid "unknown identity" error
# git config user.name "GitHub Action"
# git config user.email "[email protected]"
# # Merge the PR branch into the new branch
# git merge --no-ff pr-branch
#
# - name: Push the new branch to the repository
# run: |
# BRANCH_NAME=${{ steps.create_branch_and_merge.outputs.branch_name }}
# git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} "$BRANCH_NAME"
auto_merge_pr:
needs: audit
runs-on: ubuntu-latest
steps:
- name: Create branch
uses: peterjgrainger/[email protected]
with:
branch: "$PR_AUTHOR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 975fb3a

Please sign in to comment.