Skip to content

Commit

Permalink
Move release process to GitHub Actions Workflow (pinterest#1740)
Browse files Browse the repository at this point in the history
* Migrate release to a new workflow

* fix email

* fix typo

* minor cleanup
  • Loading branch information
shashachu committed Dec 20, 2022
1 parent 08db766 commit 557c640
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 100 deletions.
17 changes: 10 additions & 7 deletions .announce
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ else
AUTOACCEPT=false
fi

PREVIOUS_VERSION=$(cat CHANGELOG.md | grep -E "## \[\d+[.]\d+[.]\d+\]" | awk '{gsub(/\[|\]/,"",$2); print $2}' | awk 'NR == 2')
PREVIOUS_VERSION=$(grep -E "## \[[0-9]+\.[0-9]+\.[0-9]+\]" CHANGELOG.md | awk '{gsub(/\[|\]/,"",$2); print $2}' | awk 'NR == 2')

if [ -z "$PREVIOUS_VERSION" ]; then
echo "Cannot find PREVIOUS_VERSION."
exit 1
fi

if [ "$VERSION" == "$PREVIOUS_VERSION" ]; then
echo "VERSION $VERSION equal to PREVIOUS_VERSION $PREVIOUS_VERSION"
exit 1
Expand All @@ -30,12 +36,12 @@ if [ "$(git status --porcelain=v1 docs/install/cli.md docs/install/integrations.
fi
fi

escape_for_sed() { echo $1 | sed -e 's/[]\/$*.^|[]/\\&/g'; }
escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; }

# update Docs

sed -i "" "s/$(escape_for_sed $PREVIOUS_VERSION)/$(escape_for_sed $VERSION)/g" docs/install/cli.md
sed -i "" "s/$(escape_for_sed $PREVIOUS_VERSION)/$(escape_for_sed $VERSION)/g" docs/install/integrations.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/cli.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/integrations.md
git --no-pager diff docs/install/cli.md docs/install/integrations.md

# ask for user confirmation
Expand All @@ -57,6 +63,3 @@ fi

# Make a separate branch because master branch is protected
git checkout --track origin/master -b $BRANCH && git commit -m "$COMMIT_MESSAGE" docs/install/cli.md docs/install/integrations.md && git push origin $BRANCH

open "https://github.com/pinterest/ktlint/compare/$BRANCH?expand=1"

32 changes: 21 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release (WIP)
name: Publish Release

on :
push :
Expand All @@ -9,9 +9,11 @@ jobs:
publish:
runs-on: ubuntu-latest
if: github.repository == 'pinterest/ktlint'

steps:
- uses: actions/checkout@v3
with:
ref: 'master'
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
Expand All @@ -24,8 +26,8 @@ jobs:
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }}
ORG_GRADLE_PROJECT_signingPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
ORG_GRADLE_PROJECT_signingKeyPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}

