Skip to content

Update pr_creation.yml #6

Update pr_creation.yml

Update pr_creation.yml #6

Workflow file for this run

name: Auto-create Feature Branches and PRs
on:
push:
branches:
- master
jobs:
create_branches_and_prs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
FEATURE_NAME: testRes
DEV_ASSIGNEE: dev-user
DOC_ASSIGNEE: doc-user
QA_ASSIGNEE: qa-user
RELEASE_ASSIGNEE: release-owner
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitHub CLI
run: |
sudo apt update
sudo apt install -y gh
- name: Authenticate GH CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh auth setup-git
gh auth status
- name: Create branches if not exist
run: |
fname=${FEATURE_NAME}
base=master
echo "Creating branches for feature: $fname"
# Helper to create branch from base if not exists
create_branch() {
branch=$1
from=$2
if ! git ls-remote --exit-code origin "refs/heads/$branch" >/dev/null 2>&1; then
echo "Creating branch $branch from $from"
git fetch origin $from
git branch $branch origin/$from
git push origin $branch
else
echo "Branch $branch already exists, skipping."
fi
}
create_branch src/$fname $base
create_branch doc/$fname $base
create_branch test/$fname src/$fname
create_branch feature/$fname $base
- name: Create draft PRs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
fname=${FEATURE_NAME}
echo "Creating draft PRs for $fname"
create_pr() {
head=$1
base=$2
title=$3
assignee=$4
# Check if PR already exists
if gh pr list --head "$head" --base "$base" --json headRefName,baseRefName | jq -e '.[]' >/dev/null; then
echo "PR from $head to $base already exists, skipping."
else
echo "Creating PR: $head → $base"
gh pr create --base "$base" --head "$head" --title "$title" --draft ${assignee:+--assignee "$assignee"}
fi
}
create_pr src/$fname feature/$fname "Source changes for $fname" "$DEV_ASSIGNEE"
create_pr doc/$fname feature/$fname "Docs for $fname" "$DOC_ASSIGNEE"
create_pr test/$fname src/$fname "Tests for $fname" "$QA_ASSIGNEE"
create_pr feature/$fname master "Integrate $fname" "$RELEASE_ASSIGNEE"