-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
613 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ jobs: | |
distribution: temurin | ||
cache: gradle | ||
|
||
- name: Update released.api | ||
- name: Export the api file | ||
run: | | ||
./gradlew updateApi --no-daemon | ||
./gradlew exportApi --no-daemon | ||
- name: Save released.api from master | ||
run: mv generativeai/released.api ~/released.api | ||
- name: Save exported.api from master | ||
run: mv generativeai/exported.api ~/exported.api | ||
|
||
- name: Checkout branch | ||
uses: actions/[email protected] | ||
|
@@ -36,7 +36,7 @@ jobs: | |
cache: gradle | ||
|
||
- name: Copy saved api to branch | ||
run: mv ~/released.api generativeai/released.api | ||
run: mv ~/exported.api generativeai/exported.api | ||
|
||
- name: Run api warning task | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
plugins/src/main/java/com/google/gradle/plugins/ReleasePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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 com.google.gradle.plugins | ||
|
||
import com.google.gradle.tasks.CopyFileTask | ||
import com.google.gradle.tasks.MakeReleaseNotesTask | ||
import com.google.gradle.tasks.VersionBumpTask | ||
import com.google.gradle.types.ModuleVersion | ||
import com.google.gradle.util.moduleVersion | ||
import com.google.gradle.util.outputFile | ||
import com.google.gradle.util.readFirstLine | ||
import java.io.File | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.named | ||
import org.gradle.kotlin.dsl.provideDelegate | ||
import org.gradle.kotlin.dsl.register | ||
|
||
/** | ||
* A Gradle plugin for preparing the release of a [Project]. | ||
* | ||
* Intended to be ran before running `publishAllPublicationsToMavenRepository`. | ||
* | ||
* Registers three tasks: | ||
* - `updateVersion` -> updates the project version declared in `gradle.properties` file, according | ||
* to the release notes. | ||
* - `createNewApiFile` -> creates a new `.api` file in the `api` directory for the release, | ||
* aligning with the current state of the public api; for future auditing. | ||
* - `prepareRelease` -> does everything needed to prepare a release; creates the release notes and | ||
* runs the above tasks. | ||
* | ||
* If any of these tasks are ran without changelog files present, the current version declared in | ||
* the `gradle.properties` file will be used instead. | ||
* | ||
* @see ApiPluginExtension | ||
* @see ChangelogPluginExtension | ||
*/ | ||
abstract class ReleasePlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
with(project) { | ||
val buildApi = tasks.named<BuildApiTask>("buildApi") | ||
val makeReleaseNotes = tasks.named<MakeReleaseNotesTask>("makeReleaseNotes") | ||
|
||
val releaseNotes = makeReleaseNotes.outputFile | ||
val releasingVersion = | ||
releaseNotes.map { parseReleaseVersion(it) }.orElse(project.moduleVersion) | ||
|
||
val updateVersion = | ||
tasks.register<VersionBumpTask>("updateVersion") { newVersion.set(releasingVersion) } | ||
|
||
val createNewApiFile = | ||
tasks.register<CopyFileTask>("createNewApiFile") { | ||
val newApiFile = releasingVersion.map { rootProject.file("api/$it.api") } | ||
|
||
source.set(buildApi.outputFile) | ||
dest.set(newApiFile) | ||
} | ||
|
||
tasks.register("prepareRelease") { | ||
group = "publishing" | ||
|
||
dependsOn(makeReleaseNotes, updateVersion, createNewApiFile) | ||
} | ||
} | ||
} | ||
|
||
private fun parseReleaseVersion(releaseNotes: File): ModuleVersion { | ||
val version = releaseNotes.readFirstLine().substringAfter("#").trim() | ||
|
||
return ModuleVersion.fromStringOrNull(version) | ||
?: throw RuntimeException("Invalid release notes version found") | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
plugins/src/main/java/com/google/gradle/tasks/CopyFileTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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 com.google.gradle.tasks | ||
|
||
import java.io.File | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Copy | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
/** | ||
* Copies a file (or directory) from one place to another. | ||
* | ||
* An alternative to the standard [Copy] task provided by gradle; that allows better interop with | ||
* providers, caching, directories, and individual files. | ||
* | ||
* If the file is a directory, all of its contents will be copied alongside it. | ||
* | ||
* ***If there is already a file or directory present at the destination, its contents will be | ||
* overwritten.*** | ||
* | ||
* @property source the file or directory to copy from | ||
* @property dest where to copy the file or directory to | ||
*/ | ||
abstract class CopyFileTask : DefaultTask() { | ||
@get:InputFile abstract val source: Property<File> | ||
|
||
@get:OutputFile abstract val dest: Property<File> | ||
|
||
@TaskAction | ||
fun create() { | ||
source.get().copyRecursively(dest.get(), overwrite = true) | ||
} | ||
} |
Oops, something went wrong.