Skip to content

Commit

Permalink
feat(puml): add svg render git commit hooks (#278)
Browse files Browse the repository at this point in the history
* Add initial hackathon reference docs

* feat(svg): add svg rendering scripts and notes

* feat(svg): add circleci config for `test-svg` step

* chore(scripts): cleanup

* chore(scripts): fix ci/cd

* chore(scripts): fix ci/cd

* chore(scripts): fix ci/cd

* feat(ci/cd): fix missing openjdk11 dep

* feat(ci/cd): fix ci/cd

* feat(ci/cd): fix bad reference to ./docs

* feat(ci/cd): fix cache issues

* feat(ci/cd): fix cache issues

* feat(ci/cd): work on test-svg false negative

* feat(svg): add rendered svgs

* feat(svg): remove node_modules from find list

* fix(package): add back missing npm scripts

* Update stale link for mojaloop docs (#281)

* Updated mojaloop helm repo from http to https (#280)

* Create personas.md (#282)

* Update personas.md (#283)

added additional context for personas

* feat(puml): switch to npx to run puml command

* feat(puml): change from local puml rendering to
  server based approach, with a local docker puml server

feat(puml): working on deterministic .svg rendering

feat(puml): working on deterministic .svg rendering

feat(puml): pretty print svgs for better git diffing

feat(puml): rerender some svgs, see if better diffing

feat(puml): add file count to echo comment

feat(puml): add file count to echo comment

feat(puml): make build all build just 1 for debugging

feat(puml): add graphviz, does this fix rendering?

feat(puml): going crazy trying to fix empty diagrams!

feat(puml): using server renderer

feat(puml): using server renderer

feat(puml): update test diagram

feat(puml): update render all

feat(puml): add http error handling

feat(puml): improve error messages

feat(puml): checking final rendering

feat(puml): testing deterministic rendering

feat(puml): add docker run steps

feat(puml): changes for docker puml

feat(ci/cd): update svg check to use docker

feat(ci/cd): update svg check to use docker

feat(puml): add docker run steps

fix(puml): wrong url is parsed by ci/cd

feat(puml): cleanup url, make notes about svg determinism

* fix(ci/cd): broken build step

* fix(ci/cd): broken build step

* fix(ci/cd): broken build step

* chore(docs): remove debug notes

Co-authored-by: Jishnu Mohan <mohanjishnu@gmail.com>
Co-authored-by: Miguel de Barros <miguel@debarros.me>
Co-authored-by: Kimberly Walters <kimw@crosslaketech.com>
  • Loading branch information
4 people authored Dec 9, 2020
1 parent d3975b3 commit 43c018d
Show file tree
Hide file tree
Showing 126 changed files with 54,113 additions and 426 deletions.
114 changes: 86 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# CircleCI v2 Config
version: 2
# CircleCI v2.1 Config
version: 2.1

defaults_working_directory: &defaults_working_directory
working_directory: /home/circleci/project

defaults_docker_node: &defaults_docker_node
docker:
- image: node:10.15-alpine
##
# orbs
#
# Orbs used in this pipeline
##
orbs:
slack: circleci/slack@3.4.2

##
# defaults
#
# YAML defaults templates, in alphabetical order
##
defaults_Dependencies: &defaults_Dependencies
name: Install default dependencies
command: |
apk --no-cache add git
apk --no-cache add ca-certificates
apk --no-cache add curl
apk --no-cache add openssh-client
# for node 10.15-alpine, need to install from edge repo
apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
apk --no-cache add graphviz
apk add --no-cache -t build-dependencies make gcc g++ python libtool autoconf automake
npm config set unsafe-perm true
npm install -g gitbook-cli
defaults_Environment: &defaults_environment
name: Set default environment
command: |
echo "Nothing to do here right now...move along!"
defaults_slack_announcement: &defaults_slack_announcement
name: Slack announcement for tag releases
Expand Down Expand Up @@ -75,40 +80,53 @@ defaults_publish_to_gh_pages: &defaults_publish_to_gh_pages
echo "Publishing $GITHUB_TAG release to $GITBOOK_TARGET_BRANCH on github..."
git push -q $GITHUB_PROJECT_USERNAME $GITBOOK_TARGET_BRANCH &> git.log
##
# Executors
#
# CircleCI Executors
##
executors:
default-docker:
working_directory: /home/circleci/project
docker:
- image: node:10.15-alpine

default-machine:
machine:
image: ubuntu-1604:201903-01

##
# Jobs
#
# A map of CircleCI jobs
##
jobs:
setup:
<<: *defaults_working_directory
<<: *defaults_docker_node
executor: default-docker
steps:
- checkout
- run:
<<: *defaults_Dependencies
- run:
<<: *defaults_environment
- run:
name: Access npm folder as root
command: cd $(npm root -g)/npm
- run:
name: Update NPM install
command: npm install
command: npm ci
- run:
name: Delete build dependencies
command: apk del build-dependencies
- save_cache:
key: dependency-cache-{{ .Revision }}
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- node_modules

build:
<<: *defaults_working_directory
<<: *defaults_docker_node
executor: default-docker
steps:
- checkout
- run:
<<: *defaults_Dependencies
- run:
<<: *defaults_environment
- run:
name: Installing build dependencies
command: |
Expand All @@ -123,25 +141,49 @@ jobs:
curl -L https://sourceforge.net/projects/plantuml/files/plantuml.${PLANTUML_VERSION}.jar/download -o plantuml.jar
- restore_cache:
keys:
- dependency-cache-{{ .Revision }}
- dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Build Gitbooks
command: |
npm run gitbook:build
- save_cache:
key: build-cache-{{ .Revision }}
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- _book

test-svg:
executor: default-machine
steps:
- checkout
- run:
name: Set up NVM
command: |
echo ${NVM_DIR}
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install v10.15.3
nvm alias default v10.15.3
node --version
npm ci
- run:
name: Check if plantuml has been updated correctly
command: |
set +o pipefail
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
npm run build:plantuml:all
FILE_COUNT=$(git diff --name-only | grep .svg | wc -l)
if [ ${FILE_COUNT} -ne "0" ]; then
echo "${FILE_COUNT} plantuml files are out of sync. Please run npm run build:plantuml and try again.";
exit 1;
else
echo 'Plantuml files are up to date';
fi
deploy:
<<: *defaults_working_directory
<<: *defaults_docker_node
executor: default-docker
steps:
- checkout
- run:
<<: *defaults_Dependencies
- run:
<<: *defaults_environment
- run:
name: setup environment vars
command: |
Expand All @@ -162,6 +204,11 @@ jobs:
- run:
<<: *defaults_slack_announcement

##
# Workflows
#
# CircleCI Workflow config
##
workflows:
version: 2
build_and_test:
Expand All @@ -176,6 +223,17 @@ workflows:
- /feature.*/
- /bugfix.*/
- gh-pages
- test-svg:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- build:
context: org-global
requires:
Expand Down
51 changes: 51 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Documentation Notes

Helpers and notes for building and working on these docs.


## Building `.svg`s from plantuml sources

We use a git commit hook to automatically rebuild `.svg` files from plantuml
sources. The magic of git hooks means that no extra work is required by you
after creating or editing a `.puml` file

Behind the scenes, this hook spins up a docker container to run the PUML server
and calls `./scripts/_render_svg.js` for each file that has changed. We use the
docker version instead of the public puml server to (1) get around rate limits, and
(2) ensure deterministic SVG output that is git diffable.

### Creating a new PUML

1. Create a new `*.puml/plantuml` file
2. Add the file and generate the `.svg`

```bash
git add . #(or the specific file you are working on)
npm run build:plantuml:diff
```
3. Update your `.md` file to refer to the newly created `.svg` file
4. Git add/commit
### Updating an existing PUML

1. Make changes to an existing `*.puml/plantuml` file
2. `git add` + `git commit`
3. The pre-commit hook rebuilds the changed SVG files, and adds them before the commit

### Building all `.puml` sources manually

You can also force a complete rebuild of all `.puml` and `.plantuml` sources like so:

```bash
npm install
npm run build:plantuml:all
```

### `test-svg` CI/CD Step

This is a ci/cd step that ensures that the `.svg` files have been updated
correctly, just in case something got out of sync on your branch before
merging a pull request.

It runs `npm run build:plantuml:all` to build all of the plantuml sources
and if it detects file changes, it means something went wrong with the
commit hook (or you skipped it with `git commit -n`).
Loading

0 comments on commit 43c018d

Please sign in to comment.