Skip to content

Commit

Permalink
global command "pipeline-mermaid"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Novikov committed Jan 30, 2021
1 parent 57a75d9 commit 6c45219
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
20 changes: 10 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stages:
- deploy

variables:
DOCKER_IMAGE_VERSION: 1
PROJECT_VERSION: 0.4

build docker:
stage: docker
Expand All @@ -15,7 +15,7 @@ build docker:
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_VERSION
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$PROJECT_VERSION --build-arg PROJECT_VERSION=$PROJECT_VERSION
only:
changes:
- Dockerfile
Expand All @@ -25,8 +25,9 @@ build docker:
unit tests:
stage: test
tags: [gitlab-org-docker]
image: $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_VERSION
image: python:3-slim
script:
- pip install --no-cache-dir -r requirements.txt
- coverage run --source pipeline_mermaid -m unittest discover tests "*test*"
- coverage xml # for merge request
- coverage html # for pages
Expand All @@ -41,7 +42,7 @@ unit tests:

build package:
tags: [ gitlab-org-docker ]
image: $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_VERSION
image: python:3-slim
stage: build
script:
- python setup.py sdist bdist_wheel
Expand All @@ -67,13 +68,12 @@ pages:
notify merge request:
stage: deploy
tags: [ gitlab-org-docker ]
image: $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_VERSION
image: $CI_REGISTRY_IMAGE:$PROJECT_VERSION
dependencies: []
script:
- pip install -e .
- python -m pipeline_mermaid.gitlab_helper show_current_pipeline graph
- python -m pipeline_mermaid.gitlab_helper show_pipeline 190875422
- python -m pipeline_mermaid.gitlab_helper show_pipeline 192204962 journey
- pipeline-mermaid show_current_pipeline graph
- pipeline_mermaid show_pipeline 190875422
- pipeline_mermaid show_pipeline 192204962 journey


upload to pypi:
Expand All @@ -83,7 +83,7 @@ upload to pypi:
dependencies:
- build package
tags: [ gitlab-org-docker ]
image: $CI_REGISTRY_IMAGE:$DOCKER_IMAGE_VERSION
image: $CI_REGISTRY_IMAGE:$PROJECT_VERSION
when: manual
script:
- twine upload dist/* --non-interactive -u __token__ -p $PYPI_TOKEN --verbose
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ FROM python:3-slim

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt \
&& rm -rf *
COPY ./ ./
RUN pip install --no-cache-dir .
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.4
- global command "pipeline-mermaid"

# 0.3
- support repeated jobs

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@

Useful tool to show Gitlab pipeline as mermaid

## install

```commandline
pip install pipeline-mermaid
```

#### required environments

- `GITLAB_API_TOKEN` - gitlab api token

## Using

Show current pipeline in merge request notes. [Example merge request](https://gitlab.com/Nov1kov/pipeline_to_mermaid/-/merge_requests/4)

### in .gitlab-ci.yml

```yml
notify merge request:
image: registry.gitlab.com/nov1kov/pipeline_to_mermaid:0.4
stage: deploy
only:
- merge_requests
script:
- python -m pipeline_mermaid.gitlab_helper show_current_pipeline
- pipeline-mermaid show_current_pipeline
```
### as python package
```commandline
pip install pipeline-mermaid
pipeline-mermaid show_current_pipeline
```
Show current pipeline in merge request notes. [Example merge request](https://gitlab.com/Nov1kov/pipeline_to_mermaid/-/merge_requests/4)

## Gitlab pipeline as mermaid

Expand Down Expand Up @@ -98,6 +101,7 @@ section deploy
### mermaid
- interactions https://mermaid-js.github.io/mermaid/diagrams-and-syntax-and-examples/gantt.html#interaction
- state
- docker implement

### documentaion
- https://pdoc3.github.io/pdoc/
Expand Down
9 changes: 9 additions & 0 deletions pipeline-mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

import sys

from pipeline_mermaid.gitlab_helper import GitlabHelper

if __name__ == "__main__":
gl = GitlabHelper()
result = eval("GitlabHelper." + sys.argv[1])(gl, *sys.argv[2:])
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from setuptools import setup, find_packages

with open('README.md') as readme_file:
Expand All @@ -8,7 +10,7 @@

setup_args = dict(
name='pipeline_mermaid',
version='0.3',
version=os.environ['PROJECT_VERSION'],
description='Useful tool to show Gitlab pipeline as mermaid',
long_description_content_type="text/markdown",
long_description=README + '\n\n' + HISTORY,
Expand All @@ -18,7 +20,8 @@
author_email='[email protected]',
keywords=['pipeline', 'mermaid', 'Gitlab'],
url='https://github.com/Nov1kov/pipeline_to_mermaid',
download_url='https://pypi.org/project/pipeline-mermaid/'
download_url='https://pypi.org/project/pipeline-mermaid/',
scripts=['pipeline-mermaid']
)

install_requires = [
Expand Down

0 comments on commit 6c45219

Please sign in to comment.