Skip to content

Commit

Permalink
lets try as a notify.sh script
Browse files Browse the repository at this point in the history
Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Dec 20, 2024
1 parent 7830319 commit 3a3d92a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/notify-irc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# notify.sh
# This script formats the IRC notification message.

# Extract input from environment variables (set by GitHub Actions)
COMMITS_JSON="$1"
ACTOR="$2"
BRANCH="$3"
COMPARE_URL="$4"

# Parse the JSON to extract commit titles
COMMIT_TITLES=$(echo "$COMMITS_JSON" | jq -r '.[0:8][] | "\(.id[0:7]) - \(.message | split("\n")[0])"')

# Count the commits
COMMIT_COUNT=$(echo "$COMMITS_JSON" | jq -r 'length')

# Format the message
if [ "$COMMIT_COUNT" -eq 1 ]; then
echo "[openzfs] $ACTOR pushed 1 commit to $BRANCH"
else
echo "[openzfs] $ACTOR pushed $COMMIT_COUNT commits to $BRANCH"
fi

echo "$COMPARE_URL"

# Print each commit title
echo "$COMMIT_TITLES"

25 changes: 16 additions & 9 deletions .github/workflows/notify-irc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install jq
run: sudo apt-get install -y jq

- name: Notify IRC
uses: rectalogic/notify-irc@v1
with:
channel: "#OpenZFS-Windows"
server: "irc.libera.chat"
nickname: zfs-consus
message: |
[openzfs] ${{ github.actor }} pushed ${{ github.event.commits && github.event.commits.size || 0 }} commit${{ github.event.commits && github.event.commits.size > 1 && 's' || '' }} to ${{ github.ref_name }}
${{ github.event.compare }}
${{ join(github.event.commits.*.message.split('\n')[0], '\n') }}
env:
COMMITS_JSON: ${{ toJson(github.event.commits) }}
ACTOR: ${{ github.actor }}
BRANCH: ${{ github.ref_name }}
COMPARE_URL: ${{ github.event.compare }}
run: |
.github/workflows/notify-irc.sh "$COMMITS_JSON" "$ACTOR" "$BRANCH" "$COMPARE_URL" | notify-irc \
--channel "#OpenZFS-Windows" \
--server "irc.libera.chat" \
--nickname zfs-consus

0 comments on commit 3a3d92a

Please sign in to comment.