Skip to content

Commit 9fb0a34

Browse files
authored
feat: Generate a Hubot instance (#1668)
* 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
1 parent a4219a0 commit 9fb0a34

File tree

9 files changed

+2660
-9222
lines changed

9 files changed

+2660
-9222
lines changed

.github/workflows/nodejs-ubuntu.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Node.js (Ubuntu) CI
33
on:
44
push:
55
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
86
schedule:
97
- cron: '5 4 * * 0'
108

.github/workflows/pipeline.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build and release pipeline
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- next
7+
pull_request:
8+
branches:
9+
- main
10+
- next
11+
permissions:
12+
contents: write
13+
issues: write
14+
pull-requests: write
15+
id-token: write
16+
jobs:
17+
build:
18+
name: Build and Verify
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
node-version:
23+
- 18.x
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
- name: Setup Node.js ${{ matrix.node-version }}
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: ${{ matrix.node-version }}
33+
cache: 'npm'
34+
- name: Install dependencies
35+
run: npm ci
36+
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
37+
run: npm audit signatures
38+
test:
39+
name: Fast Tests
40+
runs-on: ubuntu-latest
41+
needs: build
42+
strategy:
43+
matrix:
44+
node-version:
45+
- 18.x
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v3
49+
with:
50+
fetch-depth: 0
51+
- name: Use Node.js ${{ matrix.node-version }}
52+
uses: actions/setup-node@v3
53+
with:
54+
node-version: ${{ matrix.node-version }}
55+
cache: 'npm'
56+
- run: npm ci
57+
- run: npm test
58+
e2etest:
59+
name: E2E Test
60+
needs:
61+
- build
62+
- test
63+
runs-on: ubuntu-latest
64+
strategy:
65+
matrix:
66+
node-version:
67+
- 18.x
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v3
71+
with:
72+
fetch-depth: 0
73+
- name: Install expect
74+
run: sudo apt-get install expect
75+
- name: Setup Node.js ${{ matrix.node-version }}
76+
uses: actions/setup-node@v3
77+
with:
78+
node-version: ${{ matrix.node-version }}
79+
cache: 'npm'
80+
- run: npm ci
81+
- run: npm run test:e2e
82+
release:
83+
name: Release
84+
if: github.ref == 'refs/heads/main' && success()
85+
needs: [build, test, e2etest]
86+
runs-on: ubuntu-latest
87+
strategy:
88+
matrix:
89+
node-version:
90+
- 18.x
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v3
94+
- name: Semantic Release
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
98+
run: npx semantic-release

.github/workflows/release.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

README.md

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

18+
# Create your own Hubot instance
19+
20+
```sh
21+
mkdir myhubot
22+
cd myhubot
23+
npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
24+
```
25+
26+
Review `scripts/example.mjs`. Create more scripts in the `scripts` folder.
27+
1828
## License
1929

2030
See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).

bin/e2e-test.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ trap "{ CODE=$?; popd; rm -rf $TEMP_ROOT; exit $CODE; }" EXIT
88

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

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

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

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

2829
## start, but have to sleep 1 second to wait for hubot to start and the scripts to load
2930
expect <<EOL
@@ -36,4 +37,9 @@ expect <<EOL
3637
"PONG" {}
3738
timeout {exit 1}
3839
}
40+
send "e2etest adapter\r"
41+
expect {
42+
"shell" {}
43+
timeout {exit 1}
44+
}
3945
EOL

bin/hubot.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const pathResolve = require('path').resolve
66
const OptParse = require('optparse')
77

88
const Hubot = require('..')
9+
const create = require('../src/GenHubot.js')
910

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

8889
if (options.create) {
89-
console.error("'hubot --create' is deprecated. Use the yeoman generator instead:")
90-
console.error(' npm install -g yo generator-hubot')
91-
console.error(` mkdir -p ${options.path}`)
92-
console.error(` cd ${options.path}`)
93-
console.error(' yo hubot')
94-
console.error('See https://github.com/github/hubot/blob/main/docs/index.md for more details on getting started.')
95-
process.exit(1)
90+
options.hubotInstallationPath = process.env.HUBOT_INSTALLATION_PATH ?? 'hubot'
91+
create(options.path, options)
92+
process.exit(0)
9693
}
94+
9795
if (options.file) {
9896
options.adapter = options.file.split('/').pop().split('.')[0]
9997
}

0 commit comments

Comments
 (0)