Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .github/workflows/mattermost-notify.yml

This file was deleted.

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ Actions for common tasks in Holochain repositories

## Mattermost notifier action

Reusable workflow: `.github/workflows/mattermost-notify.yml`
Composite action: `mattermost-notify/action.yml`

Inputs:
- `mattermost_url`: base URL for Mattermost (defaults to `https://chat.holochain.org`)
- `channel_id`: target Mattermost channel ID. This can be obtained by clicking the "(i)" icon at the top right of an open channel.
- `message`: message text to post

Secret:
- `MATTERMOST_PERSONAL_ACCESS_TOKEN`: Mattermost personal access token with permission to post in the channel.
- `mattermost_personal_access_token`: Mattermost personal access token with permission to post in the channel.

Example usage:

Expand All @@ -23,11 +21,13 @@ on:

jobs:
notify:
uses: holochain/actions/.github/workflows/mattermost-notify.yml@main
with:
mattermost_url: https://chat.example.com
channel_id: your_channel_id
message: Hello from GitHub Actions
secrets:
MATTERMOST_PERSONAL_ACCESS_TOKEN: ${{ secrets.MATTERMOST_PERSONAL_ACCESS_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Send Mattermost message
uses: holochain/actions/mattermost-notify@main
with:
mattermost_url: https://chat.example.com
channel_id: your_channel_id
message: Hello from GitHub Actions
mattermost_personal_access_token: ${{ secrets.MATTERMOST_PERSONAL_ACCESS_TOKEN }}
```
29 changes: 29 additions & 0 deletions mattermost-notify/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Mattermost notifier
description: Send a message to a Mattermost channel

inputs:
mattermost_url:
description: Base URL for the Mattermost instance (for example, https://example.com)
required: false
default: https://chat.holochain.org
channel_id:
description: Mattermost channel ID to post to
required: true
message:
description: Message text to send
required: true
mattermost_personal_access_token:
description: Mattermost personal access token
required: true

runs:
using: composite
steps:
- name: Send Mattermost message
shell: bash
env:
MATTERMOST_URL: ${{ inputs.mattermost_url }}
MATTERMOST_CHANNEL_ID: ${{ inputs.channel_id }}
MATTERMOST_MESSAGE: ${{ inputs.message }}
MATTERMOST_PERSONAL_ACCESS_TOKEN: ${{ inputs.mattermost_personal_access_token }}
run: "$GITHUB_ACTION_PATH/notify.sh"
34 changes: 34 additions & 0 deletions mattermost-notify/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail

base_url="${MATTERMOST_URL%/}"
posts_url="${base_url}/api/v4/posts"

payload="$(jq -cn \
--arg channel_id "$MATTERMOST_CHANNEL_ID" \
--arg message "$MATTERMOST_MESSAGE" \
'{channel_id: $channel_id, message: $message}')"

response_body="$(mktemp)"
trap 'rm -f "$response_body"' EXIT

response_code="$(curl \
--silent \
--show-error \
--connect-timeout 10 \
--max-time 30 \
--output "$response_body" \
--write-out "%{http_code}" \
--request POST "$posts_url" \
--header "Authorization: Bearer $MATTERMOST_PERSONAL_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data "$payload")"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if [ "$response_code" -lt 200 ] || [ "$response_code" -ge 300 ]; then
printf 'Mattermost API request failed with HTTP %s\n' "$response_code"
cat "$response_body"
exit 1
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.

printf 'Message sent to Mattermost channel %s\n' "$MATTERMOST_CHANNEL_ID"