Send github actions->CI result to Slack - github

I want to receive result of CI test in github actions to Slack.
Something like this:
Anybody knows how to do this or which tool should be used?
.github/workflows/verify.yml:
name: Verify CI
on: [push]
jobs:
tests:
name: Tests
...

You could use the slack-send GitHub Action to send data into Slack from your GitHub Workflow.
This Action can:
Send data to Slack's Workflow Builder (requires a paid Slack instance).
Send data via a Slack app to post to a specific channel (use an existing custom app or create a new one).
Send data via a Slack Incoming Webhook URL (use an existing custom app or create a new one).
There are a bunch of similar actions, for example, slack - GitHub Actions Slack integration - also simple and flexible Slack integration with GitHub Actions.

Related

How to Trigger a Jenkins Job on Pull Request Close Event from Webhook

We have an Enterprise Jenkins box with the GitHub Plugin that scans orgs and creates jobs for each branch/PR etc. Repos then have a webhook which send push/pull request events to the webhook, which builds them.
I'm trying to work out how to destroy ephemeral environments after a Ent. GitHub PR has been closed. I figured the best way to do this would be to have the webhook invoke the job and read the GH payload on the PR close event, however it doesn't appear like this is an option from any of the GH plugin settings on the org? The webhook simply disables job on the close event rather than building.
We don't have GitHub Actions available, so that's not an avenue. How else could I invoke a build upon PR close?

Repository-Webhooks vs Github Apps - which to use?

UseCase: My current use case is to react on new Issues and post automatic comments. This is mainly specific to one or two repositories.
Thus I guess webhooks on a repository as well as Github Apps can be used. Although Github has some really good documentation on both, I'm unsure which one to use for my scenario.
What advantages / disadvantages do they have when compared?
One advantage of Github Apps is that they don't need to add a WebHook to the repository according to this answer. - Not sure why that is an advantage.
Obviously a GitHub App can be installed in different repositories and also published in the marketplace. But I could also use the same URL for Webhooks in different repositories and thus mimmic that behavior with repository-webhooks to a certain extend.
What else?
The main difference is that while webhooks generate events and send them to a given URL Github. Apps have the right to access the repositories where you install them based on the permissions you give them.
If you have a webhook that fires every time an issue is updated you will receive an event at the URL you specified, but you will not have any rights to e.g. modify that issue in Github (e.g. through an API call).
If you instead have a Github App installed in your repository and the webhook URL set in the App settings, then the event will be sent to the URL as well. However, here's the difference: behind the webhook URL you will probably have a service that uses the Github App credentials (private key or temporary tokens) to make some modifications to your Github repo.
An example:
Webhook -> logging of Pull Request changes
Github App -> automate tagging of new pull requests
What else?
You can also use GitHub Actions. For your use case, there is the issues event (which is actually a webhook). It has several activity types, including opened:
on:
issues:
types: opened
This workflow only runs when an issue is created. Afterwards, you can use the REST API (e.g. via curl) to GET the newest issue and POST a comment.
As you said this is only relevent for "one or two repositories", I think it is fine to just copy & paste that workflow. If the number of repos grows, you may want to create a dedicated action.
Speaking of custom actions, there is also an existing Auto Comment action:
on: issues
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: bubkoo/auto-comment#v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
issuesOpened: >
Your issue comment goes here.

Integrating slack with github to get notifications on push happening to specific branch

I am looking for a way how i can get a message to slack channel when a push happens in specific branch of github repo.
I tried doing it with below mentioned steps -
1. Installed github app in slack.
2. Added github to slack channel using /github.
After that when i try connecting to repository, github asked to authenticate. When i tried to do so it is navigating me to github.com instead of custom github domain of the company.
Please help me here.
You could add to your repository a .github/workflows in order to use a GitHub Action (which is also available for GitHub Enterprise, not just github.com)
For example:
pullreminders/slack-action
An action which wraps the Slack chat.postMessage API method for posting to channels, private groups, and DMs.
This action sends messages using Slack bot tokens, which have two main advantages compared to user tokens and incoming webhooks:
Bots can't be disabled inadvertently when a Slack user is disabled or removed. Slack has written about this in a recent announcement, and
Bots offer a powerful range of capabilities that can be leveraged to perform more functions.
If you have a Drone continuous integration system in place you can use a webhook to trigger sending a Slack notification. This would work for the repository .drone.yml file:
- name: slack
image: plugins/slack
settings:
webhook: https://hooks.slack.com/services/...
channel: my_awesome_channel
username: Github Bot
when:
event: [ pull_request ]
branch: [ dev, master ]
template: |
New Pull Request Opened By: {{build.author}} ({{repo.name}} / {{build.branch}})
{{build.link}}
This assumes that drone is already enabled and the webhook configured in Github. If it isn't you can enable it through the Drone web dashboard by navigating to Repositories and clicking the green switch next to your repo name.
For custom github domain of company you need to use slack app (Githhub Enterprise Server) instead of Github App.
Once you are done with installation of Githhub Enterprise Server App on slack , Under configuration you will se payload url. Copy payload URL and go to github repository settings add webhooks sections and add payload url there and keep content type application/json

Github actions check_run is not called

I am playing with github actions and trying to do something whenever other check is completed. I see 0 runs for this action.
This action is available in master branch and I am opening PR to the master.
I've tried to capture events via webhooks and I receive events there just fine. Why is my action not working?
Code below:
name: on check run
on:
check_run:
types: [ completed, rerequested, completed, requested_action]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: ENV
run: env
- name: check out event
run: cat "$GITHUB_EVENT_PATH"
update
I also tried to have other checks in the repository (travis ci), the action is still not executed.
update 2
It turned out I was looking for different event that I needed. I confused status even with "check run" event. Travis ci in it's default setup produced "status" event, "check" api needs to be enabled separately
I think the issue might be that the GitHub Checks API support on Travis was only added to travis-ci.com. So if your checks are running on travis-ci.org you need to migrate.
See this blog post for the announcement.
https://blog.travis-ci.com/2018-05-07-announcing-support-for-github-checks-api-on-travis-ci-com
It is available to private and open source projects using travis-ci.com
This is the announcement about migration of
https://blog.travis-ci.com/2018-09-27-deprecating-github-commit-status-api-for-github-apps-managed-repositories
As part of our gradual migration to GitHub Apps for our GitHub integration, we’re formally deprecating GitHub Commit Status API updates for repositories on travis-ci.com managed by GitHub Apps. Instead, these repositories will have status updates reported to the GitHub Check Runs API.

How to restrict build failure emails to only a specific branch in travis CI?

I have email and slack notifications configured for travis build failures. Currently It sends notifications for build failure of every branch. Since every developer does creates lot of branches, the mails come in a large number which sound like spam. I would want to restrict the mails only for failures of develop branch.
My configuration in .travis.yml is something like this.
notifications:
email:
recipients:
- xyz#abc.com
branches:
only: develop
on_success: change
on_failure: always
Is this branch specific alerts are really supported, if yes how do you do it ?
For your specific query about if branch specific notification is supported by Travis currently, the answer is NO. Below is from the Travis documentation:
There is currently no way of limiting the notification to a specific branch, but the payload will contain all relevant data to do so at the receiving end
So currently the branch specific notification is not supported by Travis, but would need to be implemented separately by consuming the webhook payload from Travis.
Update:
(Courtesy #LucasCimon) There is an open GitHub issue to track this feature request.