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
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,54 @@ Bundles use Maven coordinate names and include all artifacts of the selected pub
The selected publication's module metadata and adjacent signature are cleared before metadata generation, including plain `publishToMavenLocal`, publishing to other repositories, and snapshots. Metadata regenerates or restores from cache. Deleting its signature forces the publication signing task to re-sign every artifact; gpg-agent/pinentry may prompt on every publish even when signing previously stayed up to date. Disable generation with `enabled = false` to omit metadata. Skipping it with `onlyIf` while the POM advertises metadata fails before upload.

The publishing-script harness runs as part of `check` when Bash is available. Local builds without Bash skip it with a reason; CI requires it with `-PrequireShellHarness=true`.

### Upload a verified combined bundle

Run planning and `bundleAll` separately from the upload invocation. After testing and
reviewing the saved ZIP, configure the upload task with the ZIP and manifest SHA-256 values
from retained, reviewed evidence:

```groovy
releaseAll {
useExistingBundle = providers.gradleProperty('existing').isPresent()
expectedBundleSha256 = providers.gradleProperty('verifiedBundleSha256')
expectedManifestSha256 = providers.gradleProperty('verifiedManifestSha256')
}
```

Then run:

```sh
./gradlew releaseAll -Pexisting \
-PverifiedBundleSha256="$REVIEWED_BUNDLE_SHA256" \
-PverifiedManifestSha256="$REVIEWED_MANIFEST_SHA256"
```

This submits without rebuilding, signing or staging again. Existing-bundle mode requires
both digests; do not derive them from the mutable receipt at upload time. Each must match
both its receipt entry and the corresponding file. The verified manifest controls the
coordinates probed before upload and during polling in that upload invocation, so review
and retain it with the ZIP. A later resume trusts the manifest copy in `deployment.json`;
it ignores the reviewed digests and does not authenticate that journal copy. Protect the
retained journal from modification.

Digest presence and syntax are validated before any task runs. Digests are accepted only
in existing-bundle mode: normal uploads rebuild and re-sign artifacts, so an earlier ZIP's
digest generally cannot match. Digest properties also come from project/user
`gradle.properties` and `ORG_GRADLE_PROJECT_*` environment variables; remove or clear them
before a normal release. Upload evidence is ignored when `releaseAll` is absent from the
task graph, including plain checks, signing checks and bundle-only runs. Source/version
and saved manifest hashes are rechecked.

The uploader hashes and parses the same manifest bytes, and sends a private ZIP snapshot
checked against the verified digest. The bundle directory must be writable for snapshot
creation. Snapshots live beside the bundle, independently of the deployment journal
location. Cleanup failures emit a warning naming the path for manual removal after the
upload has stopped; after a process crash, remove leftover `.verified-upload-*`
directories there once no upload is running.

Requesting `bundleAll` and `releaseAll` together in existing-bundle mode is rejected,
including through task dependencies. `useExistingBundle` defaults to false, including
when assigned a provider with no value. When `resumeId` is set, resume takes priority:
`useExistingBundle`, `expectedBundleSha256` and `expectedManifestSha256` are ignored.
Resume remains status-only and does not require current build outputs.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@ package se.alipsa.gradle.plugin.release

