Related
Breaking Trough NAT: Decentralized Self-Hosting Via Open-Chat
How Open-Chats Federation Enables anybody to host anything anywhere
Popular topics
02 min reading in—DevOpsAutomation
Set up Slack notifications for deployments using GitHub Actions and the Python slack_sdk package, keeping your team updated automatically.
Need to notify your team about deployment status on Slack? Automate the process using the slack_sdk Python package with GitHub Actions. Here's how to set it up step by step:
Create a Slack App: Go to the Slack API section, select 'Create New App', input a name, and choose your workspace.
Set Permissions: In the Slack app settings, navigate to 'Features' > 'OAuth & Permissions'. Under 'Scopes', add chat:write for your bot to send messages. Once you save changes, click 'Install to Workspace'.
Retrieve Your Slack Bot Token: After installing the app to your workspace, grab your 'Bot User OAuth Token' from the 'OAuth & Permissions' page. Securely store this token as it will be used to authenticate your GitHub Actions script.
First, include your Slack API token as a secret in your GitHub repository:
SLACK_API_TOKEN.Now, integrate the send_slack_message.py script with your deployment process:
# send_slack_message.py import os from slack_sdk import WebClient client = WebClient(token=os.environ["SLACK_API_TOKEN"]) response = client.chat_postMessage( channel=os.environ["CHANNEL_ID"], mrkdwn=True, text=os.environ["MESSAGE"], ) print(response["message"]["text"])
Add a GitHub Actions step in your workflow to execute the notification script:
jobs: deployment: runs-on: ubuntu-latest steps: # ... previous steps for deployment ... - name: Notify Slack Channel env: SLACK_API_TOKEN: ${{ secrets.SLACK_API_TOKEN }} CHANNEL_ID: 'your-channel-id' MESSAGE: "*Deployment Update*\nImage: ${{ steps.build.outputs.IMAGE_URL }}\nURL: ${{ steps.deploy.outputs.WEBSITE_URL }}" run: | pip install slack_sdk wget -qO- https://raw.githubusercontent.com/tbscode/tims-blog-posts/main/assets/send_slack_message.py | python3 -
Replace your-channel-id with the actual Slack channel ID where you wish to send notifications.
Replace the script url with a self hosted fork of send_slack_message.py
Remember to update the MESSAGE variable with relevant details for your deployment, such as image URL or site URL.
Executing the GitHub Action with these configurations will automatically send your predefined message to the designated Slack channel, informing your team about the latest deployment status.
Your GitHub Actions workflow now works seamlessly with Slack for real-time notifications!
Related
How Open-Chats Federation Enables anybody to host anything anywhere
Related
A n8n workflow setup, that synchronizes workflow and credential changes directly to github
Related
Minimal, repeatable setup to run n8n with TLS behind nginx ingress using the 8gears Helm chart.