Skip to content

Commit

Permalink
Add Slack integration and workflow to send messages (#22)
Browse files Browse the repository at this point in the history
* Add Slack integration and workflow to send messages

* add slack notifications

* add slack webhook url

* move notify to workflow

* Add registry username and password inputs to build action

* maybe?

* add webhook url

* add payload

* make tag link

* fix?

* explicitly add ghcr registry.

* fixy fix

* better

* format link
  • Loading branch information
KevinMind authored Mar 15, 2024
1 parent 008c92f commit d820425
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ inputs:
required: true
description: "Build and push image to registry (cannot be used together with load)"
default: "false"
password:
required: false
description: "Password for the registry"
username:
required: false
description: "Username for the registry"

outputs:
tags:
Expand Down Expand Up @@ -36,15 +42,17 @@ runs:
if: ${{ inputs.push == 'true' }}
uses: docker/login-action@v3
with:
registry: 'ghcr.io'
registry: ghcr.io
username: ${{ inputs.username }}
password: ${{ inputs.password }}

# Determine the tags for the image
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# Hard coding our dockerhub imnage name
images: mozilla/test-github-features
images: ghcr.io/mozilla/test-github-features
tags: |
type=schedule
type=ref,event=tag
Expand Down
26 changes: 26 additions & 0 deletions .github/actions/slack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Send slack message
description: Send a slack message
inputs:
message:
description: "Message to send"
required: true
channel:
description: "The channel to send the message to"
required: false
default: "test-github-features"
webhook_url:
description: "The webhook url to use"
required: true
runs:
using: 'composite'
steps:
- name: Send message
uses: slackapi/slack-github-action@v1
with:
channel-id: ${{ inputs.channel }}
payload: |
{
"message": "${{ inputs.message }}"
}
env:
SLACK_WEBHOOK_URL: ${{ inputs.webhook_url }}
22 changes: 21 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@ name: Build
on:
create:
workflow_dispatch:
inputs:
push:
description: 'Push to registry'
required: false
default: 'false'

permissions:
contents: read
packages: write

jobs:
ci_build:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
id: build
uses: ./.github/actions/build
with:
push: ${{ github.event.inputs.push }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Notify
if: ${{ inputs.push == 'true' }} && ${{ success() }}
uses: ./.github/actions/slack
with:
message: "Image built and pushed to [${{ steps.build.outputs.tags }}](${{ steps.build.outputs.tags }})"
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}

12 changes: 12 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ jobs:
run: |
echo "Deploying to staging"
# Your deployment script here
- name: Notify (scuccessful deployment)
if: success()
uses: ./.github/actions/slack
with:
message: ":tada: Deployed to staging :white_check_mark: successfully!"
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Notify (failed deployment)
if: failure()
uses: ./.github/actions/slack
with:
message: ":fail: Failed to deploy to staging :red_flag: successfully!"
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
13 changes: 13 additions & 0 deletions .github/workflows/ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Ping slack

on:
workflow_dispatch:

jobs:
ping:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/slack
with:
message: 'Hello from GitHub Actions! :tada:'
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
12 changes: 12 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ jobs:
run: |
echo "Deploying to production"
# Your deployment script here
- name: Notify (scuccessful deployment)
if: success()
uses: ./.github/actions/slack
with:
message: ":tada: Deployed to production :white_check_mark: successfully!"
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Notify (failed deployment)
if: failure()
uses: ./.github/actions/slack
with:
message: ":fail: Failed to deploy to production :red_flag: successfully!"
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}

0 comments on commit d820425

Please sign in to comment.