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.
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.
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.
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.
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.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With