Skip to content

Instantly share code, notes, and snippets.

@amitkumar0000
Forked from tfcporciuncula/1 - ci.yml
Created September 17, 2023 02:53
Show Gist options
  • Save amitkumar0000/879a1ec8b2c8205e47715ece56c764e3 to your computer and use it in GitHub Desktop.
Save amitkumar0000/879a1ec8b2c8205e47715ece56c764e3 to your computer and use it in GitHub Desktop.

Revisions

  1. @tfcporciuncula tfcporciuncula revised this gist Sep 24, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 1 - ci.yml
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ generate-dependency-graph:
    git config --local user.email '[email protected]'
    git config --local user.name 'GitHub Action'
    git diff --quiet && git diff --staged --quiet || git commit -am 'Update dependency graph'
    - name: Push
    uses: ad-m/github-push-action@master
    with:
  2. @tfcporciuncula tfcporciuncula revised this gist Sep 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 1 - ci.yml
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ generate-dependency-graph:
    uses: actions/checkout@v2

    - name: Setup Graphviz
    uses: kamiazya/setup-graphviz@v1
    uses: ts-graphviz/setup-graphviz@v1

    - name: Generate Dependency Graph
    run: ./gradlew projectDependencyGraph
  3. @tfcporciuncula tfcporciuncula created this gist Sep 7, 2020.
    22 changes: 22 additions & 0 deletions 1 - ci.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    generate-dependency-graph:
    name: Generate Dependency Graph
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
    uses: actions/checkout@v2

    - name: Setup Graphviz
    uses: kamiazya/setup-graphviz@v1

    - name: Generate Dependency Graph
    run: ./gradlew projectDependencyGraph

    - name: Commmit
    run: |
    git config --local user.email '[email protected]'
    git config --local user.name 'GitHub Action'
    git diff --quiet && git diff --staged --quiet || git commit -am 'Update dependency graph'
    - name: Push
    uses: ad-m/github-push-action@master
    with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    122 changes: 122 additions & 0 deletions 2 - projectDependencyGraph.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,122 @@
    // From https://github.com/JakeWharton/SdkSearch/blob/master/gradle/projectDependencyGraph.gradle
    // The only difference here is the output directory.

    // Add this file in your gradle directory and the following line at the bottom of your build file:
    // apply from: file('gradle/projectDependencyGraph.gradle')

    task projectDependencyGraph {
    doLast {
    def dot = new File(rootProject.rootDir, 'gradle/dependency-graph/project.dot')
    dot.parentFile.mkdirs()
    dot.delete()

    dot << 'digraph {\n'
    dot << " graph [label=\"${rootProject.name}\\n \",labelloc=t,fontsize=30,ranksep=1.4];\n"
    dot << ' node [style=filled, fillcolor="#bbbbbb"];\n'
    dot << ' rankdir=TB;\n'

    def rootProjects = []
    def queue = [rootProject]
    while (!queue.isEmpty()) {
    def project = queue.remove(0)
    rootProjects.add(project)
    queue.addAll(project.childProjects.values())
    }

    def projects = new LinkedHashSet<Project>()
    def dependencies = new LinkedHashMap<Tuple2<Project, Project>, List<String>>()
    def multiplatformProjects = []
    def jsProjects = []
    def androidProjects = []
    def javaProjects = []

    queue = [rootProject]
    while (!queue.isEmpty()) {
    def project = queue.remove(0)
    queue.addAll(project.childProjects.values())

    if (project.plugins.hasPlugin('org.jetbrains.kotlin.multiplatform')) {
    multiplatformProjects.add(project)
    }
    if (project.plugins.hasPlugin('org.jetbrains.kotlin.js')) {
    jsProjects.add(project)
    }
    if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) {
    androidProjects.add(project)
    }
    if (project.plugins.hasPlugin('java-library') || project.plugins.hasPlugin('java')) {
    javaProjects.add(project)
    }

    project.configurations.all { config ->
    config.dependencies
    .withType(ProjectDependency)
    .collect { it.dependencyProject }
    .each { dependency ->
    projects.add(project)
    projects.add(dependency)
    rootProjects.remove(dependency)

    def graphKey = new Tuple2<Project, Project>(project, dependency)
    def traits = dependencies.computeIfAbsent(graphKey) { new ArrayList<String>() }

    if (config.name.toLowerCase().endsWith('implementation')) {
    traits.add('style=dotted')
    }
    }
    }
    }

    projects = projects.sort { it.path }

    dot << '\n # Projects\n\n'
    for (project in projects) {
    def traits = []

    if (rootProjects.contains(project)) {
    traits.add('shape=box')
    }

    if (multiplatformProjects.contains(project)) {
    traits.add('fillcolor="#ffd2b3"')
    } else if (jsProjects.contains(project)) {
    traits.add('fillcolor="#ffffba"')
    } else if (androidProjects.contains(project)) {
    traits.add('fillcolor="#baffc9"')
    } else if (javaProjects.contains(project)) {
    traits.add('fillcolor="#ffb3ba"')
    } else {
    traits.add('fillcolor="#eeeeee"')
    }

    dot << " \"${project.path}\" [${traits.join(", ")}];\n"
    }

    dot << '\n {rank = same;'
    for (project in projects) {
    if (rootProjects.contains(project)) {
    dot << " \"${project.path}\";"
    }
    }
    dot << '}\n'

    dot << '\n # Dependencies\n\n'
    dependencies.forEach { key, traits ->
    dot << " \"${key.first.path}\" -> \"${key.second.path}\""
    if (!traits.isEmpty()) {
    dot << " [${traits.join(", ")}]"
    }
    dot << '\n'
    }

    dot << '}\n'

    def p = 'dot -Tpng -O project.dot'.execute([], dot.parentFile)
    p.waitFor()
    if (p.exitValue() != 0) {
    throw new RuntimeException(p.errorStream.text)
    }

    println("Project module dependency graph created at ${dot.absolutePath}.png")
    }
    }
    3 changes: 3 additions & 0 deletions 3 - README
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    And here's how to show the (automatically kept) up to date dependency graph for the project in a README file:

    ![](gradle/dependency-graph/project.dot.png)