From 300c7159403209791010cf7a54713171a67449cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Mon, 23 Mar 2026 21:19:39 +0100 Subject: [PATCH 1/4] Add github workflow to test the action --- .github/workflows/test.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..510426d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test action + +on: + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Send plain message + uses: ./ + with: + server: ${{ secrets.ROCKETCHAT_SERVER }} + user: ${{ secrets.ROCKETCHAT_USER }} + password: ${{ secrets.ROCKETCHAT_PASSWORD }} + channel: "#test-notifications-akiel" + message: "Test plain message from ${{ github.repository }}@${{ github.sha }}" From aac8c39c7d49c2d0230ab8fca25284503d28e881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Mon, 23 Mar 2026 21:22:49 +0100 Subject: [PATCH 2/4] Migrate away from docker --- action.yml | 49 +++++++++++++++++++++++------------------------ entrypoint.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/action.yml b/action.yml index e831db8..83483dc 100644 --- a/action.yml +++ b/action.yml @@ -1,38 +1,37 @@ -name: 'Rocket.Chat notification with credentials' -description: 'Send a message to Rocket.Chat' +name: "Rocket.Chat notification with credentials" +description: "Send a message to Rocket.Chat" branding: - icon: 'bell' - color: 'red' + icon: "bell" + color: "red" inputs: user: - description: 'The username to login to your rocket.chat server' + description: "The username to login to your rocket.chat server" required: true - default: '' + default: "" password: - description: 'The password to login to your rocket.chat server' + description: "The password to login to your rocket.chat server" required: true message: - description: 'The message you want to send' + description: "The message you want to send" required: true server: - description: 'Your rocket.chat server' + description: "Your rocket.chat server" required: false - default: 'https://open.rocket.chat' + default: "https://open.rocket.chat" channel: - description: 'The channel you want to write to' + description: "The channel you want to write to" required: false - default: 'GENERAL' - code: - description: 'Set it to true if you wish to have a code block' - required: false - default: 'false' + default: "GENERAL" runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.user }} - - ${{ inputs.password }} - - ${{ inputs.message }} - - ${{ inputs.server }} - - ${{ inputs.channel }} - - ${{ inputs.code }} + using: "composite" + steps: + - name: Send Rocket.Chat notification + shell: bash + run: ${{ github.action_path }}/entrypoint.sh + env: + INPUT_USER: ${{ inputs.user }} + INPUT_PASSWORD: ${{ inputs.password }} + INPUT_MESSAGE: ${{ inputs.message }} + INPUT_SERVER: ${{ inputs.server }} + INPUT_CHANNEL: ${{ inputs.channel }} + INPUT_CODE: ${{ inputs.code }} diff --git a/entrypoint.sh b/entrypoint.sh index 2e60697..1d9611d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,49 @@ -#!/usr/bin/env sh -if $6 == "true"; then - rocketchat-notification -u "$1" -p "$2" -m "$3" -s "$4" -c "$5" -code -else - rocketchat-notification -u "$1" -p "$2" -m "$3" -s "$4" -c "$5" +#!/usr/bin/env bash +set -euo pipefail + +GREEN='\033[0;32m' +RED='\033[0;31m' +BOLD='\033[1m' +RESET='\033[0m' + +SERVER="${INPUT_SERVER}" +USER="${INPUT_USER}" +PASSWORD="${INPUT_PASSWORD}" +MESSAGE="${INPUT_MESSAGE}" +CHANNEL="${INPUT_CHANNEL}" + +LOGIN_RESPONSE=$(curl -s -X POST \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg user "$USER" --arg password "$PASSWORD" '{"user": $user, "password": $password}')" \ + "${SERVER}/api/v1/login") + +mapfile -t login_data < <(jq -r '.data.authToken, .data.userId' <<< "$LOGIN_RESPONSE") +AUTH_TOKEN="${login_data[0]}" +USER_ID="${login_data[1]}" + +if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" = "null" ]; then + LOGIN_ERROR=$(jq -r '.message // "unknown error"' <<< "$LOGIN_RESPONSE") + echo -e "${RED}${BOLD}✗ Login failed${RESET} — ${LOGIN_ERROR}" + exit 1 fi + +RESPONSE=$(curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "X-Auth-Token: ${AUTH_TOKEN}" \ + -H "X-User-Id: ${USER_ID}" \ + -d "$(jq -n --arg channel "$CHANNEL" --arg text "$MESSAGE" '{"channel": $channel, "text": $text}')" \ + "${SERVER}/api/v1/chat.postMessage") + +mapfile -t response_data < <(jq -r '.success, .channel, .message.u.username, .message._id' <<< "$RESPONSE") +SUCCESS="${response_data[0]}" +CHANNEL_NAME="${response_data[1]}" +SENDER="${response_data[2]}" +MSG_ID="${response_data[3]}" + +if [ "$SUCCESS" != "true" ]; then + ERROR=$(jq -r '.error // .message // "unknown error"' <<< "$RESPONSE") + echo -e "${RED}${BOLD}✗ Failed to send message${RESET} — ${ERROR}" + exit 1 +fi + +echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}" From ddfa41a9023b3e8584f3999267033a8ba6e35b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Mon, 23 Mar 2026 21:26:00 +0100 Subject: [PATCH 3/4] Logout at the end of the script --- entrypoint.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 1d9611d..5fbe1bc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,3 +47,14 @@ if [ "$SUCCESS" != "true" ]; then fi echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}" + +LOGOUT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ + -H "X-Auth-Token: ${AUTH_TOKEN}" \ + -H "X-User-Id: ${USER_ID}" \ + "${SERVER}/api/v1/logout") || true + +if [ "${LOGOUT_STATUS}" = "200" ]; then + echo -e "${GREEN}✓ Logged out${RESET}" +else + echo -e "${RED}✗ Logout failed${RESET} — HTTP ${LOGOUT_STATUS}" +fi From 1503fe229e82195af04054874939358ecd1bd45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Mon, 23 Mar 2026 21:28:09 +0100 Subject: [PATCH 4/4] Add logged in message --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 5fbe1bc..fa5f1d5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,6 +27,8 @@ if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" = "null" ]; then exit 1 fi +echo -e "${GREEN}✓ Logged in${RESET} — ${USER}@${SERVER}" + RESPONSE=$(curl -s -X POST \ -H "Content-Type: application/json" \ -H "X-Auth-Token: ${AUTH_TOKEN}" \