telegram-bot-bash/doc/7_develop.md

122 lines
5.7 KiB
Markdown
Raw Normal View History

2019-04-19 11:01:25 +00:00
#### [Home](../README.md)
## Notes for bashbot developers
2019-04-27 21:15:05 +00:00
This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.
2019-04-19 11:01:25 +00:00
2019-04-19 12:07:01 +00:00
bashbot development is done on github. If you want to provide fixes or new features [fork bashbot on githup](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request).
2019-04-19 11:01:25 +00:00
### Setup your develop environment
1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck)
2. setup your [environment for UTF-8](4_expert.md#Setting-up-your-Environment)
2019-04-19 12:07:01 +00:00
3. clone your bashbot fork to a new directory ```git clone https://github.com/<YOURNAME>/telegram-bot-bash.git```, replace ```<YOURNAME>``` with your username on github
4. create and change to your develop branch ```git checkout -b <YOURBRANCH>```, replace ```<YOURBRANCH>``` with the name you want to name it, e.g. 'develop'
2019-05-01 10:37:18 +00:00
5. give your (dev) fork a new version tag: ```git tag vx.xx```(optional)
2019-04-19 11:01:25 +00:00
6. setup github hooks by running ```dev/install-hooks.sh``` (optional)
2019-04-26 09:17:42 +00:00
### Test, Add, Push changes
2019-04-26 15:40:24 +00:00
A typical bashbot develop loop looks as follow:
2019-04-26 09:17:42 +00:00
2019-04-26 11:19:34 +00:00
1. start developing - *change, copy, edit bashbot files ...*
2019-04-27 21:15:05 +00:00
2. after changing a bash sript: ```shellcheck -x scipt.sh```
2019-04-26 11:19:34 +00:00
3. ```dev/all-tests.sh``` - *in case if errors back to 2.*
4. ```dev/git-add.sh``` - *check for changed files, update version string, run git add*
2019-05-01 10:37:18 +00:00
5. ```git commit -m "COMMIT MESSAGE"; git push```
2019-04-26 09:17:42 +00:00
2019-05-01 10:37:18 +00:00
**If you setup your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.**
2019-04-26 09:17:42 +00:00
2019-04-26 15:40:24 +00:00
### Prepare a new version
After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or
a new release version for new features. To mark a new version use ```git tag NEWVERSION``` and run ```dev/version.sh``` to update all version strings.
2019-04-27 11:02:10 +00:00
Usually I start with pre versions and when everything looks good I push out a release candidate (rc) and finally the new version.
2019-04-26 15:40:24 +00:00
```
2019-04-27 11:02:10 +00:00
v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x ... 0.x+1-dev ...
2019-04-26 15:40:24 +00:00
```
2019-04-19 11:01:25 +00:00
### Versioning
2019-05-01 10:37:18 +00:00
Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version.
2019-04-19 12:07:01 +00:00
E.g. if you fork 'v0.60' the next develop version should tagged as ```git tag "v0.61-dev"``` for fixes or ```git tag "v0.70-dev"``` for new features.
2019-04-19 11:01:25 +00:00
2019-04-19 12:07:01 +00:00
To get the current version name of your develepment fork run ```git describe --tags```. The output looks like ```v0.70-dev-6-g3fb7796``` where your version tag is followed by the number of commits since you tag your branch and followed by the latest commit hash. see also [comments in version.sh](../dev/version.sh)
2019-04-19 11:01:25 +00:00
2019-05-01 10:37:18 +00:00
To update the Version Number in files run ```dev/version.sh files```, it will update the line '#### $$VERSION$$ ###' in all files to the current version name.
To update version in all files run 'dev/version.sh' without parameter.
2019-04-19 11:01:25 +00:00
2019-05-01 10:37:18 +00:00
### Shellcheck
2019-04-19 11:01:25 +00:00
2019-04-19 12:07:01 +00:00
For a shell script running as a service it's important to be paranoid about quoting, globbing and other common problems. So it's a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.
2019-04-19 11:01:25 +00:00
2019-05-01 10:37:18 +00:00
To run shellcheck for a single script run ```shellcheck -x script.sh```, to check all schripts run ```dev/hooks/pre-commit.sh```.
2019-04-19 11:01:25 +00:00
2019-04-19 15:31:01 +00:00
## bashbot tests
2019-04-26 09:17:42 +00:00
Starting with version 0.70 bashbot has a test suite. To start testsuite run ```dev/all-tests.sh```. all-tests.sh will return 'SUCCESS' only if all tests pass.
2019-04-19 15:31:01 +00:00
### enabling / disabling tests
2019-05-01 10:37:18 +00:00
All tests are placed in the directory ```test```. To disable a test remove the execute flag from the '*-test.sh' script, to (re)enable a test make the script executable again.
2019-04-19 15:31:01 +00:00
### creating new tests
2019-05-01 10:37:18 +00:00
To create a new test run ```test/ADD-test-new.sh``` and answer the questions, it will create the usually needed files and dirs:
2019-04-26 09:17:42 +00:00
2019-05-01 10:37:18 +00:00
Each test consists of a script script named after ```p-name-test.sh``` *(where p is test pass 'a-z' and name the name
2019-04-26 09:17:42 +00:00
of your test)* and an optional dir ```p-name-test/``` *(script name minus '.sh')* for additional files.
2019-04-20 17:42:38 +00:00
Tests with no dependency to other tests will run in pass 'a', tests which need an initialized bahsbot environment must run in pass 'd' or later.
2019-05-01 10:37:18 +00:00
A temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished.
The file ```ALL-tests.inc.sh``` must be included from all tests and provide the test environment as shell variables:
```bash
# Test Evironment
TESTME="$(basename "$0")"
DIRME="$(pwd)"
TESTDIR="$1"
LOGFILE="${TESTDIR}/${TESTME}.log"
REFDIR="${TESTME%.sh}"
TESTNAME="${REFDIR//-/ }"
# common filenames
TOKENFILE="token"
ACLFILE="botacl"
COUNTFILE="count"
ADMINFILE="botadmin"
DATADIR="data-bot-bash"
# SUCCESS NOSUCCES -> echo "${SUCCESS}" or echo "${NOSUCCESS}"
SUCCESS=" OK"
NOSUCCESS=" FAILED!"
# default input, reference and output files
INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input"
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
```
2019-04-19 15:31:01 +00:00
Example test
```bash
#!/usr/bin/env bash
# file: b-example-test.sh
2019-04-19 15:31:01 +00:00
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
source "./ALL-tests.inc.sh"
2019-04-19 15:31:01 +00:00
2019-05-01 10:37:18 +00:00
if [ -f "${TESTDIR}/bashbot.sh" ]; then
echo "${SUCCESS} bashbot.sh exist!"
2019-04-19 15:31:01 +00:00
exit 0
else
2019-05-01 10:37:18 +00:00
echo "${NOSUCCESS} ${TESTDIR}/bashbot.sh missing!"
2019-04-19 15:31:01 +00:00
exit 1
fi
```
2019-04-30 12:21:24 +00:00
#### [Prev Function Reference](6_reference.md)
2019-04-23 09:45:03 +00:00
#### [Next Bashbot Environment](8_custom.md)
2019-04-19 11:01:25 +00:00
2019-05-02 10:33:10 +00:00
#### $$VERSION$$ v0.80-dev-2-g4e4194d
2019-04-19 11:01:25 +00:00