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
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.zaproxy.gradle.GitHubRepo
import org.zaproxy.gradle.GitHubUser
import org.zaproxy.gradle.HandleMainRelease
import org.zaproxy.gradle.HandleWeeklyRelease
import org.zaproxy.gradle.MainReleaseRepositoryDispatch
import org.zaproxy.gradle.UpdateAddOnZapVersionsEntries
import org.zaproxy.gradle.UpdateAndCreatePullRequestAddOnRelease
import org.zaproxy.gradle.UpdateDailyZapVersionsEntries
Expand Down Expand Up @@ -443,7 +444,7 @@ val updateZapMgmtScripts by tasks.registering(CreatePullRequest::class) {
mustRunAfter(handleMainRelease)
}

val handleSnapRelease by tasks.registering(HandleMainRelease::class) {
val handleSnapRelease by tasks.registering(MainReleaseRepositoryDispatch::class) {
releaseState.set(releaseStateData)

gitHubUser.set(ghUser)
Expand Down
22 changes: 4 additions & 18 deletions buildSrc/src/main/java/org/zaproxy/gradle/HandleMainRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,22 @@
package org.zaproxy.gradle;

import java.util.Map;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.zaproxy.gradle.ReleaseState.VersionChange;

/**
* Task that handles a main release, if any.
*
* <p>Sends a repository dispatch to release the main and nightly Docker images.
*/
public abstract class HandleMainRelease extends SendRepositoryDispatch {

@InputFile
public abstract RegularFileProperty getReleaseState();
public abstract class HandleMainRelease extends MainReleaseRepositoryDispatch {

@Input
public abstract Property<String> getEventTypeNightly();

@Override
void send() {
ReleaseState releaseState = ReleaseState.read(getReleaseState().getAsFile().get());
if (isNewMainRelease(releaseState)) {
super.send();
sendRepositoryDispatch(getEventTypeNightly().get(), Map.of());
}
}

private static boolean isNewMainRelease(ReleaseState releaseState) {
VersionChange mainRelease = releaseState.getMainRelease();
return mainRelease != null && mainRelease.isNewVersion();
protected void sendDispatch() {
super.sendDispatch();
sendRepositoryDispatch(getEventTypeNightly().get(), Map.of());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Zed Attack Proxy (ZAP) and its related class files.
*
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
*
* Copyright 2025 The ZAP Development Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.gradle;

import java.util.Map;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.zaproxy.gradle.ReleaseState.VersionChange;

/**
* A {@link SendRepositoryDispatch} that only runs on a main release.
*/
public abstract class MainReleaseRepositoryDispatch extends SendRepositoryDispatch {

@InputFile
public abstract RegularFileProperty getReleaseState();

@Override
void send() {
ReleaseState releaseState = ReleaseState.read(getReleaseState().getAsFile().get());
if (isNewMainRelease(releaseState)) {
sendDispatch();
}
}

protected void sendDispatch() {
super.send();
}

private static boolean isNewMainRelease(ReleaseState releaseState) {
VersionChange mainRelease = releaseState.getMainRelease();
return mainRelease != null && mainRelease.isNewVersion();
}
}