29
loading...
This website collects cookies to deliver better user experience
#frontend
Slack channel and also to announce product releases to the relevant squad's channels. The release BOT looks like the one below:# Action name
name: CD
# Action triggers
on:
push:
branches:
- main
# Action jobs
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: npm ci
- run: npm run build:app
- run: npm run deploy
main
. Now let's enhance it to notify a channel, on Slack, every time the application is deployed.# Action name
name: CD
# Action triggers
on:
push:
branches:
- main
# Action jobs
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: npm ci
- run: npm run build:app
- run: npm run deploy
slack:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Get latest commit info
run: |
echo "::set-output name=TITLE::$(git show -1 --format='%s' -s)"
id: latest_commit
- name: Announce on Slack 📢
run: |
curl ${{ secrets.SLACK_RELEASE_BOT_WEBHOOK_URL }} \
--request POST \
--header 'Content-type: application/json' \
--data \
'{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.latest_commit.outputs.TITLE }}"
}
}
]
}'
slack
. This jobs needs
the deploy
job to run first so we only announce the release after the deployment. It gets the latest commit message to be used as release title (this is completely open to customization) and afterward, it sends a POST request to our webhook.SLACK_RELEASE_BOT_WEBHOOK_URL
is defined as a secret in the repositoryset-output
and id
curl
might not be the best experience and can lead to a lot of errors, we can create our own GitHub Action. Clear advantages are easy to reuse and, most important, documentation.curl
step through different workflows is creating a composite action. Composite actions allow you to group a sequence of steps without much extra setup. All you need is one file by the end.uses
key in your steps.action.yml
. This file will have the following template:name: Slack Release BOT
description: Slack Release BOT used by us
inputs:
webhook_url:
required: true
description: Slack webhook URL
title:
required: true
description: Message title
runs:
using: 'composite'
steps:
- shell: bash
run: |
curl ${{ inputs.webhook_url }} \
--request POST \
--header 'Content-type: application/json' \
--data \
'{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ inputs.title }}"
}
}
]
}'
inputs
allow you to pass data from your main workflow to this action through with
, the full example will show it. We encapsulated the curl
into its own action, allowing all applications to use it once we push the code to our repository.github-username/my-action
:# Action name
name: CD
# Action triggers
on:
push:
branches:
- main
# Action jobs
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: npm ci
- run: npm run build:app
- run: npm run deploy
slack:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Get latest commit info
run: |
echo "::set-output name=TITLE::$(git show -1 --format='%s' -s)"
id: latest_commit
- uses: github-username/my-action@main
with:
webhook_url: ${{ secrets.SLACK_RELEASE_BOT_WEBHOOK_URL }}
title: ${{ steps.latest_commit.outputs.TITLE }}
curl
ourselves, we just use the new action, and using with
we can pass the required variables.curl
from another workflow.curl
step with the new action for every release of our component library: https://github.com/homeday-de/homeday-blocks/pull/74429