The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Auto-post GitHub releases to Slack

To automatically post GitHub releases to a Slack channel, you can set up an integration between GitHub and Slack using GitHub Actions and the Slack API. This allows you to push notifications to a specific Slack channel whenever a new release is published on your GitHub repository.

Here’s a step-by-step guide on how to set this up:

1. Create a Slack Incoming Webhook

  • First, you’ll need to set up an Incoming Webhook in Slack.

  • Go to Slack API: Incoming Webhooks and create a new app.

  • Select Create New App, choose your workspace, and then select From Scratch.

  • In the app’s settings, go to Incoming Webhooks and turn them on.

  • Click Add New Webhook to Workspace and select the channel where you want to post the GitHub release updates.

  • After adding the webhook, copy the generated webhook URL. This will be used to post messages to Slack.

2. Set Up GitHub Action Workflow

Now, we need to create a GitHub Action that will trigger on a release event and send a message to Slack. Follow these steps:

Step 2.1: Create a Workflow File

  • In your GitHub repository, create a new directory .github/workflows if it doesn’t already exist.

  • Inside that directory, create a new YAML file, e.g., release-to-slack.yml.

Step 2.2: Configure the Workflow File

Here’s an example of a GitHub Action YAML file that triggers when a release is published and sends the release details to Slack.

yaml
name: Post Release to Slack on: release: types: [published] jobs: notify-slack: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - name: Send release details to Slack uses: slackapi/slack-github-action@v1.19.0 with: channel: '#your-slack-channel' slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} text: | :tada: A new release has been published! *Release Name:* ${{ github.event.release.name }} *Release URL:* ${{ github.event.release.html_url }} *Published At:* ${{ github.event.release.published_at }} env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

3. Add the Slack Webhook URL to GitHub Secrets

  • For security reasons, you shouldn’t directly include sensitive information like the Slack Webhook URL in your GitHub Action file.

  • Go to your GitHub repository’s Settings > Secrets.

  • Add a new repository secret named SLACK_WEBHOOK_URL and paste the webhook URL you got from Slack.

4. Test the Workflow

  • Now, when a new release is published in your GitHub repository, the GitHub Action will be triggered, and a message will be posted to the designated Slack channel with the release details.

  • You can create a test release by navigating to the Releases section of your repository and clicking Draft a new release.

Optional Enhancements:

  • You can customize the Slack message further by adding additional release details, such as the release description or assets attached to the release.

  • You can also make the workflow trigger for different events like when a release is edited, or a draft release is published, depending on your needs.

With this setup, you’ll be able to automatically notify your team or users on Slack whenever a new release is made on GitHub!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About