Skip to content

Updates for recent Hubot #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
87 changes: 87 additions & 0 deletions .github/workflows/hubot-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This workflow will create a new Hubot, install dependencies, and connect to a Matrix server.
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Hubot demo (e2e)

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 5

env:
HUBOT_ADAPTER: 'hubot-matrix'
HUBOT_FAREWELL_ENABLED: true
HUBOT_FAREWELL_MESSAGE: "Goodbye from GHA Hubot demo"
HUBOT_FAREWELL_TARGET: ${{ secrets.TEST_MATRIX_ROOM }}
HUBOT_FAREWELL_TIMEIN: 5000
HUBOT_FAREWELL_TIMEOUT: 30000
# HUBOT_LOG_LEVEL: debug
HUBOT_NAME: 'HubotMatrixTest'
HUBOT_MATRIX_HOST: ${{ secrets.TEST_MATRIX_URL }}
HUBOT_MATRIX_PASSWORD: ${{ secrets.TEST_MATRIX_PASSWORD }}
HUBOT_MATRIX_USER: ${{ secrets.TEST_MATRIX_USER }}
HUBOT_STARTUP_MESSAGE: "Hello from GHA Hubot demo"
HUBOT_STARTUP_ROOM: ${{ secrets.TEST_MATRIX_ROOM }}
# LOG_LEVEL: debug

steps:
- uses: actions/checkout@v2
- name: Use Node.js v22
uses: actions/setup-node@v1
with:
node-version: '22.x'
- name: Configure env vars
run: |
# echo "HUBOT_NAME=Github E2E $GITHUB_RUN_ID" >> $GITHUB_ENV
echo "GHA_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: NPM CI
run: npm ci
- name: NPM link
run: npm link
- name: Configure env vars
run: |
echo "ADAPTER_DIR=$( pwd )" >> $GITHUB_ENV
echo "HUBOT_DIR=$( pwd )/node_modules/hubot" >> $GITHUB_ENV
echo "HUBOT_ROOT=$( mktemp -d )" >> $GITHUB_ENV
- name: Create and configure Hubot instance
run: |
npx hubot --create $HUBOT_ROOT
cd $HUBOT_ROOT
mkdir -p configuration src/scripts # silence warnings
echo "Creating Hubot for this adapter in $TEMP_ROOT and installing Hubot from $HUBOT_DIR"
npm install --save github:xurizaemon/hubot-matrix#update-esm github:xurizaemon/hubot-farewell github:xurizaemon/hubot-startup
npm show matrix-js-sdk
echo '["@xurizaemon/hubot-farewell", "@xurizaemon/hubot-startup"]' > external-scripts.json
echo "PATH=$PATH:$( pwd )/node_modules/.bin" >> $GITHUB_ENV
echo "HUBOT_INSTALLATION_PATH=$TEMP_ROOT" >> $GITHUB_ENV
echo "NODE_PATH=$TEMP_ROOT/node_modules" >> $GITHUB_ENV
echo "PATH=$PATH:$TEMP_ROOT/node_modules/.bin" >> $GITHUB_ENV
cat package.json
- name: Start Hubot, let plugins say hello & goodbye
run: |
cd $HUBOT_ROOT
echo "First run, initialise local storage"
PATH=$PATH:$( pwd )/node_modules/.bin
echo
echo "Second run"
# Log in and save creds to local storage, then exit.
HUBOT_FAREWELL_TIMEOUT=15000 hubot
# Reconnect with saved creds from local storage.
hubot

- name: Preserve artifacts
run: |
mkdir tmp
cp -v $HUBOT_ROOT/package-lock.json tmp/
- name: Upload package-lock.json
uses: actions/upload-artifact@v4
with:
name: package-lock-json
path: tmp/package-lock.json
21 changes: 17 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -13,17 +13,30 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: NPM CI
run: npm ci
- name: NPM run build
run: npm run build --if-present
- name: Unit tests
run: npm run test:unit
- name: Integration Tests
if: ${{ github.event_name == 'pull_request' }}
env:
TEST_MATRIX_USER: ${{ secrets.TEST_MATRIX_USER }}
TEST_MATRIX_PASSWORD: ${{ secrets.TEST_MATRIX_PASSWORD }}
TEST_MATRIX_ROOM: ${{ secrets.TEST_MATRIX_ROOM }}
TEST_MATRIX_URL: ${{ secrets.TEST_MATRIX_URL }}
TEST_ROOM_ID: ${{ secrets.TEST_ROOM_ID }}
run: npm run test:integration
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
.env
.hubot_history
*.iml
.idea
node_modules
# Local storage may be created.
hubot-matrix.localStorage
integration-test.localStorage
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,20 +4,49 @@ This is a [Hubot](https://hubot.github.com) adapter for [Matrix](https://matrix.

## Installation

Use the version of this adapter appropriate to your Hubot version.
Use the following adapter based on your Hubot version (`npm list hubot`).

* For Hubot v2, `npm i hubot-matrix@1`
* For Hubot v3, `npm i hubot-matrix@2`

| **hubot** | **hubot-matrix** |
|----|----|
| v2 | v1 |
| v3 | v2 |
* For Hubot v13+, `npm i @xurizaemon/hubot-matrix`

## Adapter configuration

Set the following variables:

* `HUBOT_ADAPTER` should be `hubot-matrix`
* `HUBOT_MATRIX_HOST_SERVER` - the Matrix server to connect to (default is `https://matrix.org` if unset)
* `HUBOT_MATRIX_USER` - bot login on the Matrix server - eg `@examplebotname:matrix.example.org`
* `HUBOT_MATRIX_PASSWORD` - bot password on the Matrix server

## Tests

To run tests in Github Actions, the following **Github Secrets** should be configured.

| Name | Example | Description |
|------------------------|----------------------------------|---------------------------|
| `TEST_MATRIX_URL` | https://matrix-client.matrix.org | Home instance URL |
| `TEST_MATRIX_ROOM` | `!something@example.org` | Room ID (where to get it) |
| `TEST_MATRIX_USER` | @someuser:example.org | Username |
| `TEST_MATRIX_PASSWORD` | **** | Password |

There are environment variables which the tests need set to execute also. In Github Actions,
these variables are set in the Github workflow configuration (`.github/workflows/*.yml`).

| Name | Example | Description |
|-------------------------|----------------------------------|----------------------------|
| `HUBOT_MATRIX_HOST` | https://matrix-client.matrix.org | Home instance URL |
| `HUBOT_MATRIX_PASSWORD` | **** | Test user a/c password. |
| `HUBOT_MATRIX_USERNAME` | **** | Test user a/c login. |
| `HUBOT_FAREWELL_*` | Configure `hubot-farewell`[^1] | Configure shutdown message |
| `HUBOT_STARTUP_*` | Configure `hubot-startup`[^2] | Configure startup message |

Jest requires the experimental-vm-modules Node option to run .mjs tests:

```shell
NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npm run test
```

[^1]: https://github.com/xurizaemon/hubot-farewell/

[^2]: https://github.com/xurizaemon/hubot-startup/
16 changes: 16 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Polyfill in some Node crypto for tests only.
import { TextEncoder, TextDecoder } from 'util'
import crypto from 'crypto'

// Add TextEncoder and TextDecoder to global
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder

// Add crypto to global
if (typeof global.crypto === 'undefined') {
global.crypto = {
getRandomValues: function (array) {
return crypto.randomBytes(array.length).copy(array)
}
}
}
10 changes: 10 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"testMatch": [
"**/*.test.mjs"
],
"testTimeout": 30000,
"detectOpenHandles": true,
"setupFiles": [
"./jest-setup.js"
]
}
Loading