/** One-attempt upload journaling and status-only recovery. */
class CombinedDeployment {
private static final org.gradle.api.logging.Logger LOGGER = org.gradle.api.logging.Logging.getLogger(CombinedDeployment)

/** Uploads once, persisting intent before HTTP and ID immediately after it. */
static Map submit(File record, File bundle, Map manifest, PublicationStatus availability, CentralPortalClient client) {
static Map submit(File record, File bundle, Map manifest, PublicationStatus availability, CentralPortalClient client, String verifiedBundleHash = '') {
if (record.exists()) throw new IllegalStateException('Deployment record exists; resume or reconcile it before a new upload')
manifest.selected.each { Map component ->
if (availability.published(new ReleaseCoordinate(component.groupId, component.artifactId, component.version), true)) {
throw new IllegalStateException("Component was published since planning: ${component.artifactId}")
}
}
Map state = [state: 'SUBMITTING', bundleHash: ReleaseChecksums.checksum(bundle, 'SHA-256'),
// Upload a private snapshot: later writes to the original ZIP cannot change request bytes.
File uploadDirectory
try {
uploadDirectory = java.nio.file.Files.createTempDirectory(bundle.absoluteFile.parentFile.toPath(), '.verified-upload-').toFile()
} catch (IOException failure) {
throw new IllegalStateException("Cannot create a verified upload snapshot beside ${bundle.absolutePath}; place the reviewed ZIP in a writable directory and point bundleFile there. No upload attempted", failure)
}
File snapshot = new File(uploadDirectory, bundle.name)
try {
String uploadHash
try {
java.nio.file.Files.copy(bundle.toPath(), snapshot.toPath())
uploadHash = ReleaseChecksums.checksum(snapshot, 'SHA-256')
} catch (IOException failure) {
throw new IllegalStateException("Cannot copy or read the verified upload snapshot for ${bundle.absolutePath}; check that the ZIP is readable and its directory has sufficient free space and write access. No upload attempted", failure)
}
if (verifiedBundleHash && uploadHash != verifiedBundleHash) {
throw new IllegalStateException('Bundle changed after verification; no upload attempted')
}
return uploadSnapshot(record, snapshot, manifest, client, uploadHash)
} finally {
[snapshot, uploadDirectory].each { File temporary ->
if (temporary.exists() && !temporary.delete()) {
LOGGER.warn("Could not remove verified upload temporary path {}; remove it manually after the upload has stopped", temporary.absolutePath)
}
}
}
}

private static Map uploadSnapshot(File record, File bundle, Map manifest, CentralPortalClient client, String uploadHash) {
Map state = [state: 'SUBMITTING', bundleHash: uploadHash,
manifest: manifest, created: java.time.Instant.now().toString()]
// Reserve the active journal atomically: two local invocations must not both submit.
record.parentFile.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,35 @@ final class CombinedReleaseRegistrar {
task.password.convention(shared.password)
task.portalFixture.convention(shared.portalFixture)
task.resumeId.convention('')
task.useExistingBundle.convention(false)
task.expectedBundleSha256.convention('')
task.expectedManifestSha256.convention('')
}
// Inspect resolved paths without realizing tasks. Reject before any task actions,
// including when planning is scheduled through dependencies or abbreviations.
// Rejected graphs cannot be reused to bypass validation on the next invocation.
String planPath = project.absoluteProjectPath('releaseAllPlan')
String releasePath = project.absoluteProjectPath('releaseAll')
String bundlePath = project.absoluteProjectPath('bundleAll')
project.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
if (graph.hasTask(planPath) && graph.hasTask(releasePath)) {
throw new GradleException('Do not request releaseAllPlan and releaseAll in the same invocation; review the saved manifest, then run :releaseAll separately')
}
if (graph.hasTask(releasePath)) {
ReleaseAllTask release = releaseAllTask.get()
release.validateDigestInputs()
if (!release.resumeId.getOrElse('') && release.useExistingBundle.getOrElse(false)) {
// Bind upload evidence only for an upload graph, never plain checks/bundling.
// This input is retained when the configuration cache stores the resolved graph.
guardTask.get().expectedManifestSha256.set(release.expectedManifestSha256)
}
}
if (graph.hasTask(releasePath) && graph.hasTask(bundlePath)) {
ReleaseAllTask release = releaseAllTask.get()
if (!release.resumeId.getOrElse('') && release.useExistingBundle.getOrElse(false)) {
throw new GradleException('Do not request bundleAll and releaseAll in the same invocation in existing-bundle mode; verify the saved ZIP, then run releaseAll separately')
}
}
}
def providers = new CombinedReleaseTasks(planTask, signingCheckTask, guardTask, prepareMavenTask, bundleAllTask, releaseAllTask)
CombinedReleaseExtension extension = objects.newInstance(CombinedReleaseExtension, shared, providers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ final class ModuleReleaseConfigurer {
task.wiredSelection.set(staging.map { it.selection })
}
extension.releaseAllTask.configure { task ->
if (!task.resumeId.getOrElse('')) task.dependsOn(extension.bundleAllTask)
if (!task.resumeId.getOrElse('')) {
task.dependsOn(task.useExistingBundle.getOrElse(false) ? extension.guardTask : extension.bundleAllTask)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ abstract class ReleaseAllTask extends DefaultTask {
@Input abstract Property<String> getPortalUrl()
@Input abstract Property<String> getRepositoryUrl()
@Input abstract Property<String> getResumeId()
/** Upload the saved ZIP without bundling; ignored when resumeId is set. */
@Input @Optional abstract Property<Boolean> getUseExistingBundle()
/** Reviewed SHA-256 anchor, required in existing-bundle mode; ignored during resume. */
@Input @Optional abstract Property<String> getExpectedBundleSha256()

/** Reviewed manifest anchor, required in existing-bundle mode; ignored during resume. */
@Input @Optional abstract Property<String> getExpectedManifestSha256()

/** Validates reviewed evidence inputs before any build tasks execute. */
void validateDigestInputs() {
if (resumeId.getOrElse('')) return
boolean existing = useExistingBundle.getOrElse(false)
[expectedBundleSha256: expectedBundleSha256.getOrElse(''),
expectedManifestSha256: expectedManifestSha256.getOrElse('')].each { String name, String value ->
if (value && !(value ==~ /[0-9a-fA-F]{64}/)) {
throw new IllegalStateException("${name} must be a 64-character hexadecimal SHA-256")
}
if (existing && !value) {
throw new IllegalStateException("Existing-bundle mode requires ${name} from reviewed evidence")
}
if (!existing && value) {
throw new IllegalStateException("${name} is supported only in existing-bundle mode; set useExistingBundle or remove the digest")
}
}
}

/** Checks source and availability before submitting, or resumes without building. */
@TaskAction
Expand All @@ -29,14 +54,35 @@ abstract class ReleaseAllTask extends DefaultTask {
String id = resumeId.getOrElse('')
File record = recordFile.get().asFile
if (!id) {
Map manifest = ReleaseManifest.read(manifestFile.get().asFile)
ReleaseManifest.guard(sourceDirectory.get().asFile, manifest)
validateDigestInputs()
String expected = expectedBundleSha256.getOrElse('').toLowerCase(Locale.ROOT)
String expectedManifest = expectedManifestSha256.getOrElse('').toLowerCase(Locale.ROOT)
[manifestFile.get().asFile, receiptFile.get().asFile, bundleFile.get().asFile].each { File required ->
if (!required.isFile()) {
String guidance = useExistingBundle.getOrElse(false) ?
'run releaseAllPlan and bundleAll separately before existing-bundle upload' :
'check that releaseAll and bundleAll use the same manifest, receipt and bundle paths'
throw new IllegalStateException("Prepared release file missing: ${required.name}; ${guidance}")
}
}
// Hash and parse the same bytes, so the probed graph is the reviewed manifest.
byte[] manifestBytes = manifestFile.get().asFile.bytes
String manifestHash = ReleaseChecksums.checksum(manifestBytes, 'SHA-256')
Map receipt = ReleaseManifest.read(receiptFile.get().asFile)
if (receipt.bundleHash != ReleaseChecksums.checksum(bundleFile.get().asFile, 'SHA-256') || receipt.manifestHash != ReleaseChecksums.checksum(manifestFile.get().asFile, 'SHA-256')) {
if (expectedManifest && (receipt.manifestHash != expectedManifest || manifestHash != expectedManifest)) {
throw new IllegalStateException('Manifest or receipt differs from expectedManifestSha256; no upload attempted')
}
Map manifest = new groovy.json.JsonSlurper().parse(manifestBytes) as Map
ReleaseManifest.guard(sourceDirectory.get().asFile, manifest)
String verifiedHash = ReleaseChecksums.checksum(bundleFile.get().asFile, 'SHA-256')
if (expected && (receipt.bundleHash != expected || verifiedHash != expected)) {
throw new IllegalStateException('Bundle or receipt differs from expectedBundleSha256; no upload attempted')
}
if (receipt.bundleHash != verifiedHash || receipt.manifestHash != manifestHash) {
throw new IllegalStateException('Bundle or manifest changed since validation; rebuild the bundle')
}
def status = new PublicationStatus(repositoryUrl: repositoryUrl.get(), portalUrl: portalUrl.get(), userName: userName.getOrElse(''), password: password.getOrElse(''), requireFixture: true, fixtureFile: portalFixture.get().asFile)
id = CombinedDeployment.submit(record, bundleFile.get().asFile, manifest, status, client).deploymentId
id = CombinedDeployment.submit(record, bundleFile.get().asFile, manifest, status, client, verifiedHash).deploymentId
}
CombinedDeployment.resume(record, id, client, { Map manifest ->
manifest.selected.every { Map p ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package se.alipsa.gradle.plugin.release

import java.security.MessageDigest

/** Shared streaming checksums for single and combined release archives. */
/** Shared checksums for single and combined release archives and records. */
class ReleaseChecksums {
/** Computes a Maven checksum without loading the artifact into memory. */
static String checksum(File file, String algorithm) {
Expand All @@ -14,4 +14,8 @@ class ReleaseChecksums {
}
digest.digest().encodeHex().toString()
}
/** Computes a checksum of already-read evidence bytes in the same lowercase hex format. */
static String checksum(byte[] bytes, String algorithm) {
MessageDigest.getInstance(algorithm).digest(bytes).encodeHex().toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ abstract class ReleaseSourceGuardTask extends DefaultTask {
@InputFile @PathSensitive(PathSensitivity.NONE) abstract RegularFileProperty getManifestFile()
@Internal abstract DirectoryProperty getSourceDirectory()
@Input abstract Property<String> getVersionsJson()
/** Optional reviewed manifest anchor, checked before source and selection diagnostics. */
@Input @Optional abstract Property<String> getExpectedManifestSha256()
@Input abstract org.gradle.api.provider.ListProperty<String> getModulePaths()
@Input abstract org.gradle.api.provider.ListProperty<String> getUnpublishedProjectPaths()

ReleaseSourceGuardTask() {
expectedManifestSha256.convention('')
modulePaths.convention([])
unpublishedProjectPaths.convention([])
outputs.upToDateWhen { false }
Expand All @@ -26,7 +29,12 @@ abstract class ReleaseSourceGuardTask extends DefaultTask {
/** Rejects stale manifests before any preparation task can run. */
@TaskAction
void guard() {
Map manifest = ReleaseManifest.read(manifestFile.get().asFile)
byte[] manifestBytes = manifestFile.get().asFile.bytes
String expected = expectedManifestSha256.getOrElse('').toLowerCase(Locale.ROOT)
if (expected && ReleaseChecksums.checksum(manifestBytes, 'SHA-256') != expected) {
throw new IllegalStateException('Manifest differs from expectedManifestSha256; no upload attempted')
}
Map manifest = new JsonSlurper().parse(manifestBytes) as Map
if (!modulePaths.get().empty && manifest.modulePaths != modulePaths.get()) {
throw new IllegalStateException('Configured modules changed; run releaseAllPlan again before bundling')
}
Expand Down
Loading
Loading