Skip to content

Commit

Permalink
Automate development chore using single entry script
Browse files Browse the repository at this point in the history
`workflows` script provides capabilities on managing development
routine. It is a single entry point to run any developers command
and is used in CI setup.
In the future, if there is an action which simplifies development, it
must be added to the script.

Any other subscripts are stores within `.workflows` directory. This
cleans root directory and keeps non-production code separated.
  • Loading branch information
extsoft committed Sep 29, 2019
1 parent eb004cc commit c004a3f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Run development pipeline
run: docker run --rm -v $PWD:/eg beeshive/elegant-git-ci:3 ./quality-pipeline.bash testing
run: ./workflows ci
6 changes: 3 additions & 3 deletions .rultor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
architect: extsoft
docker:
image: beeshive/elegant-git-ci:3
image: beeshive/elegant-git-ci:4
as_root: true
merge:
fast-forward: only
rebase: true
script: ./quality-pipeline.bash testing
script: .workflows/ci-pipeline.bash testing
release:
script: |-
./quality-pipeline.bash testing
.workflows/ci-pipeline.bash testing
echo "Release ${tag}"
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: required
language: bash
services: docker
script: docker run -it --rm -v $PWD:/eg beeshive/elegant-git-ci:3 ./quality-pipeline.bash testing
script: ./workflows ci
notifications:
email: false
File renamed without changes.
10 changes: 5 additions & 5 deletions quality-pipeline.bash → .workflows/ci-pipeline.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# This script is destructive! That's why it will work only if a specific variable is set.
# It's recommended to run it within a docker container only.
# Usage:
# ./quality-pipeline.bash runs quality pipeline
# ./quality-pipeline.bash --version prints tooling version
# ./ci-pipeline.bash runs quality pipeline
# ./ci-pipeline.bash --version prints tooling version
set -e

