-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bbec7b
commit 5c009eb
Showing
4 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] | ||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"structurizr" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# structurizr-pr-comment | ||
This GitHub Action automatically makes a comment on each pull requests which updates Structurizr diagrams. It's designed to simplify the process of visualizing architecture diagrams changes in your codebase. | ||
# Comment on PR with Structurizr Diagrams Action | ||
|
||
## Introduction | ||
|
||
This GitHub Action, designed to complement the [Generate Structurizr Diagrams Images from DSL](https://github.com/marketplace/actions/generate-structurizr-diagrams-images-from-dsl) action, automatically comments on pull requests with the previously generated Structurizr diagrams. It ensures that team members can easily review the latest architecture diagrams directly within the context of a PR. | ||
|
||
## Prerequisites | ||
|
||
To use this action effectively, you should have: | ||
|
||
- A GitHub repository. | ||
- Completed the setup of the "Generate Structurizr Diagrams Images from DSL" action in your repository. | ||
|
||
## Usage | ||
|
||
This action is meant to be used in a separate workflow that triggers after the "Generate Structurizr Diagrams Images from DSL" workflow. To set it up: | ||
|
||
1. **Create a workflow file**: In your repository's `.github/workflows` directory, create a new file (e.g., `structurizr-diagrams-comment.yml`) with the following content: | ||
|
||
```yaml | ||
name: Comment on PR with Structurizr Diagrams | ||
|
||
on: | ||
workflow_run: | ||
types: | ||
- completed | ||
workflows: | ||
- "Update Structurizr Diagrams" | ||
|
||
jobs: | ||
comment-on-pr: | ||
if: github.event.workflow_run.conclusion == 'success' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: sebastienfi/structurizr-pr-comment@v1 | ||
``` | ||
## How It Works | ||
- The action triggers after the "Update Structurizr Diagrams" workflow completes. | ||
- It retrieves information about the PR and lists the generated diagram files. | ||
- If diagrams are updated, the action posts or updates a comment in the PR with the diagrams. | ||
## Contributing | ||
Contributions to improve this action are welcome. Ensure your contributions are well-documented and follow the coding standards of this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: 'Comment on PR with Structurizr Diagrams' | ||
description: 'Automatically comments on PRs with Structurizr diagrams.' | ||
branding: | ||
icon: 'activity' | ||
color: 'white' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Get PR Info | ||
run: | | ||
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") | ||
echo "Previous Job ID: $PREVIOUS_JOB_ID" | ||
echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" | ||
PR_NUMBER=$(jq -r '.pull_requests[0].number' \ | ||
<<< "$WORKFLOW_RUN_EVENT_OBJ") | ||
echo "PR Number: $PR_NUMBER" | ||
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" | ||
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \ | ||
<<< "$WORKFLOW_RUN_EVENT_OBJ") | ||
echo "Head sha: $HEAD_SHA" | ||
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} | ||
|
||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.workflow_run.head_branch }} | ||
|
||
- name: List Diagram Files | ||
run: | | ||
cd ${{ env.OUTPUT_DIR }} | ||
echo 'PNG_FILES_MARKDOWN<<EOF' >> "$GITHUB_ENV" | ||
for png_file in *.png; do | ||
# Skip legend files in this loop | ||
if [[ $png_file == *"-key.png" ]]; then | ||
continue | ||
fi | ||
base_name=$(basename $png_file .png) | ||
legend_file="${base_name}-key.png" | ||
# URLs for diagram and its legend | ||
png_raw_file_path="https://raw.githubusercontent.com/${{ github.repository }}/${{ env.HEAD_SHA }}/${{ env.OUTPUT_DIR }}/${png_file}" | ||
legend_raw_file_path="https://raw.githubusercontent.com/${{ github.repository }}/${{ env.HEAD_SHA }}/${{ env.OUTPUT_DIR }}/${legend_file}" | ||
echo "<details>" >> "$GITHUB_ENV" | ||
clean_base_name=${base_name#structurizr-} | ||
echo "<summary>${clean_base_name}</summary>" >> "$GITHUB_ENV" | ||
if [ -f "$legend_file" ]; then | ||
echo "<img src=\"${legend_raw_file_path}\">" >> "$GITHUB_ENV" | ||
echo "" >> "$GITHUB_ENV" | ||
fi | ||
echo " <img src=\"${png_raw_file_path}\">" >> "$GITHUB_ENV" | ||
echo "</details>" >> "$GITHUB_ENV" | ||
done | ||
echo EOF >> "$GITHUB_ENV" | ||
shell: bash | ||
env: | ||
OUTPUT_DIR: 'docs/diagrams' | ||
HEAD_SHA: ${{ env.HEAD_SHA }} | ||
|
||
- name: Find Comment | ||
uses: peter-evans/find-comment@v2 | ||
id: find-comment | ||
env: | ||
PR_NUMBER: ${{ env.PR_NUMBER }} | ||
with: | ||
issue-number: ${{ env.PR_NUMBER }} | ||
comment-author: 'github-actions[bot]' | ||
|
||
- name: Comment on PR | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ env.PR_NUMBER }} | ||
HEAD_SHA: ${{ env.HEAD_SHA }} | ||
PREVIOUS_JOB_ID: ${{ env.PREVIOUS_JOB_ID }} | ||
PNG_FILES_MARKDOWN: ${{ env.PNG_FILES_MARKDOWN }} | ||
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
issue-number: ${{ env.PR_NUMBER }} | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
edit-mode: replace | ||
reactions: | | ||
heart | ||
hooray | ||
body: | | ||
## C4 Diagrams | ||
Commit: ${{ env.HEAD_SHA }} | ||
Logs: ${{ env.JOB_PATH }} | ||
${{ env.PNG_FILES_MARKDOWN }} |