Skip to content

dataconnect: .github/workflows/dataconnect_demo_app.yml added #6568

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 6 commits into from
Dec 6, 2024
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
164 changes: 164 additions & 0 deletions .github/workflows/dataconnect_demo_app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: Data Connect Demo App

on:
workflow_dispatch:
inputs:
nodeVersion:
firebaseToolsVersion:
javaVersion:
gradleInfoLog:
type: boolean
pull_request:
paths:
- firebase-dataconnect/demo/**
- .github/workflows/dataconnect_demo_app.yml
schedule:
- cron: '0 11 * * *' # Run nightly at 11am UTC (3am Pacific, 6am Eastern)

env:
FDC_NODE_VERSION: ${{ inputs.nodeVersion || '20' }}
FDC_FIREBASE_TOOLS_VERSION: ${{ inputs.firebaseToolsVersion || '13.25.0' }}
FDC_JAVA_VERSION: ${{ inputs.javaVersion || '17' }}
FDC_FIREBASE_TOOLS_DIR: ${{ github.workspace }}/firebase-tools
FDC_FIREBASE_COMMAND: ${{ github.workspace }}/firebase-tools/node_modules/.bin/firebase

defaults:
run:
shell: bash
working-directory: firebase-dataconnect/demo

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
continue-on-error: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: firebase-dataconnect/demo

- name: Create Cache Key Files
run: |
echo "gmagjr2b9d" >github_actions_demo_test_cache_key.txt
echo "${{ env.FDC_FIREBASE_TOOLS_VERSION }}" >github_actions_demo_assemble_firebase_tools_version.txt
- uses: actions/setup-node@v3
with:
node-version: ${{ env.FDC_NODE_VERSION }}
cache: 'npm'
cache-dependency-path: |
firebase-dataconnect/demo/github_actions_demo_test_cache_key.txt
firebase-dataconnect/demo/github_actions_demo_assemble_firebase_tools_version.txt
- name: cache package-lock.json
id: package_json_lock
uses: actions/cache@v4
with:
path: ${{ env.FDC_FIREBASE_TOOLS_DIR }}/package*.json
key: firebase_tools_package_json-${{ env.FDC_FIREBASE_TOOLS_VERSION }}

- name: install firebase-tools from scratch
if: steps.package_json_lock.outputs.cache-hit != 'true'
run: |
set -v
mkdir -p ${{ env.FDC_FIREBASE_TOOLS_DIR }}
cd ${{ env.FDC_FIREBASE_TOOLS_DIR }}
echo '{}' > package.json
npm install --fund=false --audit=false --save --save-exact firebase-tools@${{ env.FDC_FIREBASE_TOOLS_VERSION }}
- name: install firebase-tools from package-lock.json
if: steps.package_json_lock.outputs.cache-hit == 'true'
run: |
cd ${{ env.FDC_FIREBASE_TOOLS_DIR }}
npm ci --fund=false --audit=false
- uses: actions/setup-java@v4
with:
java-version: ${{ env.FDC_JAVA_VERSION }}
distribution: temurin
cache: gradle
cache-dependency-path: |
firebase-dataconnect/demo/build.gradle.kts
firebase-dataconnect/demo/gradle.properties
firebase-dataconnect/demo/gradle/wrapper/gradle-wrapper.properties
firebase-dataconnect/demo/github_actions_demo_test_cache_key.txt
- name: tool versions
continue-on-error: true
run: |
set +e -v
which java
java -version
which javac
javac -version
which node
node --version
${{ env.FDC_FIREBASE_COMMAND }} --version
./gradlew --version
- name: ./gradlew assemble test
run: |
set -x
./gradlew \
--no-daemon \
${{ (inputs.gradleInfoLog && '--info') || '' }} \
--profile \
-PdataConnect.minimalApp.firebaseCommand=${{ env.FDC_FIREBASE_COMMAND }} \
assemble test
- uses: actions/upload-artifact@v4
with:
name: apks
path: firebase-dataconnect/demo/build/**/*.apk
if-no-files-found: warn
compression-level: 0

- uses: actions/upload-artifact@v4
with:
name: gradle_build_reports
path: firebase-dataconnect/demo/build/reports/
if-no-files-found: warn
compression-level: 9

spotlessCheck:
continue-on-error: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: firebase-dataconnect/demo

- name: Create Cache Key Files
run: echo "h99ee4egfd" >github_actions_demo_spotless_cache_key.txt