fail() {
Expand All @@ -12,7 +12,7 @@ fail() {
}

pipeline() {
bats --tap tests || fail "Unit tests are failed."
.workflows/bats-pipeline.bash || fail "Unit tests are failed."
(
echo "Installation...."
./install.bash /usr/local src
Expand All @@ -25,10 +25,10 @@ pipeline() {
--exclude=docs/*.png \
--verbose --file=/dev/null || fail "Unreadable todo is identified."
(
./.wf/docs-generation.bash
.workflows/docs-generation.bash
git update-index --refresh
git diff-index --quiet HEAD --
) || fail "The documentation is not up to date. Please run './.wf/docs-generation.bash' and commit the changes"
) || fail "The documentation is not up to date. Please run './.workflows/docs-generation.bash' and commit the changes"

}

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ RUN apk update && \
LABEL maintainer="Dmytro Serdiuk <[email protected]>" \
description="Run the image without arguments to get the desciption." \
version=3
COPY docs/requirements.txt entry.bash /
COPY docs/requirements.txt /
RUN pip install --no-cache -r requirements.txt && rm -r requirements.txt
WORKDIR /eg
ENV EG_ENABLE_TESTING true
CMD ["./quality-pipeline.bash", "--version"]
CMD [".workflows/ci-pipeline.bash", "--version"]
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ something which should be quickly available, please propose changes here.
The structure of directories:
```text
.
├── bin <- stores executable which is entry point
├── completions <- stores completion files
├── docs <- stores user documentation
├── libexec <- contains all commands
└── tests <- stores all tests along with additional test libraries
├── .workflows/ <- stores development scripts
├── bin/ <- stores executable which is entry point
├── completions/ <- stores completion files
├── docs/ <- stores user documentation
├── libexec/ <- contains all commands
├── tests/ <- stores all tests along with additional test libraries
└── workflows <- executes different development tasks
```

When you run `git elegant ...`, it initiates `bin/git-elegant` entry-point script. It calls
Expand Down Expand Up @@ -100,14 +102,13 @@ A testing procedure consists of 3 steps:
3. validation of documentation correctness
4. validation of todo' correctness (for [0pdd](http://www.0pdd.com/p?name=bees-hive/elegant-git))

All these steps can be executed by
`docker run -it --rm -v $PWD:/eg beeshive/elegant-git-ci:3 ./quality-pipeline.bash testing`.
All these steps can be executed by `./workflows ci` which runs a Docker container (based on
`beeshive/elegant-git-ci` image) and calls all described checks. The image is also used on CI.
If the image requires modifications, then

`beeshive/elegant-git-ci` Docker image is also used on CI. If the image requires modifications,
it has to be updated manually by the following instructions:
1. update `Dockerfile` (including `version` and `description`)
2. `docker build -t beeshive/elegant-git-ci:<version> .`
3. `docker push beeshive/elegant-git-ci:<version>`
1. run `./workflows prepare-worker <new tag>` to build a new image
2. update `WORKER_IMAGE` in `./workflows` and test some workflow
3. run `./workflows publich-worker <new tag>` to push the image

### Unit testing
#### Addons
Expand Down Expand Up @@ -143,5 +144,5 @@ In order to get the documentation preview locally, please install required depen
`pip install -r docs/requirements.txt`. After, run `mkdocs serve` and open <http://127.0.0.1:8000/>
in a browser. That's it!

The [docs/commands.md](docs/commands.md) generates by running `./.wf/docs-generation.bash` script.
The [docs/commands.md](docs/commands.md) generates by running `./workflows documentation` script.
All other files in ["docs" directory](docs/) require manual corrections.
69 changes: 64 additions & 5 deletions workflows
Original file line number Diff line number Diff line change
@@ -1,32 +1,91 @@
#!/usr/bin/env bash
set -ex
set -e

source ./libexec/plugins/text

WORKER_IMAGE="beeshive/elegant-git-ci:4"

testing() {
docker run -it --rm -v $PWD:/eg beeshive/elegant-git-ci:3 ./.wf/tests-execution.bash $@
docker run -it --rm -v $PWD:/eg ${WORKER_IMAGE} .workflows/bats-pipeline.bash "$@"
}

documentation() {
.workflows/docs-generation.bash
}

repository() {
docker run -idt --rm --name repository --workdir /tmp/elegant-git-repo -v $PWD:/eg beeshive/elegant-git-ci:3 bash
info-text "Start container..."
docker run -idt --rm --name repository --workdir /tmp/elegant-git-repo -v $PWD:/eg ${WORKER_IMAGE} bash
info-text "Init repository..."
docker exec -it repository bash -c "source /eg/tests/addons-git.bash;source /eg/tests/addons-common.bash; init-repo"
info-text "Install Elegant Git..."
docker exec -it repository bash -c "cd /eg; ./install.bash /usr/local src"
info-text "Ready! Enjoy experiments..."
docker attach repository
}

ci() {
docker run --rm -v $PWD:/eg ${WORKER_IMAGE} .workflows/ci-pipeline.bash testing
}

prepare-worker() {
if [[ -z ${1} ]]; then
error-text "Please specify a tag for Docker image (like '2')"
fi
docker build --no-cache -t beeshive/elegant-git-ci:${1} .
}

publish-worker() {
if [[ -z ${1} ]]; then
error-text "Please specify a tag for Docker image (like '2')"
fi
docker push beeshive/elegant-git-ci:${1}
}

usage() {
cat <<MESSAGE
usage: ${BASH_SOURCE[0]} [command] [arg]...
Available commands:
help prints this message
testing runs bats tests; accepts a optional pattern for tests
filtering ("${BASH_SOURCE[0]} testing work" run all tests
which have the word in the test name)
repository creates a git repository and installs Elegant Git within
documentation generates fresh commands documentation bases on the latest
changes
ci runs CI quality assessment workflow
prepare-worker builds a new worker image
publish-worker pushes a new worker image
MESSAGE
}

commands=(
usage
testing
repository
documentation
ci
prepare-worker
publish-worker
)

main() {
local command=${1}
if [[ -z "${command}" ]]; then
if [[ -z ${command} ]]; then
question-text "Please select a command:"
echo ""
select any in ${commands[@]}; do
command=${any}
question-text "Please give the arguments: "
read args
break
done
else
shift
fi
${command} ${@}
info-box "Run:" ${command} ${args:-${@}}
${command} ${args:-${@}}
}

main ${@}

0 comments on commit c004a3f

Please sign in to comment.