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
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,15 @@ The fallback cannot account for a conflicting task registered later.

### Version

By default, the plugin resolves and verifies the latest Embed Code release on
the first installation. Before reusing the executable in
`build/embed-code/latest`, it verifies the executable against the digest stored
during installation. This local check does not require another release or
checksum-metadata request. If the executable was modified, the plugin restores
it from the authenticated cached release asset, or fails safely when that asset
cannot be authenticated offline. Run `clean` or remove that directory to check
for a newer release. Changing the configured `version` selects a separate cache
entry. If that entry does not already contain a verified installation, the
plugin downloads and verifies the selected release while online.

To use a specific Embed Code application release, add its exact release tag to the extension:
Each plugin release has a default Embed Code version that was tested with it.
The executable is downloaded and verified on its first use. Before reusing it,
the plugin compares its digest with the one recorded during installation. This
local check does not require a network request. If the executable was modified,
the plugin restores it from the authenticated cached release asset, or fails
safely when that asset cannot be authenticated offline. Changing `version`
selects a separate cache entry.

To set the application version explicitly, use its exact release tag:

```kotlin
embedCode {
Expand All @@ -136,9 +133,7 @@ embedCode {
```

For CI, configure `githubToken` to avoid GitHub's unauthenticated API rate limit
during the initial resolution. Without `sha256`, the first online installation
resolves the asset digest from GitHub release metadata. Pin both `version` and
`sha256` to keep that initial installation tied to an immutable release.
during the initial checksum lookup.

## Development

Expand Down
18 changes: 18 additions & 0 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import io.spine.embedcode.gradle.BuildSettings
import io.spine.embedcode.gradle.dependency.Kotlin
import io.spine.embedcode.gradle.dependency.PluginPublish
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Sync
import org.gradle.plugin.compatibility.compatibility

plugins {
Expand All @@ -47,6 +49,22 @@ dependencies {
testRuntimeOnly(gradleApi())
}

val embedCodeAppVersion = rootProject.extra["embedCodeAppVersion"] as String
val generateEmbedCodeVersion = tasks.register<Sync>("generateEmbedCodeVersion") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pattern for baking in the default version. One hardening opportunity now that the default version is fixed at plugin-build time: the default install path (default version, default downloadBaseUrl, no sha256) still resolves the asset digest from api.github.com on first install via resolveTrustedAssetSha256. That's an unauthenticated GitHub API call, and it's the most common path — on shared CI runner IPs it can hit the 60/hour limit and fail a clean build for reasons unrelated to the user's config.

Since this task already knows the default version, consider also generating the default per-platform SHA-256 digests into EmbedCodeVersionDefaults.kt (fetched at plugin-build time and baked in), and short-circuiting the metadata request when version == default and the user configured no sha256. That would make the default path verify without any GitHub API call at all. More build machinery, so reasonable to defer — but it closes the last unauthenticated-API dependency for the common case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To resolve issue with github rate limit it is possible to provide the GitHub authentication, which will bypass unauth limit.

description = "Generates the default Embed Code application version."
inputs.property("embedCodeAppVersion", embedCodeAppVersion)
from(layout.projectDirectory.dir("src/main/templates")) {
filter<ReplaceTokens>(
"tokens" to mapOf("embedCodeAppVersion" to embedCodeAppVersion),
)
}
into(layout.buildDirectory.dir("generated/sources/embedCodeVersion/kotlin"))
}

kotlin.sourceSets.named("main") {
kotlin.srcDir(generateEmbedCodeVersion)
}

val functionalTestSourceSet = sourceSets.create("functionalTest")
functionalTestSourceSet.compileClasspath += sourceSets.main.get().output
functionalTestSourceSet.runtimeClasspath += sourceSets.main.get().output
Expand Down
Loading