diff --git a/.github/workflows/update-main-version.yml b/.github/workflows/update-main-version.yml new file mode 100644 index 0000000..db3fd54 --- /dev/null +++ b/.github/workflows/update-main-version.yml @@ -0,0 +1,30 @@ +name: Update Main Version +run-name: Move ${{ github.event.inputs.major_version }} to ${{ github.event.inputs.target }} + +on: + workflow_dispatch: + inputs: + target: + description: The tag or reference to use + required: true + major_version: + type: choice + description: The major version to update + options: + - v1 + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Git config + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: Tag new target + run: git tag -f ${{ github.event.inputs.major_version }} ${{ github.event.inputs.target }} + - name: Push new tag + run: git push origin ${{ github.event.inputs.major_version }} --force \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..85baa39 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "structurizr" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 178fc8a..1058c3e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,64 @@ -# structutizr-gh-action-gen-images +# Generate Structurizr Diagrams Action + +## Introduction + This GitHub Action automatically generates and updates Structurizr diagrams on pull requests. It's designed to simplify the process of keeping architecture diagrams up-to-date with the latest changes in your codebase. + +## Prerequisites + +Before you use this action, make sure you have: + +- A GitHub repository. +- A `workspace.dsl` file in your repository for Structurizr. + +## Usage + +To use this action in your workflow, follow these steps: + +1. **Set up the workflow**: Create a `.github/workflows` directory in your repository if it doesn't exist. +2. **Create a workflow file**: Inside the `.github/workflows` directory, create a new file (e.g., `structurizr-diagrams-update.yml`) and add the following content: + +```yaml +name: Update Structurizr Diagrams + +on: + pull_request: + paths: + - 'docs/workspace.dsl' # This setting will have the action trigger only if certain file changes. Set the location of your DSL. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + update-diagrams: + runs-on: ubuntu-latest + steps: + - uses: sebastienfi/structurizr-gen-images@v1 + with: + workspace-path: 'docs/workspace.dsl' # This setting will have the action generate images from this DSL. Set the location of your DSL. +``` + +3. Commit the workflow to `main` and create a PR which include a change in your DSL file. +4. The action will commit the generated images to your Pr's branch. + +## Inputs + +This action accepts the following inputs: + +- `workspace-path`: Path to the `workspace.dsl` file. + - **Required**: Yes + - **Default**: `docs/workspace.dsl` + +## Outputs + +This action does not produces any output. + +## Additional Notes + +- Ensure that the `workspace.dsl` file is correctly set up and located in the specified path. +- The action will check for changes in the diagram images and update them if necessary. +- Generated diagrams are committed and pushed to the same branch that initiated the pull request. Of course, if your diagram does not change, there will be no commit. + +## Contributing + +Contributions to this action are welcome. Please ensure that your pull requests are well-described and adhere to the project's coding standards. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ad54973 --- /dev/null +++ b/action.yml @@ -0,0 +1,49 @@ +name: 'Generate Structurizr Diagrams' +description: 'Automatically generates and updates Structurizr diagrams on pull requests.' +inputs: + # You can define inputs that users of your action can specify + # For example, the path to workspace.dsl if it varies + workspace-path: + description: 'Path to the workspace.dsl file' + required: true + default: 'docs/workspace.dsl' + +runs: + using: 'composite' + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup Git + run: git config --global --add safe.directory $PWD + shell: bash + + - name: Generate Diagram Images + run: | + output_dir="docs/diagrams" # Default output directory + /usr/local/structurizr-cli/structurizr.sh export -workspace ${{ inputs.workspace-path }} -format plantuml -output $output_dir + cd $output_dir + echo 'Generating PNGs...' + plantuml -tpng *.puml + shell: bash + + - name: Check for Changes + id: check_changes + run: | + git add *.png + if git diff --staged --quiet; then + echo "CHANGES_EXIST=false" >> $GITHUB_ENV + else + echo "CHANGES_EXIST=true" >> $GITHUB_ENV + shell: bash + + - name: Commit and Push Diagrams + if: env.CHANGES_EXIST == 'true' + run: | + git commit -m "chores(C4 diagrams): Update Structurizr diagrams for views" + git push origin HEAD:${GITHUB_HEAD_REF} + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}