- name : Extract release notes
id : release_notes
uses : ffurrer2/extract-release-notes@v1
Expand All @@ -35,23 +37,31 @@ jobs:
uses : softprops/action-gh-release@v1
with :
draft: false
prerelease: true
prerelease: true # Remove this after testing
body : ${{ steps.release_notes.outputs.release_notes }}
files: |
ktlint/build/run/*
env :
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}

- name: Get version
id: get_version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}

run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: Announce Release
run: |
git config user.email "<>" |
git config user.name "Ktlint Release Workflow" |
./.announce -y
env:
VERSION: ${{ env.version }}

- name: Bump Homebrew Formula
uses: mislav/bump-homebrew-formula-action@v1
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TOKEN }}
with:
formula-name: ktlint
download-url: https://github.com/pinterest/ktlint/releases/download/${{ steps.get_version.outputs.version }}/ktlint
download-url: https://github.com/pinterest/ktlint/releases/download/${{ env.version }}/ktlint

26 changes: 8 additions & 18 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
# How to make new project release

### Required configuration

Add following information to your `$HOME/.gradle/gradle.properties` file:
```properties
# You Github access token
servers.github.privKey=github_token
# Signing GPG key id
signing.keyId=12345678
# Signing GPG key password
signing.password=some_password
# Path to GPG file to sync artifcats
signing.secretKeyRingFile=~/.gnupg/secring.gpg
```

### Publishing new release

1. Update `VERSION_NAME` with new release version in project root `gradle.properties`
2. Fill in `CHANGELOG.md` with related to new version changes.
3. Run `./gradlew publishNewRelease` to build, upload new artifacts, update KtLint version number on [CLI documentation](docs/install/cli.md) and [integrations documentation](docs/install/integrations.md) and [https://ktlint.github.io](https://ktlint.github.io) site.
4. Update Github release notes with info from `CHANGELOG.md`
1. Update `VERSION_NAME` with new release version in project root `gradle.properties`. Be sure to remove `-SNAPSHOT`
2. Update `CHANGELOG.md` to rename the `Unreleased` section to the new release name, following the `## [x.x.x] - YYYY-MM-DD` format.
3. Add the new release to the bottom of the `CHANGELOG.md` file.
4. Commit `gradle.properties` and `CHANGELOG.md`.
5. Add a tag with the new release version, and push it to remote. This will kick off the Release workflow.
6. Close and release the repo on Sonatype.
7. Find the `<release>-update-refs` branch in the repo (created by the `.announce` script) and merge it.
8. Update `gradle.properties` with the new `SNAPSHOT` version, and add a new empty `Unreleased` section to the top of `CHANGELOG.md` and commit.
5 changes: 5 additions & 0 deletions build-logic/src/main/kotlin/ktlint-publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ signing {
// See https://docs.gradle.org/current/userguide/signing_plugin.html#sec:using_gpg_agent how to configure it
// useGpgCmd()

val signingKeyId = System.getenv("ORG_GRADLE_PROJECT_signingKeyId")
val signingKey = System.getenv("ORG_GRADLE_PROJECT_signingKey")
val signingPassword = System.getenv("ORG_GRADLE_PROJECT_signingKeyPassword")
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)

sign(publishing.publications["maven"])
isRequired = !version.toString().endsWith("SNAPSHOT")
}
63 changes: 0 additions & 63 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import java.net.URL
import org.gradle.crypto.checksum.Checksum

plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.checksum)
alias(libs.plugins.shadow)
alias(libs.plugins.githubRelease)
}

val isKotlinDev: Boolean = project.hasProperty("isKotlinDev")
Expand Down Expand Up @@ -54,67 +52,6 @@ tasks.register<JavaExec>("ktlint") {
)
}

// Deployment tasks
val githubToken: String = if (project.hasProperty("servers.github.privKey")) {
project.property("servers.github.privKey").toString()
} else {
logger.warn("No github token specified")
""
}

tasks.githubRelease {
setReleaseAssets(
provider {
projects.ktlint.dependencyProject.tasks.named<Checksum>("shadowJarExecutableChecksum")
.map { it.outputDirectory.asFileTree.files.toTypedArray() }
},
)
}

githubRelease {
token(githubToken)
owner("pinterest")
repo("ktlint")
tagName(project.property("VERSION_NAME").toString())
releaseName(project.property("VERSION_NAME").toString())
targetCommitish("master")
overwrite(true)
dryRun(false)
body {
var changelog = project.file("CHANGELOG.md").readText()
changelog = changelog.substring(changelog.indexOf("## "))
// 1 in indexOf here to skip first "## [" occurence
changelog.substring(0, changelog.indexOf("## [", 1))
}
}

// Put "servers.github.privKey" in "$HOME/.gradle/gradle.properties".
val announceRelease by tasks.registering(Exec::class) {
group = "Help"
description = "Runs .announce script"
subprojects.filter { !it.name.contains("ktlint-ruleset-template") }.forEach { subproject ->
dependsOn(subproject.tasks.named("publishMavenPublicationToMavenCentralRepository"))
}

commandLine("./.announce", "-y")
environment("VERSION" to "${project.property("VERSION_NAME")}")
environment("GITHUB_TOKEN" to githubToken)
}

val homebrewBumpFormula by tasks.registering(Exec::class) {
group = "Help"
description = "Runs brew bump-forumula-pr"
commandLine("./.homebrew")
environment("VERSION" to "${project.property("VERSION_NAME")}")
dependsOn(tasks.githubRelease)
}

tasks.register<DefaultTask>("publishNewRelease") {
group = "Help"
description = "Triggers uploading new archives and publish announcements"
dependsOn(announceRelease, homebrewBumpFormula, tasks.githubRelease)
}

tasks.wrapper {
distributionSha256Sum = URL("$distributionUrl.sha256")
.openStream().use { it.reader().readText().trim() }
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ kotlinDev = "1.8.0-RC"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
githubRelease = "com.github.breadmoirai.github-release:2.4.1"
checksum = "org.gradle.crypto.checksum:1.4.0"
shadow = "com.github.johnrengelman.shadow:7.1.2"

Expand Down

0 comments on commit 557c640

Please sign in to comment.