Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github actions on pull request and master branch

Github actions is still in beta and pretty new, but I hope someone can help regardless. I thought it would be possible to run github actions on the master branch and on pull requests, like this:

on:
  pull_request
  push:
    branches: master

But this doesn't work, and throws the error

yaml: line 4: mapping values are not allowed in this context

. Instead I can only get it to work like this:

on: [pull_request, push]

What am I doing wrong? Thanks.

like image 553
Thjen Avatar asked Oct 01 '19 12:10

Thjen


People also ask

Do GitHub actions only run on master?

The first workflow runs for every branch except master . In this workflow you run tests only. The second workflow runs for just master and runs both your tests and deploys if the tests were successfully passed.

Can a GitHub action create a pull request?

A GitHub action to create a pull request for changes to your repository in the actions workspace. Changes to a repository in the Actions workspace persist between steps in a workflow. This action is designed to be used in conjunction with other steps that modify or add files to your repository.

What happens to branch after pull request?

If you're working in a shared repository model, you create a pull request and you, or someone else, will merge your changes from your feature branch into the base branch you specify in your pull request.

How do you raise a pull request in master branch?

Once you've committed changes to your local copy of the repository, click the Create Pull Request icon. Check that the local branch and repository you're merging from, and the remote branch and repository you're merging into, are correct. Then give the pull request a title and a description. Click Create.


2 Answers

I think you are just missing a colon after pull_request. This works for me.

on:
  pull_request:
  push:
    branches: master
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Test
        run: echo "done"
like image 126
peterevans Avatar answered Oct 02 '22 10:10

peterevans


Explanation

Each trigger has to be defined as a property that defines an object.

Each object defines overrides for default settings.

There are 3 possible syntax you can use:

Minimal syntax:

on:
  pull_request:
  push: { branches: [master] }

Explicit syntax:

on:
  pull_request: {}
  push: { branches: [master] }

Extendable syntax:

on:
  pull_request:
  push: 
    branches: 
      - master

When using a version control system the latter may be most useful as diff viewers can always easily distinguish* between different lines.

*Although modern diff viewers can also easily distinguish inline differences.

like image 23
Webber Avatar answered Oct 02 '22 09:10

Webber