Have a unique check-run for github actions workflow - github

I'm trying to enforce labelling PR's using enforce-label-action.
name: Enforce PR label
on:
pull_request:
types: [labeled, unlabeled, opened, edited]
jobs:
enforce-label:
runs-on: ubuntu-latest
steps:
- uses: yogevbd/enforce-label-action#master
with:
REQUIRED_LABELS_ANY: "bug,enhancement,feature"
The problem is that each time PR is labeled, a new check-run getting created and the old one's still having a failing status which cause the check-suite to show: Some checks were not successful.
Is it possible for github-actions to discard the old check-runs when a workflow check with the same name is getting triggered?

This is now fixed, it was a bug on GitHubs end.

Related

Automatically set the assignee on an issue using guthub actions

I am trying to add some automation to my github project (the project feature, not a repo). I added a project for my user which I use to manage all my issues. I created a github action that always assigns issues and PRs to this project so I always have an overview over all todos.
Now I want another action. My project uses 4 statuses:
Backlog
Selected for Development
In Progress
Done
I want to automatically assign a user to an issue when the issue is moved into status "In Progress". The assignee should be the current user (= ${{ github.actor }}). So far this works.
on:
issues:
types:
- opened
pull_request:
types:
- opened
permissions:
contents: read
issues: write
pull-requests: write
jobs:
add-to-project:
name: Add to project
runs-on: ubuntu-latest
steps:
- name: Add to project (issues and PRs)
uses: actions/add-to-project#main
with:
project-url: https://github.com/users/sebastian-sommerfeld-io/projects/1
github-token: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}
assign-issue-to-user:
name: Assign to user
runs-on: ubuntu-latest
steps:
- name: Assign issue to user
uses: pozil/auto-assign-issue#v1
# https://github.com/marketplace/actions/auto-assign-issue
with:
assignees: ${{ github.actor }}
numOfAssignee: 1
allowSelfAssign: true
abortIfPreviousAssignees: true
Assigning the issue works (job assign-issue-to-user). But the assignee should only be set automatically, if the assignee field is empty (I do not want to override existing assignees) and if the issue is moved into the project status "In Progress". This if condition is the problem I cannot get my head around. The code above just always assigns the user when the issue is created. Regardless of any column change.

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

How to run a Github Action when a pull requestion is merged to master?

I am new to Github actions and I have searched all over to answer my question. I have an action setup to run on all push events but apparently that does not count for merging pull requests. So I wanted to know how I can run an action when a pull request is merged.
name: CI
on: push
jobs:
test:
name: test
...
deploy:
name: Deploy
needs: [test] # will wait until test finished
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
...
One way is to use if condition.