Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lebovits/issu849 automate weekly pr to main #936

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions .github/workflows/weekly-pr-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,38 @@ on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
workflow_dispatch: # Allows manual triggering
inputs:
branch:
description: 'The branch to create the PR from'
required: true
default: 'staging'

jobs:
open-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Git
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Check if staging is ahead of main
id: check_diff
run: |
git fetch origin main
git fetch origin staging
if [ $(git rev-list --count main..staging) -gt 0 ]; then
git fetch origin main staging
if [ $(git rev-list --count origin/main..origin/staging) -gt 0 ]; then
echo "staging is ahead"
echo "::set-output name=staging_ahead::true"
echo "staging_ahead=true" >> $GITHUB_OUTPUT
else
echo "staging is not ahead"
echo "::set-output name=staging_ahead::false"
echo "staging_ahead=false" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Open PR if staging is ahead
- name: Create PR if staging is ahead
if: steps.check_diff.outputs.staging_ahead == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: staging
title: 'Weekly PR from Staging to Main'
body: 'Automated PR to merge staging into main. This PR was generated as part of the weekly process.'
labels: 'automated-pr'
commit-message: '[create-pull-request] Merge staging into main'
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_url=$(gh pr create --base main --head staging \
--title "Weekly PR from Staging to Main" \
--body "Automated PR to merge staging into main. This PR was generated as part of the weekly process.")
echo "Pull request created: $pr_url"

- name: Skip PR if no changes
if: steps.check_diff.outputs.staging_ahead == 'false'
Expand Down
Loading