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: 63 additions & 0 deletions .github/workflows/mattermost-notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: mattermost-notify.yml

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

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Mattermost message
env:
MATTERMOST_URL: ${{ inputs.mattermost_url }}
MATTERMOST_CHANNEL_ID: ${{ inputs.channel_id }}
MATTERMOST_MESSAGE: ${{ inputs.message }}
MATTERMOST_PERSONAL_ACCESS_TOKEN: ${{ secrets.MATTERMOST_PERSONAL_ACCESS_TOKEN }}
run: |
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)"

response_code="$(curl \
--silent \
--show-error \
--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")"

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

printf 'Message sent to Mattermost channel %s\n' "$MATTERMOST_CHANNEL_ID"
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# actions
Actions for common tasks in Holochain repositories

## Mattermost notifier action

Reusable workflow: `.github/workflows/mattermost-notify.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.

Example usage:

```yaml
name: Notify Mattermost

on:
workflow_dispatch:

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 }}
```