How to prevent running GitHub workflow on master/main - github

I have 2 workflows set up on GitHub:
pre submit verification (PSV) - should run on every push on every branch except master
submit verification (SV) - should be run only merge to master
PSV config:
name: Pre Submit Verification Pydriver
on:
push:
branches-ignore:
- master
And SV:
on:
push:
branches:
- master
Such configuration causes that when I push something to branch that is not the master PSV and SV workflows are run (When I push/merge to master everything works as expected and only SV is run).
I also tried such solution for excluding running SV on branches other than master:
on:
push:
branches-ignore:
- '!master'
But this also does not work. I would like to avoid conditions in steps to run SV.

Related

How do I configure a GitHub Actions workflow so it does not run on a tag push?

I'd like to configure a GitHub Actions workflow so that it runs on branch pushes, but not tag pushes. I thought this would work:
on:
push:
tags-ignore: ['**']
But then the workflow failed to run when I pushed a branch, too. Is there a way to configure it so that it runs on a branch push but not a tag push?
Unintuitively, to avoid the tags, you have to tell it to run on all the branches instead. See its use in psycopg for instance.
on:
push:
branches:
- "*"
pull_request:
schedule:
- cron: '48 6 * * *'
The docs say:
If you define only tags/tag-ignore or only branches/branches-ignore, the workflow won't run for events affecting the undefined Git ref.

Trigger diferent jobs depending on pull request type

I'm trying to reduce the amount of files I have for my workflows from 4 to 1. And with that my on is like this:
on:
pull_request:
types: [opened, synchronize, closed]
push:
branches: [master]
I know it's possible to use if in workflows but looking at the documentation I didn't find which parameters I should use to trigger the correct jobs when:
Pull request is opened
Pull request is closed
Push is made to a existing pull request
Push is made to a brach
The piece of documentation that touches on how to use if is this one.
You can use it at the job level. Consider the following example to execute a job only when the PR has been closed and merged (not just closed):
name: Build Your App
on:
pull_request:
types: [ closed ]
jobs:
build:
# this job will only run if the PR has been merged, not just 'closed'
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout#v2
with:
fetch-depth: '0'
And you can also use it at the step level, to execute or not the step based on the {{ expression }} evaluation, as the documentation shows.
Based on your ask, I would use the information on the github.event.* payload. To do that I use to re-create the conditions and triggers on a test repository and print it to the console. Then I know what I have to look for in each kind of event. It's like debugging the events. This is the documentation to do that.

how to define workflow to run based on two push rules

Is there a way to define 2 push rules in same workflow file or work around ?
How to combine and write below rules into single workflow file :
Run when any file is pushed on non master branch
On:
push:
branches-ignore:
- 'master'
paths:
- 'path-to-package/**'
Run Only when particular(package.json) file pushed in master branch
On:
push:
branches:
- 'master'
paths:
- 'path-to-package/package.json'
Your specific request doesn't appear to be supported by the syntax.
According to the workflow syntax for GitHub Actions documentation, two trigger configurations appear unrelated.
GitHub allows free users to open support requests. You could always make a feature request at support.github.com/contact
The closest workaround I know at the moment would be something like the workflow below, using a conditional inside your jobs.
on:
push:
paths:
- 'path-to-package/package.json'
jobs:
build_pom:
runs-on: ubuntu-latest
steps:
- run: echo 'this is master'
if: github.ref == 'refs/heads/master'

GitHub action branch creation for code review pull request

I'm trying to create a GitHub workflow that will run ONLY when a new branch is created with a pattern. The purpose of this is to create a Code Review Pull Request when a new branch is pushed to origin, but only on the first time the branch is created, so using a push event will not work and why I'm looking at create.
All of these combinations fail where any new branch created will run, instead of those just matching the pattern
name: "Create Code Review PR"
on:
create:
branches: ['feature/**']
or
name: "Create Code Reivew PR"
on:
create:
branches:
- 'feature/**'
- 'support/**'
- 'hotfix/**'
In both of these scenarios, if push a new branch called no-code-review, the above workflow will still run, but my expected behavior is that it wont run, but it should when a new branch such as these: feature/new-branch, support/new-support-branch or hotfix/fix-this ONLY.
The create event does not support a branch filter.
The alternative would be using an if condition on your step or job:
if: ${{ contains(github.ref, 'refs/heads/releases/') }}
Here's more information: https://github.community/t/trigger-job-on-branch-created/16878/5

GitHub Action: No event is appearing, is workflow running?

I've added to my repository a workflow inspired from https://henry.wang/2019/12/05/arm-dockerhub.html
The repository is public so you can see the "Action" tab here.
There were a typo error in the file:
So I fixed it and pushed the fix. However no new event is appearing: there is only the previous "fail" event as you can see above.
Does this mean that the worklow is running and is not terminated or does it mean the workflow wasn't started?
If it wasn't started what did I done wrong?
Ok, I just choosed the wrong branch.
Changed the workflow file from
on:
push:
branches:
- master
# ...
to
on:
push:
branches:
- auto-build
# ...
This works for all branches:
on: [push]
You can find more in the official doc
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
# Example: Using a list of events
# Triggers the workflow on push or pull request events
on: [push, pull_request]