Skip to content

Commit

Permalink
Merge pull request #228 from thc202/build/rel-auto
Browse files Browse the repository at this point in the history
Automate more release steps
  • Loading branch information
psiinon authored Jun 11, 2021
2 parents b19a7f4 + fe1f27e commit 9b22bb1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/prepare-release-add-on.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Prepare Release Add-on

on:
workflow_dispatch:

jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 8
- name: Prepare Release and Create Pull Request
env:
ZAPBOT_TOKEN: ${{ secrets.ZAPBOT_TOKEN }}
run: ./gradlew createPullRequestRelease
25 changes: 16 additions & 9 deletions .github/workflows/release-add-on.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ name: Release Add-On

on:
push:
tags:
- 'v*'
branches:
- main
paths:
- 'gradle.properties'

jobs:
release:
name: Build and Release Add-On
if: github.actor == 'kingthorin' || github.actor == 'psiinon' || github.actor == 'thc202'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 8
- name: Generate Release State
run: ./gradlew generateReleaseStateLastCommit
- name: Build and Release Add-On
uses: docker://openjdk:8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
entrypoint: ./gradlew
args: createReleaseFromGitHubRef
ZAPBOT_TOKEN: ${{ secrets.ZAPBOT_TOKEN }}
run: ./gradlew releaseAddOn
9 changes: 9 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release

The following steps should be followed to release the add-on:
1. Run the workflow [Prepare Release Add-on](https://github.com/zaproxy/community-scripts/actions/workflows/prepare-release-add-on.yml),
to prepare the release. It creates a pull request updating the version and changelog;
2. Merge the pull request.

After merging the pull request the [Release Add-on](https://github.com/zaproxy/community-scripts/actions/workflows/release-add-on.yml) workflow
will create the tag, create the release, trigger the update of the marketplace, and create a pull request preparing the next development iteration.
45 changes: 13 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import org.zaproxy.gradle.addon.AddOnPlugin
import org.zaproxy.gradle.addon.AddOnStatus
import org.zaproxy.gradle.addon.internal.model.ProjectInfo
import org.zaproxy.gradle.addon.internal.model.ReleaseState
import org.zaproxy.gradle.addon.internal.tasks.GenerateReleaseStateLastCommit
import org.zaproxy.gradle.addon.misc.ConvertMarkdownToHtml
import org.zaproxy.gradle.addon.misc.CreateGitHubRelease
import org.zaproxy.gradle.addon.misc.ExtractLatestChangesFromChangelog

plugins {
`java-library`
id("org.zaproxy.add-on") version "0.5.0"
id("org.zaproxy.add-on") version "0.6.0"
id("com.diffplug.spotless") version "5.12.1"
}

repositories {
mavenCentral()
}

version = "10"
description = "Useful ZAP scripts written by the ZAP community."

val scriptsDir = layout.buildDirectory.dir("scripts")
Expand Down Expand Up @@ -112,33 +111,15 @@ spotless {
}
}

System.getenv("GITHUB_REF")?.let { ref ->
if ("refs/tags/" !in ref) {
return@let
}

tasks.register<CreateGitHubRelease>("createReleaseFromGitHubRef") {
val targetTag = ref.removePrefix("refs/tags/")
val targetAddOnVersion = targetTag.removePrefix("v")

authToken.set(System.getenv("GITHUB_TOKEN"))
repo.set(System.getenv("GITHUB_REPOSITORY"))
tag.set(targetTag)

title.set(provider { "Version ${zapAddOn.addOnVersion.get()}" })
bodyFile.set(tasks.named<ExtractLatestChangesFromChangelog>("extractLatestChanges").flatMap { it.latestChanges })

assets {
register("add-on") {
file.set(tasks.named<Jar>(AddOnPlugin.JAR_ZAP_ADD_ON_TASK_NAME).flatMap { it.archiveFile })
}
}
val projectInfo = ProjectInfo.from(project)
val generateReleaseStateLastCommit by tasks.registering(GenerateReleaseStateLastCommit::class) {
projects.set(listOf(projectInfo))
}

doFirst {
val addOnVersion = zapAddOn.addOnVersion.get()
require(addOnVersion == targetAddOnVersion) {
"Version of the tag $targetAddOnVersion does not match the version of the add-on $addOnVersion"
}
}
val releaseAddOn by tasks.registering {
if (ReleaseState.read(projectInfo).isNewRelease()) {
dependsOn("createRelease")
dependsOn("handleRelease")
dependsOn("createPullRequestNextDevIter")
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=10
release=false

0 comments on commit 9b22bb1

Please sign in to comment.