Skip to content

Add Diff Javadoc workflow #4426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 14, 2022
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
67 changes: 67 additions & 0 deletions .github/workflows/diff-javadoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Diff Javadoc

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Make Dir
run: mkdir ~/diff

- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: true

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: temurin
cache: gradle

- name: Changed Modules
id: changed-modules
run: |
git diff --name-only HEAD~1 | xargs printf -- '--changed-git-paths %s\n' | xargs ./gradlew writeChangedProjects --output-file-path=modules.json --only-firebase-sdks
echo "run=$(cat modules.json | sed "s/[]\"[]//g" | sed "s/,/\n/g" | xargs printf -- "%s:kotlinDoc ")" >> $GITHUB_OUTPUT

- name: Build
run: ./gradlew ${{ steps.changed-modules.outputs.run }}

- name: Move original docs
run: mv build ~/diff/modified

- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}

- name: Build
run: ./gradlew ${{ steps.changed-modules.outputs.run }}

- name: Move modified docs
run: mv build ~/diff/original

- name: Diff docs
run: >
`# Recursively diff directories, including new files, git style, with 3 lines of context`
diff -wEburN ~/diff/original ~/diff/modified
`# Remove the first line and new file signifier of the output`
| tail -n +2
`# Replace the diff new file signifier with the end and start of a new codeblock`
| sed "s/^diff.*$/\`\`\`\\n\`\`\`diff/g"
`# Add a collapsable block, summary, and start the first code block on the first line`
| sed "1s/^/<details>\\n<summary>Javadoc Changes:<\/summary>\\n\\n\`\`\`diff\\n/"
`# Close the final code block and close the collapsable on the final line`
| sed "$ s/$/\\n\`\`\`\\n<\/details>/"
`# Write to diff.md for later`
> diff.md

- name: Add comment
uses: mshick/add-pr-comment@v2
with:
message-path: diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.gradle.plugins.ci

import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
import com.google.gson.Gson
import java.io.File
import org.gradle.api.DefaultTask
Expand All @@ -22,16 +23,21 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.kotlin.dsl.findByType

abstract class ChangedModulesTask : DefaultTask() {
@get:Input
@set:Option(option = "changed-git-paths", description = "Hellos")
@set:Option(option = "changed-git-paths", description = "The list of changed paths")
abstract var changedGitPaths: List<String>

@get:Input
@set:Option(option = "output-file-path", description = "Hello")
@set:Option(option = "output-file-path", description = "The file to output json to")
abstract var outputFilePath: String

@get:Input
@set:Option(option = "only-firebase-sdks", description = "Only list Firebase SDKs")
abstract var onlyFirebaseSDKs: Boolean

@get:OutputFile val outputFile by lazy { File(outputFilePath) }

init {
Expand All @@ -43,14 +49,25 @@ abstract class ChangedModulesTask : DefaultTask() {
val projects =
AffectedProjectFinder(project, changedGitPaths.toSet(), listOf())
.find()
.filter {
val ext = it.extensions.findByType(FirebaseLibraryExtension::class.java)
!onlyFirebaseSDKs || it.extensions.findByType<FirebaseLibraryExtension>() != null
}
.map { it.path }
.toSet()

val result = project.rootProject.subprojects.associate { it.path to mutableSetOf<String>() }
project.rootProject.subprojects.forEach { p ->
p.configurations.forEach { c ->
c.dependencies.filterIsInstance<ProjectDependency>().forEach {
result[it.dependencyProject.path]?.add(p.path)
if (
!onlyFirebaseSDKs ||
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
) {
if (!onlyFirebaseSDKs || p.extensions.findByType<FirebaseLibraryExtension>() != null) {
result[it.dependencyProject.path]?.add(p.path)
}
}
}
}
}
Expand Down