Skip to content

Commit 812d7d4

Browse files
authored
Merge pull request #67 from InnerSourceCommons/add-auto-use-gqm-update
feat: gqm diagram updated by GitHub Actions
2 parents 08760ad + 42a07db commit 812d7d4

File tree

8 files changed

+1976
-89
lines changed

8 files changed

+1976
-89
lines changed

.github/workflows/gqm_update.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Update GQM
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- 'measuring/goals/**'
7+
- 'measuring/questions/**'
8+
- 'measuring/metrics/**'
9+
10+
workflow_dispatch:
11+
jobs:
12+
generateDiagram:
13+
name: Generate Diagram
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Use Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '21.x'
22+
- run: npm install --prefix ./scripts/gqm_gen
23+
- run: npm run coverage-report --prefix ./scripts/gqm_gen
24+
- name: Report NYC coverage
25+
uses: sidx1024/[email protected]
26+
with:
27+
coverage_file: ".nyc_output/nyc-coverage-report/coverage-summary.json"
28+
- run: npm run --silent start --prefix ./scripts/gqm_gen > ./new_gqm.md.tmp
29+
- run: sh ./scripts/gqm_gen/gqm_update.sh ./new_gqm.md.tmp ./measuring/use_gqm.md > ./measuring/use_gqm.md.tmp
30+
- run: rm -f ./new_gqm.md.tmp
31+
- run: mv -f ./measuring/use_gqm.md.tmp ./measuring/use_gqm.md
32+
- run: sh ./scripts/gqm_gen/gqm_commit.sh

measuring/use_gqm.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,62 @@
44

55
This page works better in GitHub; [click here](https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/use_gqm.md).
66

7+
<!---
8+
9+
WARNING: Changes to this graph are overwritten by a GitHub workflow.
10+
11+
To update this graph, add new goals, questions, and metrics to the following directores.
12+
13+
./goals
14+
./questions
15+
./metrics
16+
17+
A GitHub workflow will automatically update this graph with your changes.
18+
19+
See this README.md file for more information about how to add goals, questions, and metrics.
20+
21+
./gqm_gen/README.md
22+
23+
To test your changes see this README.md file.
24+
25+
../scripts/gqm_gen/README.md
26+
27+
--->
28+
729
```mermaid
830
graph LR;
31+
932
subgraph GQM[Goals, Questions, Metrics]
10-
find-projects[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/goals/find-projects.md'>Find Projects</a>] --> who-uses[Who Uses]
11-
reduce-duplication[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/goals/reduce-duplication.md'>Reduce Duplication</a>] --> who-uses[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/questions/who-uses.md'>Who Uses</a>]
12-
who-uses --> usage-count[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/metrics/usage-count.md'>Usage Count</a>]
13-
find-projects --> who-contributes
14-
who-contributes[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/questions/who-contributes.md'>Who Contributes</a>] --> code-contributions[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/metrics/code-contributions.md'>Code Contributions</a>]
15-
end
16-
subgraph Legend
33+
34+
find-projects.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//goals/find-projects.md'>Find InnerSource Projects</a>]
35+
reduce-duplication.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//goals/reduce-duplication.md'>Reduce duplication</a>]
36+
who-contributes.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//questions/who-contributes.md'>Who contributes to the InnerSource project?</a>]
37+
who-uses.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//questions/who-uses.md'>Who uses the InnerSource project?</a>]
38+
code-contributions.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//metrics/code-contributions.md'>Code contributions</a>]
39+
usage-count.md[<a href='https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring//metrics/usage-count.md'>Usage count</a>]
40+
find-projects.md-->who-uses.md
41+
find-projects.md-->who-contributes.md
42+
reduce-duplication.md-->who-uses.md
43+
who-contributes.md-->code-contributions.md
44+
who-uses.md-->usage-count.md
45+
end
46+
subgraph Legend
1747
direction TB
1848
1949
goal[Goal]
2050
question[Question]
2151
metric[Metric]
2252
2353
classDef goals stroke:green,stroke-width:2px;
24-
class goal,find-projects,reduce-duplication goals
54+
class goal,find-projects.md,reduce-duplication.md goals
2555
2656
classDef questions stroke:orange,stroke-width:2px;
27-
class question,who-uses,who-contributes questions
57+
class question,who-contributes.md,who-uses.md questions
2858
2959
classDef metrics stroke:purple,stroke-width:2px;
30-
class metric,code-contributions,usage-count metrics
31-
end
60+
class metric,code-contributions.md,usage-count.md metrics
61+
end
62+
3263
```
3364

3465
Add your goals, questions, and metrics into this graph! It will help you to see how others approach and interact with what you are doing.

scripts/gqm_gen/gqm_commit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
if cmp -s ./measuring/use_gqm.md.tmp ./measuring/use_gqm.md; then
3+
echo "No changes in GQM diagram"
4+
exit 0
5+
fi
6+
7+
git --version
8+
git config user.name "GitHub Actions Bot"
9+
git config user.email "<>"
10+
git add ./measuring/use_gqm.md
11+
git commit -m "feat: gqm diagram updated by GitHub Actions"
12+
git push

