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

Create PR on Schedule (like every monday 8:00 am) #131

Closed
JigarM opened this issue Mar 5, 2020 · 9 comments
Closed

Create PR on Schedule (like every monday 8:00 am) #131

JigarM opened this issue Mar 5, 2020 · 9 comments

Comments

@JigarM
Copy link

JigarM commented Mar 5, 2020

Can we create a new PR from specific branch on schedule?
My requirement is need to create auto PR from develop to master on every week/specific day.

on:
  schedule:
    - cron: '0 8 * * MON'
jobs:
  createPullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Merge development to master
          title: '[Example] Add report file'
          body: |
            Auto-generated PR to make sure our `master` branch should have the latest code 
          labels: ready for review
          assignees: JigarM
          reviewers: JigarM
          branch: develop
@JigarM JigarM changed the title Create a new PR on Schedule (like every monday 8:00 am) Create PR on Schedule (like every monday 8:00 am) Mar 5, 2020
@peter-evans
Copy link
Owner

@JigarM You can do that, yes. Please see this example.

Here is what that pattern would look like for your workflow. It checks out master, resets to develop, and then creates a PR to merge into master. The PR branch is named master-promotion (you can rename it to whatever you want, but don't use an existing branch).

    steps:
      - uses: actions/checkout@v2
      - name: Reset promotion branch
        run: |
          git fetch origin develop:develop
          git reset --hard develop
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Merge development to master
          title: '[Example] Add report file'
          body: |
            Auto-generated PR to make sure our `master` branch should have the latest code 
          labels: ready for review
          assignees: JigarM
          reviewers: JigarM
          branch: master-promotion

@JigarM
Copy link
Author

JigarM commented Mar 5, 2020

@peter-evans Thanks for the quick response. Let me try this way.
I did the mistake to set the PR branch name with existing branch. I hope it should work. Will update you here.

Thanks anyway.!!!

@JigarM
Copy link
Author

JigarM commented Mar 5, 2020

@peter-evans Below changes works fine for me.

name: Create Pull Request
on:
  push:
  schedule:
    - cron: '0 8 * * MON'
jobs:
  createPullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: master
      - name: Reset develop branch
        run: |
          git fetch origin develop:develop
          git reset --hard develop
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Merge `development` to `master`
          title: Merge develop to master
          body: |
            Auto-generated PR to make sure our master branch should have the latest code 
          labels: ready for review
          branch: develop-promotion
      - name: Check outputs
        run: |
          echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"
          echo "Pull Request Number - ${{ steps.cpr.outputs.pr_number }}" 

Thanks for the help!!!!

@JigarM
Copy link
Author

JigarM commented Mar 5, 2020

@peter-evans One more thing I want to share. Github action can't trigger the workflow on schedule time. such as when I write this, nothing happens.

on:
  schedule:
    - cron: '0 8 * * MON'

But when I add push, the action triggered on push

on:
  push:
  schedule:
    - cron: '0 8 * * MON'

So, how we can schedule without "push" call?

@peter-evans
Copy link
Owner

Maybe MON isn't an accepted way to set the cron schedule. Try using digits to set the day instead.

on:
  schedule:
    - cron: '0 8 * * 1'

@JigarM
Copy link
Author

JigarM commented Mar 5, 2020

@peter-evans That's not an issue. Even I tried cron: "*/2 * * * *" but still its not working.
YML is not calling at every 2 minutes.

That's why I need to add push in the yml.

@JigarM
Copy link
Author

JigarM commented Mar 5, 2020

Do I need to update the yml with PAT(Personal access token)?

@peter-evans
Copy link
Owner

peter-evans commented Mar 5, 2020

You can't schedule it every 2 minutes. The shortest is 5.

The shortest interval you can run scheduled workflows is once every 5 minutes.

https://help.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule

Also, make sure the workflow is in the master (default) branch. It won't trigger otherwise.

Do I need to update the yml with PAT(Personal access token)?

No, this is not necessary for your use case.

@JigarM
Copy link
Author

JigarM commented Mar 6, 2020

Got it!!!
@peter-evans Thanks for correcting me. Changes runs fine now.
Thanks for everything..

@JigarM JigarM closed this as completed Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants