Skip to content
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

DNM, debugging CI issues #743

Closed
wants to merge 5 commits into from
Closed
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
236 changes: 2 additions & 234 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs :
check-latest : true

- name : Test on Ubuntu
run : ./gradlew assemble test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }}
run : ./gradlew -p compiler assemble test --tests 'com.squareup.anvil.compiler.codegen.ContributesMultibindingGeneratorTest.a contributed multibinding can be generated*' --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }}

- name : Upload Test Results
uses : actions/upload-artifact@v3
Expand Down Expand Up @@ -56,243 +56,11 @@ jobs :
# Expressions in Github actions are limited. If there would be an if expression, then we
# wouldn't need to duplicate the next step and depending on the OS enable / disable them.
- name : Test on Windows
run : ./gradlew.bat assemble test --no-build-cache --no-daemon --stacktrace -Doverride_config-fullTestRun=false
run : ./gradlew.bat -p compiler assemble test --tests 'com.squareup.anvil.compiler.codegen.ContributesMultibindingGeneratorTest.a contributed multibinding can be generated*' --no-build-cache --no-daemon --stacktrace -Doverride_config-fullTestRun=false

- name : Upload Test Results
uses : actions/upload-artifact@v3
if : ${{ failure() }}
with :
name : test-results-windows
path : ./**/build/reports/tests/

ktlint :
runs-on : ubuntu-latest
timeout-minutes : 15

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : KtLint
run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace && ./gradlew -p buildSrc ktlintCheck --no-build-cache --no-daemon --stacktrace

lint :
runs-on : ubuntu-latest
timeout-minutes : 15

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Android Lint
run : ./gradlew lint --no-build-cache --no-daemon --stacktrace

- name : Upload Lint Results
uses : actions/upload-artifact@v3
if : ${{ failure() }}
with :
name : lint-results
path : ./**/build/reports/lint-results.html

publish-maven-local :
runs-on : ubuntu-latest
timeout-minutes : 15

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Publish to Maven Local
run : ./gradlew clean publishToMavenLocal --no-build-cache --no-daemon --stacktrace --no-parallel && cd gradle-plugin && ./gradlew clean publishToMavenLocal --no-build-cache --no-daemon --stacktrace && cd ..

publish-snapshot :
runs-on : ubuntu-latest
if : github.repository == 'square/anvil' && github.ref == 'refs/heads/main'
timeout-minutes : 25
needs :
- test-ubuntu
- build-gradle-plugin
- gradle-wrapper-validation
- publish-maven-local

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Publish Snapshots 1.9
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}

# TODO: Remove when we drop Kotlin 1.8 support
- name : Publish Snapshots 1.8
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Doverride_kotlin=1.8.22 -PVERSION_NAME=2.4.8-1-8-SNAPSHOT && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=1.8.22 -PVERSION_NAME=2.4.8-1-8-SNAPSHOT && cd ..
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}

build-gradle-plugin :
runs-on : ubuntu-latest
defaults :
run :
working-directory : gradle-plugin

timeout-minutes : 15

strategy :
# Run all tasks, even if some fail. Note that they don't share an output, some tasks overlap
# which is expected. If they need to share their outputs, then we need a proper caching
# solution.
fail-fast : false
matrix :
kotlin-version : [ 1.8.22, 1.9.0 ]
agp-version : [ 7.1.1, 7.2.0, 7.3.1 ]

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Test Gradle Plugin
run : ./gradlew assemble test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_agp=${{ matrix.agp-version }}

- name : Upload Test Results
uses : actions/upload-artifact@v3
if : ${{ failure() }}
with :
# Use the Kotlin version to prevent overrides.
name : test-results-gradle-plugin-${{ matrix.kotlin-version }}-${{ matrix.agp-version }}
path : ./**/build/reports/tests/

ktlint-gradle-plugin :
runs-on : ubuntu-latest
defaults :
run :
working-directory : gradle-plugin

timeout-minutes : 15

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : KtLint Gradle Plugin
run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace

kapt-for-dagger-factories :
runs-on : ubuntu-latest
timeout-minutes : 25

strategy :
# Run all tasks, even if some fail. Note that they don't share an output, some tasks overlap
# which is expected. If they need to share their outputs, then we need a proper caching
# solution.
fail-fast : false
matrix :
kotlin-version : [ 1.8.22, 1.9.0 ]

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Run integration tests
run : ./gradlew -p integration-tests test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false

