Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/java-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
repository: AxonFramework/AxonFramework
ref: axon-${{ env.AXON_FRAMEWORK_VERSION }}
path: ./source
fetch-depth: 0 # Include the full git history for analysis

- name: (Prepare Code to Analyze) Setup Java Development Kit for Maven JARs downloading (JDK) ${{ env.JAVA_VERSION}}
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/typescript-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
with:
repository: remix-run/react-router
ref: react-router@${{ env.REACT_ROUTER_VERSION }}
fetch-depth: 0 # Include the full git history for enhanced analysis

- name: (Prepare Code to Analyze) Setup pnpm for react-router
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
Expand Down
102 changes: 100 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,100 @@
# code-graph-analysis-examples
Shows how to use the [code-graph-analysis-pipeline](https://github.com/JohT/code-graph-analysis-pipeline) based on some examples
# Code Graph Analysis Pipeline Examples

This repository provides examples of how to analyze TypeScript code and Java artifacts using a fully automated GitHub Workflows pipeline with the [code-graph-analysis-pipeline](https://github.com/JohT/code-graph-analysis-pipeline).

The process involves three steps:

1. **Extract**: Upload TypeScript source code and/or Java artifacts, optionally including their git history, using [actions/upload-artifact](https://github.com/actions/upload-artifact).

1. **Analyze**: Use the shared workflow [JohT/code-graph-analysis-pipeline/.github/workflows/public-analyze-code-graph.yml](https://github.com/JohT/code-graph-analysis-pipeline/blob/main/.github/workflows/public-analyze-code-graph.yml) to analyze the code and artifacts, then upload the results.

1. **Use**: Download the analysis results with [actions/download-artifact](https://github.com/actions/download-artifact) and utilize them as needed.

## Example for TypeScript Code

This example demonstrates how to analyze TypeScript code in a GitHub Workflows pipeline.

1. The first job, [prepare-code-to-analyze](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/typescript-code-analysis.yml#L40), in the GitHub Actions Workflow [typescript-code-analysis.yml](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/typescript-code-analysis.yml), shows how to extract TypeScript code from a repository and upload it for analysis.

2. The second job, [analyze-code-graph](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/typescript-code-analysis.yml#L89), calls the shared analysis workflows using the uploaded artifacts' names as parameters. Here is a simple example:

```yaml
name: Analyze Code Graph
needs: [prepare-code-to-analyze]
uses: JohT/code-graph-analysis-pipeline/.github/workflows/public-analyze-code-graph.yml
with:
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
```

3. The third job, [analyze-code-graph](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/typescript-code-analysis.yml#L99), demonstrates how to download the analysis results and commit them back to the repository.

## Example for Java Artifacts

Java artifacts are analyzed similarly to TypeScript code. The main difference is that Java artifacts are downloaded from a Maven repository instead of being part of the repository.

To include the git history in the analysis, checkout the corresponding source repository and upload it as the source artifact, similar to the TypeScript example. The Java source code isn't used for the analysis, so a bare git clone is sufficient.

The first job, [prepare-code-to-analyze](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/java-code-analysis.yml#L40), in the GitHub Actions Workflow [java-code-analysis.yml](https://github.com/JohT/code-graph-analysis-examples/blob/23143b34d8fc6e0ab7d80102d8de0b6e6a4ec98e/.github/workflows/java-code-analysis.yml), shows how to prepare the Java artifacts and git history for analysis.

The second and third jobs are the same as for the TypeScript example.

## Analysis Results

Here are ten examples from over a hundred reports generated by the analysis. These examples illustrate the results of analyzing [AxonFramework](https://github.com/AxonFramework/AxonFramework), a Java framework for Evolutionary Message-Driven Microservices on the JVM. For the complete set of reports, visit the [analysis-results](./analysis-results) directory.

### External Dependencies of Java Packages

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/external-dependencies-java/ExternalDependenciesJava_files/ExternalDependenciesJava_20_1.png" width="600" alt="External dependencies of Java packages">

### Dependencies Graph of Java Artifacts

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/internal-dependencies-visualization/JavaArtifactBuildLevels.svg" width="600" alt="Dependencies graph of Java artifacts">

### Longest Path(s) of Java Artifacts

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/path-finding-visualization/JavaArtifactLongestPaths.svg" width="600" alt="Longest path of Java artifacts">

### All Pairs Shortest Paths of Java Packages per Artifact

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/path-finding-java/PathFindingJava_files/PathFindingJava_47_1.png" width="600" alt="All pairs shortest paths of Java packages per artifact">

### Object-Oriented Design Metrics for Java Packages

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/object-oriented-design-metrics-java/ObjectOrientedDesignMetricsJava_files/ObjectOrientedDesignMetricsJava_41_0.png" width="600" alt="Object-Oriented Design Metrics for Java packages">

### Effective Line Count of Java Methods

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/method-metrics-java/MethodMetricsJava_files/MethodMetricsJava_14_1.png" width="600" alt="Effective line count of Java methods">

### Cyclomatic Complexity Distribution for Java Methods

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/method-metrics-java/MethodMetricsJava_files/MethodMetricsJava_26_1.png" width="600" alt="Cyclomatic complexity distribution for Java methods">

### Visibility of Java Types

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/visibility-metrics-java/VisibilityMetricsJava_files/VisibilityMetricsJava_24_2.png" width="600" alt="Visibility of Java types">

### Communities and Node Embeddings of Java Packages

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/node-embeddings-java/NodeEmbeddingsJava_files/NodeEmbeddingsJava_21_0.png" width="600" alt="Communities and node embeddings of Java packages">

### Word Cloud of Git Authors

<img src="./analysis-results/AxonFramework/AxonFramework-4.10.3/wordcloud/Wordcloud_files/Wordcloud_17_0.png" width="600" alt="Word cloud of git authors">

## Keeping the Analysis Workflow Updated with Renovate

This repository uses [Renovate](https://docs.renovatebot.com) to automatically update the analysis workflow to the latest version. To enable this, add the following extension to your Renovate configuration:

```json
"extends": [
"github>JohT/code-graph-analysis-pipeline//renovate-presets/code-graph-analysis-workflow-latest-digest.json5"
]
```

You can find the complete configuration in the [renovate.json](./renovate.json) file.

## License

This repository is licensed under the Apache License, Version 2.0. See [LICENSE](./LICENSE) for the full license text.
Loading