I am trying to create a GitHub action that will rebuild a dockerfile if a change is made to specific branch then pushed to main. If I remove the branch/specific the GitHub action works.
on:
push:
branches: [ main ], [ branch/specific/** ]
paths:
- '**.sh'
have also tried:
on:
push:
branches:
- main
- 'branch/specific/**'
paths:
- '**.sh'
Related
I have setup Github action for python app, it's located at
.github/workflows/python-app.yml
with details as
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
...
This executes fine however, We want to block if actions fails,
I'm unable to search this status under
Status checks that are required.
It was issue of name inside build which was not there in template
jobs:
build:
name: syntax-check
runs-on: ubuntu-latest
I have the following action:
name: Run after changing anything in myPath package
on:
pull_request:
push:
paths:
- 'myPath/**'
This action runs when something is pushed under myPath but also on any pull request.
How I can limit this action to pull requests that contain changes under myPath?
You have to repeat paths for each event type.
name: Run after changing anything in myPath package
on:
pull_request:
paths:
- 'myPath/**'
push:
paths:
- 'myPath/**'
I have a Github Action that deploys my app from the main branch when there is a push to it or a merge from a pull request:
'on':
push:
branches:
- main
jobs:
build_and_deploy:
What I am trying to accomplish is to only run the action if the pull request comes from a branch that does not contain the string "nodeploy/" in its name.
I tried this:
'on':
push:
branches:
- main
jobs:
build_and_deploy:
if: ${{ !startsWith(github.head_ref, 'nodeploy/') }}
but it didn't work.
I believe it doesn't work because the value of github.head_ref is always main in this case.
Are there any solutions to this?
I found a solution. As suggested in the comments, I checked the message in the head commit.
'on':
push:
branches:
- main
jobs:
build_and_deploy:
if: ${{ !contains(github.event.head_commit.message, 'nodeploy/') }}
And now it does what I wanted.
Be aware that if you change the automatically generated merge message it won't work.
I want my workflow to trigger on a push only if there are changes made to a specific directory. Is this possible, what am I missing? I tried doing something like what you see below, but it didn't fire the trigger.
name: ABC
on:
push:
branches: [master/my-directory]
pull_request:
branches: [ master ]
push has a property called paths:
name: ABC
on:
push:
branches:
- master
paths:
- my-directory/**
This will only trigger on pushes to the master branch with changes in the my-directory directory tree. See the filter pattern cheat sheet for all possible filter patterns.
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.
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.