# .github/workflows/update_with_latest_master.yml
# 
# This is a Github Action Workflow to merge master into current branch when a label is added to a PR.
# Label: `update with latest master`
#
# 1) Add this yml file to your github workflows directory.
# 2) Add the issue/pr label: `update with latest master` to your project.
# 3) Any time you want to merge master into a branch, just add the `update with latest master` label to it!
#
# NOTE: This will trigger a new commit on your branch, potentially triggering CI, and other workflows.
# NOTE: If you've already added the label to a PR earlier but you need to update from master again, you can simply remove and re-add the label to the PR and it will trigger the action again!

name: Update with latest master

on:
  pull_request:
    types: [labeled]

jobs:
  merge-branch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      - name: Inject slug/short variables
        # https://stackoverflow.com/a/58730805/2696867
        uses: rlespinasse/github-slug-action@3.5.1

      - name: Merge master -> current
        # https://github.com/marketplace/actions/merge-branch#on-labeled
        uses: devmasx/merge-branch@v1.3.1
        with:
          label_name: 'update with latest master'
          from_branch: master
          target_branch: ${{ env.GITHUB_HEAD_REF_SLUG }}
          github_token: ${{ github.token }}