Skip to content

Commit

Permalink
fix(workflow): Fix perms & condition check
Browse files Browse the repository at this point in the history
  • Loading branch information
hibare committed Nov 5, 2023
1 parent ed9fa52 commit 6ea8707
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/pr-creator.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

name: Create PR from Dev to Default Branch
on:
workflow_dispatch:
schedule:
- cron: '30 18 * * 6' # Runs every Saturday at midnight IST (adjust as needed)

env:
TARGET_BRANCH=dev

jobs:
create-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
Expand All @@ -17,8 +24,15 @@ jobs:
# Get the default branch name using GitHub API
DEFAULT_BRANCH=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/branches/default" | jq -r .name)
# Create a PR from "dev" to the default branch
PR_URL=$(gh pr create --base master --head "dev" --title "Auto-generated PR" -t "Auto-generated PR" -b "Auto-generated PR")
CHANGES_COUNT=$(git rev-list --left-right --count origin/$TARGET_BRANCH...origin/$DEFAULT_BRANCH | awk '{print $1}')
if [ "$CHANGES_COUNT" -eq "0" ]; then
echo "No changes in the '$TARGET_BRANCH' branch. Skipping PR creation."
exit 0
else
# Create a PR from "$TARGET_BRANCH" to the default branch
PR_URL=$(gh pr create --base "$DEFAULT_BRANCH" --head "$TARGET_BRANCH" --title "Auto-generated PR" -t "Auto-generated PR" -b "Auto-generated PR")
fi
echo "Created PR: $PR_URL"
env:
Expand Down

0 comments on commit 6ea8707

Please sign in to comment.