- uses: actions/setup-java@v4
with:
java-version: ${{ env.FDC_JAVA_VERSION }}
distribution: temurin
cache: gradle
cache-dependency-path: |
firebase-dataconnect/demo/build.gradle.kts
firebase-dataconnect/demo/gradle.properties
firebase-dataconnect/demo/gradle/wrapper/gradle-wrapper.properties
firebase-dataconnect/demo/github_actions_demo_spotless_cache_key.txt
- name: tool versions
continue-on-error: true
run: |
set +e -v
which java
java -version
which javac
javac -version
./gradlew --version
- name: ./gradlew spotlessCheck
run: |
set -x
./gradlew \
--no-daemon \
${{ (inputs.gradleInfoLog && '--info') || '' }} \
spotlessCheck
1 change: 0 additions & 1 deletion firebase-dataconnect/demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ local.properties

*.log
*.hprof
/dataConnectGeneratedSources/
142 changes: 99 additions & 43 deletions firebase-dataconnect/demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ spotless {
}
}

@DisableCachingByDefault(because = "Code generation is very fast and not worth caching")
abstract class DataConnectGenerateSourcesTask : DefaultTask() {

@get:InputDirectory abstract val inputDirectory: DirectoryProperty
@get:InputDirectory abstract val inputDirectory: Property<DirectoryTree>

@get:OutputDirectory abstract val outputDirectory: DirectoryProperty
@get:Input abstract val firebaseToolsVersion: Property<String>

@get:Input abstract val firebaseCommand: Property<String>

@get:Internal abstract val nodeExecutableDirectory: DirectoryProperty
@get:Input @get:Optional abstract val nodeExecutableDirectory: Property<String>

@get:Internal abstract val firebaseCommand: Property<String>
@get:OutputDirectory abstract val outputDirectory: DirectoryProperty

@get:Internal abstract val workDirectory: DirectoryProperty

Expand All @@ -127,40 +130,26 @@ abstract class DataConnectGenerateSourcesTask : DefaultTask() {
@get:Inject protected abstract val fileSystemOperations: FileSystemOperations

@TaskAction
fun run(inputChanges: InputChanges) {
if (inputChanges.isIncremental) {
val onlyLogFilesChanged =
inputChanges.getFileChanges(inputDirectory).all { it.file.name.endsWith(".log") }
if (onlyLogFilesChanged) {
didWork = false
return
}
}

val inputDirectory: File = inputDirectory.get().asFile
fun run() {
val inputDirectory: File = inputDirectory.get().dir
val firebaseToolsVersion: String = firebaseToolsVersion.get()
val firebaseCommand: String = firebaseCommand.get()
val nodeExecutableDirectory: String? = nodeExecutableDirectory.orNull
val outputDirectory: File = outputDirectory.get().asFile
val nodeExecutableDirectory: File? = nodeExecutableDirectory.orNull?.asFile
val firebaseCommand: String? = firebaseCommand.orNull
val workDirectory: File = workDirectory.get().asFile

logger.info("inputDirectory: {}", inputDirectory.absolutePath)
logger.info("firebaseToolsVersion: {}", firebaseToolsVersion)
logger.info("firebaseCommand: {}", firebaseCommand)
logger.info("nodeExecutableDirectory: {}", nodeExecutableDirectory)
logger.info("outputDirectory: {}", outputDirectory.absolutePath)
logger.info("workDirectory: {}", workDirectory.absolutePath)

outputDirectory.deleteRecursively()
outputDirectory.mkdirs()
workDirectory.deleteRecursively()
workDirectory.mkdirs()

val newPath: String? =
if (nodeExecutableDirectory === null) {
null
} else {
val nodeExecutableDirectoryAbsolutePath = nodeExecutableDirectory.absolutePath
val oldPath = providerFactory.environmentVariable("PATH").orNull
if (oldPath === null) {
nodeExecutableDirectoryAbsolutePath
} else {
nodeExecutableDirectoryAbsolutePath + File.pathSeparator + oldPath
}
}

val logFile =
if (logger.isInfoEnabled) {
null
Expand All @@ -172,12 +161,15 @@ abstract class DataConnectGenerateSourcesTask : DefaultTask() {
logFile?.outputStream().use { logStream ->
execOperations.runCatching {
exec {
commandLine(firebaseCommand ?: "firebase", "--debug", "dataconnect:sdk:generate")
configureFirebaseCommand(
this,
firebaseCommand = firebaseCommand,
nodeExecutableDirectory = nodeExecutableDirectory,
path = providerFactory.environmentVariable("PATH").orNull,
)
args("--debug", "dataconnect:sdk:generate")
workingDir(inputDirectory)
isIgnoreExitValue = false
if (newPath !== null) {
environment("PATH", newPath)
}
if (logStream !== null) {
standardOutput = logStream
errorOutput = logStream
Expand All @@ -193,29 +185,59 @@ abstract class DataConnectGenerateSourcesTask : DefaultTask() {
throw exception
}
}

companion object {

fun configureFirebaseCommand(
execSpec: ExecSpec,
firebaseCommand: String,
nodeExecutableDirectory: String?,
path: String?,
) {
execSpec.setCommandLine(firebaseCommand)

val newPath: String? =
if (nodeExecutableDirectory === null) {
null
} else {
if (path === null) {
nodeExecutableDirectory
} else {
nodeExecutableDirectory + File.pathSeparator + path
}
}

if (newPath !== null) {
execSpec.environment("PATH", newPath)
}
}
}
}

@DisableCachingByDefault(
because = "Copying files is not worth caching, just like org.gradle.api.tasks.Copy"
)
abstract class CopyDirectoryTask : DefaultTask() {

@get:InputDirectory abstract val srcDirectory: DirectoryProperty
@get:InputDirectory abstract val srcDirectory: Property<DirectoryTree>

@get:OutputDirectory abstract val destDirectory: DirectoryProperty

@get:Inject protected abstract val fileSystemOperations: FileSystemOperations

@TaskAction
fun run() {
val srcDirectory: File = srcDirectory.get().asFile
val srcDirectoryTree: DirectoryTree = srcDirectory.get()
val destDirectory: File = destDirectory.get().asFile

logger.info("srcDirectory: {}", srcDirectory.absolutePath)
logger.info("srcDirectory: {}", srcDirectoryTree.dir.absolutePath)
logger.info("destDirectory: {}", destDirectory.absolutePath)

destDirectory.deleteRecursively()
destDirectory.mkdirs()

fileSystemOperations.copy {
from(srcDirectory)
from(srcDirectoryTree)
into(destDirectory)
}
}
Expand All @@ -231,14 +253,39 @@ run {
description =
"Run firebase dataconnect:sdk:generate to generate the Data Connect Kotlin SDK sources"

inputDirectory = projectDirectory.dir("firebase")
outputDirectory = projectDirectory.dir("dataConnectGeneratedSources")
inputDirectory =
fileTree(layout.projectDirectory.dir("firebase")).apply { exclude("**/*.log") }

outputDirectory = layout.buildDirectory.dir("dataConnect/generatedSources")

firebaseCommand =
project.providers
.gradleProperty("dataConnect.minimalApp.firebaseCommand")
.orElse("firebase")

nodeExecutableDirectory =
project.providers.gradleProperty("dataConnect.minimalApp.nodeExecutableDirectory").map {
projectDirectory.dir(it)
projectDirectory.dir(it).asFile.absolutePath
}

val path = providers.environmentVariable("PATH")
firebaseToolsVersion =
providers.provider {
providers
.exec {
DataConnectGenerateSourcesTask.configureFirebaseCommand(
this,
firebaseCommand = firebaseCommand.get(),
nodeExecutableDirectory = nodeExecutableDirectory.orNull,
path = path.orNull,
)
args("--version")
}
.standardOutput
.asText
.get()
.trim()
}
firebaseCommand = project.providers.gradleProperty("dataConnect.minimalApp.firebaseCommand")

workDirectory = layout.buildDirectory.dir(name)
}
Expand All @@ -247,13 +294,22 @@ run {
androidComponents.onVariants { variant ->
val variantNameTitleCase = variant.name[0].uppercase() + variant.name.substring(1)
val copyTaskName = "dataConnectCopy${variantNameTitleCase}GeneratedSources"
val objectFactory = objects
val copyTask =
tasks.register<CopyDirectoryTask>(copyTaskName) {
group = dataConnectTaskGroupName
description =
"Copy the generated Data Connect Kotlin SDK sources into the " +
"generated code directory for the \"${variant.name}\" variant."
srcDirectory = generateSourcesTask.flatMap { it.outputDirectory }
srcDirectory =
generateSourcesTask.flatMap {
it.outputDirectory.map { outputDirectory ->
objectFactory.fileTree().apply {
setDir(outputDirectory)
exclude("**/*.log")
}
}
}
}

variant.sources.java!!.addGeneratedSourceDirectory(copyTask, CopyDirectoryTask::destDirectory)
Expand Down
Loading
Loading