Skip to content

Commit

Permalink
feat: Generate a Hubot instance (#1668)
Browse files Browse the repository at this point in the history
* feat: Generate a Hubot instance via npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
* feat: add example script and instructions
* chore: only run release on main
* chore: update e2e test to use new hubot gen facility
* chore: add e2e test job
  • Loading branch information
joeyguerra committed Oct 1, 2023
1 parent a4219a0 commit 9fb0a34
Show file tree
Hide file tree
Showing 9 changed files with 2,660 additions and 9,222 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/nodejs-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Node.js (Ubuntu) CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '5 4 * * 0'

Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Build and release pipeline
on:
push:
branches:
- main
- next
pull_request:
branches:
- main
- next
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
jobs:
build:
name: Build and Verify
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18.x
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures
test:
name: Fast Tests
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
node-version:
- 18.x
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
e2etest:
name: E2E Test
needs:
- build
- test
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18.x
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install expect
run: sudo apt-get install expect
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test:e2e
release:
name: Release
if: github.ref == 'refs/heads/main' && success()
needs: [build, test, e2etest]
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18.x
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
41 changes: 0 additions & 41 deletions .github/workflows/release.yml

This file was deleted.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ for details on getting up and running with your very own robot friend.
In most cases, you'll probably never have to hack on this repo directly if you
are building your own bot. But if you do, check out [CONTRIBUTING.md](CONTRIBUTING.md)

# Create your own Hubot instance

```sh
mkdir myhubot
cd myhubot
npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
```

Review `scripts/example.mjs`. Create more scripts in the `scripts` folder.

## License

See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
28 changes: 17 additions & 11 deletions bin/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ trap "{ CODE=$?; popd; rm -rf $TEMP_ROOT; exit $CODE; }" EXIT

## https://github.com/hubotio/hubot/blob/main/docs/index.md

## use hubot from last commit
echo "$ npm install $HUBOT_FOLDER"
npm install $HUBOT_FOLDER coffeescript hubot-diagnostics
cat <<EOF > external-scripts.json
["hubot-diagnostics"]
EOF
## use this hubot version
echo "$ create hubot in $TEMP_ROOT"
echo "$ install Hubot from $HUBOT_FOLDER"
npm init -y
npm i $HUBOT_FOLDER coffeescript

mkdir -p $TEMP_ROOT/scripts
cp $HUBOT_FOLDER/test/fixtures/TestScript.mjs $TEMP_ROOT/scripts/
./node_modules/.bin/hubot --create myhubot
cd myhubot

# npm install /path/to/hubot will create a symlink in npm 5+ (http://blog.npmjs.org/post/161081169345/v500).
# As the require calls for app-specific scripts happen inside hubot, we have to
# set NODE_PATH to the app’s node_modules path so they can be found
echo "$ NODE_PATH=$HUBOT_FOLDER/node_modules:$TEMP_ROOT/node_modules"
export NODE_PATH=$NODE_PATH/$HUBOT_FOLDER/node_modules:$TEMP_ROOT/node_modules
export PATH=$PATH:$TEMP_ROOT/node_modules/.bin
echo "$ Update NODE_PATH=$TEMP_ROOT/node_modules so everything can be found correctly."
export NODE_PATH=$TEMP_ROOT/node_modules:$TEMP_ROOT/myhubot/node_modules
export PATH=$PATH:$TEMP_ROOT/node_modules/.bin:$TEMP_ROOT/myhubot/node_modules/.bin
export HUBOT_INSTALLATION_PATH=$HUBOT_FOLDER
echo $HUBOT_INSTALLATION_PATH

## start, but have to sleep 1 second to wait for hubot to start and the scripts to load
expect <<EOL
Expand All @@ -36,4 +37,9 @@ expect <<EOL
"PONG" {}
timeout {exit 1}
}
send "e2etest adapter\r"
expect {
"shell" {}
timeout {exit 1}
}
EOL
12 changes: 5 additions & 7 deletions bin/hubot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const pathResolve = require('path').resolve
const OptParse = require('optparse')

const Hubot = require('..')
const create = require('../src/GenHubot.js')

const switches = [
['-a', '--adapter HUBOT_ADAPTER', 'The Adapter to use, e.g. "shell" (to load the default hubot shell adapter)'],
Expand Down Expand Up @@ -86,14 +87,11 @@ Parser.on((opt, value) => {
Parser.parse(process.argv)

if (options.create) {
console.error("'hubot --create' is deprecated. Use the yeoman generator instead:")
console.error(' npm install -g yo generator-hubot')
console.error(` mkdir -p ${options.path}`)
console.error(` cd ${options.path}`)
console.error(' yo hubot')
console.error('See https://github.com/github/hubot/blob/main/docs/index.md for more details on getting started.')
process.exit(1)
options.hubotInstallationPath = process.env.HUBOT_INSTALLATION_PATH ?? 'hubot'
create(options.path, options)
process.exit(0)
}

if (options.file) {
options.adapter = options.file.split('/').pop().split('.')[0]
}
Expand Down

0 comments on commit 9fb0a34

Please sign in to comment.