Skip to content

Commit fe1f27e

Browse files
committed
Automate more release steps
Add workflow to prepare the release. Tweak existing workflow to do the release on merge. Move version (and add release state) to a properties file to ease the automation. Update Gradle add-on plugin and build for the release automation. Document steps to release the add-on. Signed-off-by: thc202 <[email protected]>
1 parent b19a7f4 commit fe1f27e

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Prepare Release Add-on
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
prepare-release:
8+
name: Prepare Release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 0
14+
persist-credentials: false
15+
- name: Setup Java
16+
uses: actions/setup-java@v1
17+
with:
18+
java-version: 8
19+
- name: Prepare Release and Create Pull Request
20+
env:
21+
ZAPBOT_TOKEN: ${{ secrets.ZAPBOT_TOKEN }}
22+
run: ./gradlew createPullRequestRelease

.github/workflows/release-add-on.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@ name: Release Add-On
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches:
6+
- main
7+
paths:
8+
- 'gradle.properties'
79

810
jobs:
911
release:
1012
name: Build and Release Add-On
11-
if: github.actor == 'kingthorin' || github.actor == 'psiinon' || github.actor == 'thc202'
1213
runs-on: ubuntu-latest
1314
steps:
14-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
persist-credentials: false
19+
- name: Setup Java
20+
uses: actions/setup-java@v1
21+
with:
22+
java-version: 8
23+
- name: Generate Release State
24+
run: ./gradlew generateReleaseStateLastCommit
1525
- name: Build and Release Add-On
16-
uses: docker://openjdk:8
1726
env:
18-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19-
with:
20-
entrypoint: ./gradlew
21-
args: createReleaseFromGitHubRef
27+
ZAPBOT_TOKEN: ${{ secrets.ZAPBOT_TOKEN }}
28+
run: ./gradlew releaseAddOn

RELEASING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Release
2+
3+
The following steps should be followed to release the add-on:
4+
1. Run the workflow [Prepare Release Add-on](https://github.com/zaproxy/community-scripts/actions/workflows/prepare-release-add-on.yml),
5+
to prepare the release. It creates a pull request updating the version and changelog;
6+
2. Merge the pull request.
7+
8+
After merging the pull request the [Release Add-on](https://github.com/zaproxy/community-scripts/actions/workflows/release-add-on.yml) workflow
9+
will create the tag, create the release, trigger the update of the marketplace, and create a pull request preparing the next development iteration.

build.gradle.kts

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import org.zaproxy.gradle.addon.AddOnPlugin
21
import org.zaproxy.gradle.addon.AddOnStatus
2+
import org.zaproxy.gradle.addon.internal.model.ProjectInfo
3+
import org.zaproxy.gradle.addon.internal.model.ReleaseState
4+
import org.zaproxy.gradle.addon.internal.tasks.GenerateReleaseStateLastCommit
35
import org.zaproxy.gradle.addon.misc.ConvertMarkdownToHtml
4-
import org.zaproxy.gradle.addon.misc.CreateGitHubRelease
5-
import org.zaproxy.gradle.addon.misc.ExtractLatestChangesFromChangelog
66

77
plugins {
88
`java-library`
9-
id("org.zaproxy.add-on") version "0.5.0"
9+
id("org.zaproxy.add-on") version "0.6.0"
1010
id("com.diffplug.spotless") version "5.12.1"
1111
}
1212

1313
repositories {
1414
mavenCentral()
1515
}
1616

17-
version = "10"
1817
description = "Useful ZAP scripts written by the ZAP community."
1918

2019
val scriptsDir = layout.buildDirectory.dir("scripts")
@@ -112,33 +111,15 @@ spotless {
112111
}
113112
}
114113

115-
System.getenv("GITHUB_REF")?.let { ref ->
116-
if ("refs/tags/" !in ref) {
117-
return@let
118-
}
119-
120-
tasks.register<CreateGitHubRelease>("createReleaseFromGitHubRef") {
121-
val targetTag = ref.removePrefix("refs/tags/")
122-
val targetAddOnVersion = targetTag.removePrefix("v")
123-
124-
authToken.set(System.getenv("GITHUB_TOKEN"))
125-
repo.set(System.getenv("GITHUB_REPOSITORY"))
126-
tag.set(targetTag)
127-
128-
title.set(provider { "Version ${zapAddOn.addOnVersion.get()}" })
129-
bodyFile.set(tasks.named<ExtractLatestChangesFromChangelog>("extractLatestChanges").flatMap { it.latestChanges })
130-
131-
assets {
132-
register("add-on") {
133-
file.set(tasks.named<Jar>(AddOnPlugin.JAR_ZAP_ADD_ON_TASK_NAME).flatMap { it.archiveFile })
134-
}
135-
}
114+
val projectInfo = ProjectInfo.from(project)
115+
val generateReleaseStateLastCommit by tasks.registering(GenerateReleaseStateLastCommit::class) {
116+
projects.set(listOf(projectInfo))
117+
}
136118

137-
doFirst {
138-
val addOnVersion = zapAddOn.addOnVersion.get()
139-
require(addOnVersion == targetAddOnVersion) {
140-
"Version of the tag $targetAddOnVersion does not match the version of the add-on $addOnVersion"
141-
}
142-
}
119+
val releaseAddOn by tasks.registering {
120+
if (ReleaseState.read(projectInfo).isNewRelease()) {
121+
dependsOn("createRelease")
122+
dependsOn("handleRelease")
123+
dependsOn("createPullRequestNextDevIter")
143124
}
144125
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=10
2+
release=false

0 commit comments

Comments
 (0)