scripts/gqm_gen/gqm_update.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Check if the correct number of arguments are provided
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <path-to-new-mermaid-markdown-file> <path-to-exising-use_gqm-markdown-file>"
6+
exit 1
7+
fi
8+
9+
# File paths
10+
NEW_MERMAID_MARKDOWN_FILE="$1"
11+
EXISTING_USE_GQM_MARKDOWN_FILE="$2"
12+
13+
# Check if the new content file exists
14+
if [ ! -f "$NEW_MERMAID_MARKDOWN_FILE" ]; then
15+
echo "Error: New mermaid markdown file not found at $NEW_MERMAID_MARKDOWN_FILE"
16+
exit 1
17+
fi
18+
19+
# Check if the markdown file exists
20+
if [ ! -f "$EXISTING_USE_GQM_MARKDOWN_FILE" ]; then
21+
echo "Error: Existing use_gqm markdown file not found at $EXISTING_USE_GQM_MARKDOWN_FILE"
22+
exit 1
23+
fi
24+
25+
# The pattern to match the mermaid block
26+
START_PATTERN='```mermaid'
27+
END_PATTERN='```'
28+
29+
# Replace the entire mermaid block including the delimiters
30+
sed -e "/$START_PATTERN/,/$END_PATTERN/{
31+
/$START_PATTERN/{
32+
r $NEW_MERMAID_MARKDOWN_FILE
33+
d
34+
}
35+
/$END_PATTERN/d
36+
d
37+
}" "$EXISTING_USE_GQM_MARKDOWN_FILE"

scripts/gqm_gen/index.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as Commonmark from "commonmark";
2+
import * as fs from "fs";
23
import test from "node:test";
34
import assert from "node:assert";
45
import { FileLink, Graph, LinkType } from "./types";
56
import {
67
getLinks,
78
getFileLinks,
89
generateMermaidDiagram,
9-
getGQMFileLinks,
10+
getGQMFileLinks
1011
} from "./index";
1112

1213
test("can get links", () => {
@@ -29,13 +30,11 @@ test("can generate mermaid diagram", () => {
2930
edges: [],
3031
};
3132
const diagram = generateMermaidDiagram(graph);
32-
assert(diagram.indexOf("graph TB") > 1);
33+
assert(diagram.indexOf("graph LR") > 1);
3334
});
3435

35-
test("can generate mermaid diagram from file", { only: true }, () => {
36-
const graph = getGQMFileLinks();
37-
36+
test("can generate mermaid diagram from file", () => {
37+
const graph = getGQMFileLinks('../../measuring/');
3838
const diagram = generateMermaidDiagram(graph);
39-
console.log(diagram);
4039
assert(diagram.indexOf("graph LR;") > 1);
4140
});

scripts/gqm_gen/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ import * as path from "path";
44
import { Node, Edge, Graph, Link, LinkType, NodeShape, ArrowType } from "./types";
55
import { FileLink } from "./types";
66

7-
const graph = getGQMFileLinks();
7+
const mdFilePath = process.env.npm_config_markDownFilePath || "../../measuring";
8+
9+
const graph = getGQMFileLinks(mdFilePath);
810

911
export function getLinkUrl(linkType: LinkType, file: string) {
1012
const measuringUrl = "https://github.com/InnerSourceCommons/managing-inner-source-projects/blob/main/measuring/";
1113
const url = `${measuringUrl}/${linkType.toLowerCase()}s/${file}`
1214
return url;
1315
}
1416

15-
export function getGQMFileLinks() {
17+
export function getGQMFileLinks(mdFilePath: string) {
1618
const graph: Graph = {
1719
nodes: [],
1820
edges: [],
1921
};
2022

21-
const goalsPath = "../../measuring/goals/";
22-
const questionsPath = "../../measuring/questions/";
23-
const metricsPath = "../../measuring/metrics/";
23+
const goalsPath = `${mdFilePath}/goals/`;
24+
const questionsPath = `${mdFilePath}/questions/`;
25+
const metricsPath = `${mdFilePath}/metrics/`;
2426

2527
const goalFileLinks: FileLink[] = getFileLinks(LinkType.GOAL, goalsPath);
2628
appendToGraph(graph, goalFileLinks);
@@ -144,8 +146,7 @@ export function generateMermaidDiagram(graph: Graph) {
144146
const nodes = graph.nodes;
145147
const edges = graph.edges;
146148

147-
let mermaidSyntax = `\`\`\`mermaid\n
148-
graph LR;\n
149+
let mermaidSyntax = `\`\`\`mermaid\ngraph LR;\n
149150
subgraph GQM[Goals, Questions, Metrics]\n
150151
`;
151152

@@ -156,7 +157,7 @@ export function generateMermaidDiagram(graph: Graph) {
156157

157158
edges.forEach((edge) => {
158159
const arrowSyntax: string = ArrowType.ARROW;
159-
mermaidSyntax += `${edge.from}${arrowSyntax}${edge.to}\n`;
160+
mermaidSyntax += ` ${edge.from}${arrowSyntax}${edge.to}\n`;
160161
});
161162

162163
const goalsList = nodes.filter(n => n.type == LinkType.GOAL).map(n => `${n.id}`).join(',');

0 commit comments

Comments
 (0)