Skip to content

Instantly share code, notes, and snippets.

@thedmeyer
Last active April 17, 2024 14:38
Show Gist options
  • Save thedmeyer/8b50362ae71ecbadabb17f8683c70ece to your computer and use it in GitHub Desktop.
Save thedmeyer/8b50362ae71ecbadabb17f8683c70ece to your computer and use it in GitHub Desktop.
PlantUML Github Action for generating SVGs

PlantUML GitHub Action

To use this action, you must include a copy of the plantuml.jar file within the root directory of your repository. You can get this file here at: https://sourceforge.net/projects/plantuml/files/plantuml.jar/download

Or run this curl command in your root directory: curl -o plantuml.jar https://iweb.dl.sourceforge.net/project/plantuml/plantuml.jar

How It Works

This action works by recursively searching for PlantUML files with the extension .pu in a subdirectory named src. The found files are then generated as SVGs and placed in the output directory. The source and destination folders can be updated to your liking.

The Process Diagrams Command

This is the main command: java -jar plantuml.jar -v -tsvg -r -o "${{ github.workspace }}/output" "src/**.pu"

  • -v gives a verbose output to the console.
  • -tsvg specifies to generate SVGs.
  • -r enables recursive search.
  • -o specifies an output directory.
  • src/**.pu looks for .pu files in the src directory recursively.

If an absolute output path is not specified, the output is always placed in the same directory as the source content.

name: generate plantuml
on: push
jobs:
generate_plantuml:
runs-on: ubuntu-latest
name: plantuml
steps:
- name: Install Dependencies
run: |
sudo apt-get install graphviz
- name: Checkout Repository
uses: actions/checkout@v2
- name: Process Diagrams
run: java -jar plantuml.jar -v -tsvg -r -o "${{ github.workspace }}/output" "src/**.pu"
- name: Display Diagrams
run: pwd && ls output
- name: Commit Diagrams
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m ":rocket: adding generated diagrams" || exit 0
- name: Push Diagrams
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
@BillBensing
Copy link

Thanks for this! I attempted to use it as you had, although I got an error that the plantuml.jar did not exist. Here is what I did to fix it:

https://github.com/attestify/kernel-specification/blob/main/.github/workflows/diagrams.yml

@DomValladolid
Copy link

DomValladolid commented Oct 20, 2022

In case there's latex needed, I used this.

name: Generate Diagrams
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  generate_plantuml:
    runs-on: ubuntu-latest
    name: plantuml
    steps:
      - name: Install Dependencies
        run: |
          sudo apt-get install graphviz
          sudo mkdir -p /opt/plantuml
          cd /opt/plantuml
          UML=https://github.com/tide-foundation/devopsDL/raw/main/download/plantuml-1.2022.6.jar
          sudo curl -JLO ${UML}
          UML=https://github.com/tide-foundation/devopsDL/raw/main/download/batik-all-1.7.jar
          sudo curl -JLO ${UML}
          UML=https://github.com/tide-foundation/devopsDL/raw/main/download/jlatexmath-minimal-1.0.3.jar
          sudo curl -JLO ${UML}
          UML=https://github.com/tide-foundation/devopsDL/raw/main/download/jlm_cyrillic.jar
          sudo curl -JLO ${UML}
          UML=https://github.com/tide-foundation/devopsDL/raw/main/download/jlm_greek.jar
          sudo curl -JLO ${UML}
      - name: Checkout Repository
        uses: actions/checkout@v2
      - name: Process Diagrams svg
        run: java -jar /opt/plantuml/plantuml-1.2022.6.jar -v -tsvg -r -o "." "src/tide/current/**.puml"
      - name: Process Diagrams png
        run: java -jar /opt/plantuml/plantuml-1.2022.6.jar -v -tpng -r -o "." "src/tide/current/**.puml"
      - name: Display Diagrams
        run: pwd &&  ls diagrams/** | grep \.svg$
      - name: Commit Diagrams
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git add .
          git commit -m ":rocket: Adding Generated PlantUML Diagrams" || exit 0
      - name: Push Diagrams
        uses: ad-m/github-push-action@master
        with:
          GITHUB_TOKEN: ${{ github.token }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment