Skip to content

Commit

Permalink
Initiate Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Sep 6, 2024
1 parent a6fe2a2 commit 10984f2
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Lint Code Base

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: read
statuses: write

jobs:
lint:
name: Example Diagrams
runs-on: ubuntu-latest
steps:
- name: install nightly
run: |
rustup set profile minimal
rustup toolchain install nightly
shell: bash
- name: build pymermaider
run: |
git clone https://github.com/diceroll123/pymermaider
cd pymermaider
cargo build --release
shell: bash
- name: run pymermaider
run: |
pymermaider/target/release/pymermaider
shell: bash
- name: upload artifacts
uses: actions/upload-artifact@v2
with:
name: mermaid-diagrams
path:
pymermaider/target/release/output/*.md
- name: Upload mermaid md file diagram into PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const body = fs.readFileSync('pymermaider/target/release/output/*.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '```mermaid\n' + body + '\n```'
})
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# python-code-visualiser
## Overview

Python Code Visualiser is a github action that will create mermaid class diagrams of the a repo. The diagram can be posted to a PR as a comment to assist with Code Review, or just add as an artifact.

The repo makes use of the fantastic [pymermaider](https://github.com/diceroll123/pymermaider) to create the diagrams.

## Usage
### Permission

The following workflow permissions are necessary:

```yml
permissions:
contents: read
statuses: write
```
### Inputs
`python-code-visualiser` uses the following inputs:

| Name | Description | Required | Default |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | -------------- |
| `gh-token` | `GITHUB_TOKEN` (permissions `contents: write` and `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | no | `GITHUB_TOKEN` |

## Outputs

## Contributing

Contributions are more than welcome, just make a PR and we'll go from there!

## License

This project is licensed under the MIT license. Please see the
[LICENSE](LICENSE) file for more details.
50 changes: 50 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: python-code-visualiser
author: mike@trebilcock.net
description: 'Create Mermaid diagrams from Python code'
branding:
icon: 'file-text'
color: 'green'
inputs:
gh-token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
default: ${{ github.token }}
runs:
using: 'composite'
steps:
- name: install nightly
run: |
rustup set profile minimal
rustup toolchain install nightly
shell: bash
- name: build pymermaider
run: |
git clone https://github.com/diceroll123/pymermaider
cd pymermaider
cargo build --release
shell: bash
- name: run pymermaider
run: |
pymermaider/target/release/pymermaider
shell: bash
- name: upload artifacts
uses: actions/upload-artifact@v2
with:
name: mermaid-diagrams
path:
pymermaider/target/release/output/*.md
- name: Upload mermaid md file diagram into PR
uses: actions/github-script@v7
with:
github-token: ${{ inputs.gh-token }}
script: |
const fs = require('fs');
const body = fs.readFileSync('pymermaider/target/release/output/*.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '```mermaid\n' + body + '\n```'
})
7 changes: 7 additions & 0 deletions test/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Simple:
def __init__(self):
self.x = 1
self.y = 2

def add(self):
return self.x + self.y

0 comments on commit 10984f2

Please sign in to comment.