- name : Build the sample
run : ./gradlew :sample:app:assembleDebug --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_config-generateDaggerFactoriesWithAnvil=false

- name : Upload Test Results
uses : actions/upload-artifact@v3
if : ${{ failure() }}
with :
# Use the Kotlin version to prevent overrides.
name : test-results-kapt-${{ matrix.kotlin-version }}
path : ./**/build/reports/tests/

instrumentation-tests :
name : Instrumentation tests
runs-on : macos-latest
timeout-minutes : 20
strategy :
# Allow tests to continue on other devices if they fail on one device.
fail-fast : false
matrix :
api-level :
# Consider other devices in case it's needed.
#- 24
- 29
steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : Instrumentation Tests
uses : reactivecircus/android-emulator-runner@v2
with :
api-level : ${{ matrix.api-level }}
target : default
arch : x86_64
script : ./gradlew connectedCheck --no-build-cache --no-daemon --stacktrace

- name : Upload results
uses : actions/upload-artifact@v3
with :
name : insrumentation-test-results
path : ./**/build/reports/androidTests/connected/**

gradle-wrapper-validation :
name : "Validate the Gradle Wrapper"
runs-on : ubuntu-latest
timeout-minutes : 15
steps :
- uses : actions/checkout@v3
- uses : gradle/wrapper-validation-action@v1

build-benchmark-project :
runs-on : ubuntu-latest
timeout-minutes : 25

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : "Generate Project"
run : ./gradlew :createBenchmarkProject

- name : "Build Benchmark Project"
run : ./gradlew :benchmark:app:assemble
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ public interface AnvilApplicabilityChecker {
* will only be called _once_.
*/
public fun isApplicable(context: AnvilContext): Boolean

public companion object {
/** Returns an instance that always returns true. */
public fun always(): AnvilApplicabilityChecker = Always
}

private object Always : AnvilApplicabilityChecker {
override fun isApplicable(context: AnvilContext): Boolean = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,7 @@ fun simpleCodeGenerator(
mapper.invoke(this, it)
}
.map { content ->
val packageName = content.lines()
.map { it.trim() }
.firstNotNullOfOrNull { line ->
line
.takeIf { it.startsWith("package ") }
?.substringAfter("package ")
}
?: "tempPackage"

val fileName = content.lines()
.map { it.trim() }
.firstNotNullOfOrNull { line ->
// Try finding the class name.
line
.takeIf { it.startsWith("class ") || it.contains(" class ") }
?.substringAfter("class ")
?.trim()
?.substringBefore(" ")
?: line
// Check for interfaces, too.
.takeIf { it.startsWith("interface ") || it.contains(" interface ") }
?.substringAfter("interface ")
?.trim()
?.substringBefore(" ")
}
?: "NewFile${counter++}"
val (packageName, fileName) = parseSimpleFileContents(content)

createGeneratedFile(
codeGenDir = codeGenDir,
Expand All @@ -65,3 +40,48 @@ fun simpleCodeGenerator(
.toList()
}
}

/**
* Represents the metadata of a file that is generated by [simpleCodeGenerator].
*/
data class SimpleFileContents(
val packageName: String,
val fileName: String,
)

/**
* Parses [SimpleFileContents] metadata from a given source [content].
*/
fun parseSimpleFileContents(content: String): SimpleFileContents {
val packageName = content.lines()
.map { it.trim() }
.firstNotNullOfOrNull { line ->
line
.takeIf { it.startsWith("package ") }
?.substringAfter("package ")
}
?: "tempPackage"

val fileName = content.lines()
.map { it.trim() }
.firstNotNullOfOrNull { line ->
// Try finding the class name.
line
.takeIf { it.startsWith("class ") || it.contains(" class ") }
?.substringAfter("class ")
?.trim()
?.substringBefore(" ")
?: line
// Check for interfaces, too.
.takeIf { it.startsWith("interface ") || it.contains(" interface ") }
?.substringAfter("interface ")
?.trim()
?.substringBefore(" ")
}
?: "NewFile${counter++}"

return SimpleFileContents(
packageName = packageName,
fileName = fileName,
)
}
Loading
Loading