I can't for the life of me figure out why my GitHub Action isn't triggering on push. For context: I have a data file that is updated daily and pushed to the test branch with a timestamp commit message. I am trying to use this timestamp in a Dynamic Badge for my README. Everything works fine when the workflow is run manually (except, of course, I don't get the event data I am hoping to obtain when the action runs on the trigger.)
on:
push:
branches:
- test
paths:
- 'data/Sales.csv'
env:
BADGE_MESSAGE: ${{ github.event.commits[0].message }}
jobs:
create-badge-test:
runs-on: ubuntu-latest
steps:
- name: Create Dynamic Badge
uses: schneegans/dynamic-badges-action#v1.1.0
with:
auth: ${{ secrets.GIST_PAT }}
gistID: 0123456789 #Not actual gist ID
filename: test.json
label: Last Refresh
message: $BADGE_MESSAGE
color: orange
And yes, I've tried putting the branch name in quotes and updating the paths: to - '**.csv' and the action still does not trigger.
There must be something else wrong - all you have here in this workflows is just fine.
You can see it working here:
https://github.com/grzegorzkrukowski/stackoverflow_tests/actions/runs/1860382530
For this commit:
https://github.com/grzegorzkrukowski/stackoverflow_tests/commit/f3f8dd20fa780746441c7b6623b6a2a9929aa70d
It's exact copy of workflow from your question.
I would expect you are pushing a file with different name - keep in mind some systems will be case-sensitive - so pushing data/sales.csv won't work properly.
Another idea is that you pushing it to wrong branch or you have wrong path to the file.
You have to push to test branch and with data/Sales.csv - it only triggers workflow if both are true.
Short answers is - workflow is fine as it is - no brackets needed.
I could help more seeing the repository with this workflow and exact commits being done.
The action is not running because you also need to satisfy the paths condition as explained on GitHub docs
Note: If you use both the branches filter and the paths filter, the workflow will only run when both filters are satisfied.
If you want the action to run when you push to test you have to remove the paths condition
on:
push:
branches:
- 'test'
Related
I am trying to re-use a workflow in my GitHub repo and want to do something like this:
name: deploy
on:
push:
branches:
- 'dev'
- 'main'
jobs:
run-other-workflow:
uses: MyRepo/.github/workflows/some-other-workflow.yml#${{env.GITHUB_REF_NAME}}
I can't get this to work in any way that I am trying. Is this possible? Not being able to do this leads to duplicate templates.
EDIT:
Also tried:
jobs:
run-other-workflow:
uses: MyRepo/.github/workflows/some-other-workflow.yml#${{github.ref_name}}
I figured it out. The documentation uses the following example:
uses: octo-org/example-repo/.github/workflows/reusable-workflow.yml#main
This implies that you need to reference an org and a repo. This also seems to lead to the requirement of adding #main or #v1.
However, you can also reference your repo without the org like so:
uses: ./.github/workflows/reusable-workflow.yml
If you do it like this adding an #ref is not required. This was not immediately clear from the documentation.
I am modifying a workflow file so that a job doesn't run when a pull request originates from another repo.
So, I am looking for something like this:
build_and_deploy_job:
if: github.repository == github.pullrequest.repo
github.pullrequest.repo is just something I made up, but the idea would be that it would return the (full) name of the repo where the pull request came from.
I've tried outputting the environment variables to see if they are somehow different if a PR comes from a different branch in the same repo, or from a different repo. Nothing stood out to me as being useful.
Is something like that possible?
Background: I am trying to avoid a build job failure because it can't access a repo secret during a pull_request event when the pull request comes from another repo.
Use the following to check if the PR is coming from the same repo. This only works when the workflow is triggered by a pull request.
on: [pull_request]
jobs:
build_and_deploy_job:
if: github.event.pull_request.head.repo.name == github.repository
Bonus: Use this to check if the repo is a fork.
on: [pull_request]
jobs:
build_and_deploy_job:
if: github.event.pull_request.head.repo.fork == true
Source: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-object-34
I want to build a GitHub Action that triggers on Pull Request (PR) Approval, but only when the PR contains modification to a particular path.
Currently, I have the following implementation:
on:
pull_request_review:
types: [submitted]
paths: ['mypath/**']
jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout#v2
- name: job name
if: github.event.review.state == 'approved'
[Reference: https://github.community/t/github-actions-manual-trigger-approvals]
However, the build job triggers on Approval, and seems to ignore the path. The build runs on any Approval regardless of what files have been modified in the PR.
Is it possible to trigger a GitHub Action only when a PR modifies a particular path and it is approved?
I know fuzzi found an alternative using another solution with labels, but here is my contribution if someone wants to resolve the question issue keeping the original premisses:
Context
The ON trigger conditions work as OR and not as AND. Therefore, in the question sample, the workflow will trigger when a pull_request_review is submitted OR when one of the updated file(s) path is the one informed.
Workaround
It's not possible to check both condition (yet?) through the on workflow level field alone.
Therefore, if you want to check both conditions, you would have to do it separately.
A solution could be to check the submitted PR in the ON trigger first, then checking the folder path in a job step.
Example
Here is an example of what the solution suggested above looks like using the paths-changes-filter action:
on:
pull_request_review:
types: [submitted]
jobs:
build:
runs-on: self-hosted #or any other runner
steps:
- uses: actions/checkout#v2
- uses: dorny/paths-filter#v2
id: changes
with:
filters: |
mypath:
- 'mypath/**'
# run only if some file in 'src' folder was changed
- if: steps.changes.outputs.mypath == 'true' && github.event.review.state == 'approved'
run: ...
I found a solution to this using GitHub Labels instead, rather than file paths.
I implemented a GitHub Action for automatically adding a Label to the PR, based on the updated file paths.
(https://github.com/actions/labeler)
I then modified my existing GH Action to check the Label value. My condition is now:
if: github.event.label.name == 'project' && github.event.review.state == 'approved'
My workflow file looks like this:
on:
push:
branches:
- master
paths:
- "src/*"
pull_request:
branches:
- master
paths:
- "src/*"
At some point i added the paths: "src/*" and it simply won't trigger (anymore)?
I tried different things such as the filter on branches/paths, but it's like github actions cannot do PR merge checks? I've set them up with other CI platforms just fine, but i can't get it working with github actions. I have read in some article that PR checks will not work if there is a merge conflict, but that is not the case here either
It might be because your PR is still opened.
As your workflow is implemented:
The PR event is only triggered on the initial PR.
The workflow is not triggered on subsequent pushes events to the branch that has PR (and is not master).
I want that my GitHub Action that runs all tests doesn't execute when we push a new tag to the master repository because when we merge new branches we execute this action before, and when we push a tag to create a new release this action executes again.
Right now this action starts with this
name: Build and Test
on: push
As you see this will execute in every push we would make, and I want to change that this action will execute only when we push commits, no tags. My approximate solution would be this but I am not sure
name: Build and Test
on:
push:
branches:
- '*'
tags-ignore:
- '*'
That should work, but I'd recommend two improvements.
First, use ** instead of * (the edge case here is a branch/tag named /).
Second, omit the tags-ignore clause. In my testing, Github ignores all tags if you specify branches but not tags or tags-ignore.
name: Build and Test
on:
push:
branches:
- '**'