From 484540d188f975fcffe1220164f157c459dca9dd Mon Sep 17 00:00:00 2001 From: Bukowa Date: Wed, 26 Jun 2024 17:13:19 +0200 Subject: [PATCH] tools(release): add `justfile` recipe to run `release-please` with custom git patches https://github.com/googleapis/release-please/pull/2320 Signed-off-by: Bukowa --- .github/.gitignore | 1 + ...strategies_for_rust_workspace_plugin.patch | 84 +++++++++++++++++++ justfile | 58 ++++++++++++- 3 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/patches/release-please/fix__use_strategies_for_rust_workspace_plugin.patch diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..ba49ce2 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +release-please diff --git a/.github/patches/release-please/fix__use_strategies_for_rust_workspace_plugin.patch b/.github/patches/release-please/fix__use_strategies_for_rust_workspace_plugin.patch new file mode 100644 index 0000000..5678a2c --- /dev/null +++ b/.github/patches/release-please/fix__use_strategies_for_rust_workspace_plugin.patch @@ -0,0 +1,84 @@ +Subject: [PATCH] fix: use strategies for rust workspace plugin +--- +Index: src/plugins/cargo-workspace.ts +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/src/plugins/cargo-workspace.ts b/src/plugins/cargo-workspace.ts +--- a/src/plugins/cargo-workspace.ts (revision 3895d8987cf194cb33a13b725a8380071917322f) ++++ b/src/plugins/cargo-workspace.ts (revision 2238df955e907c55c71a28d3149462a2df648941) +@@ -38,6 +38,9 @@ + import {PatchVersionUpdate} from '../versioning-strategy'; + import {CargoLock} from '../updaters/rust/cargo-lock'; + import {ConfigurationError} from '../errors'; ++import {Strategy} from '../strategy'; ++import {Commit} from '../commit'; ++import {Release} from '../release'; + + interface CrateInfo { + /** +@@ -79,6 +82,9 @@ + * into a single rust package. + */ + export class CargoWorkspace extends WorkspacePlugin { ++ private strategiesByPath: Record = {}; ++ private releasesByPath: Record = {}; ++ + protected async buildAllPackages( + candidates: CandidateReleasePullRequest[] + ): Promise<{ +@@ -252,6 +258,34 @@ + originalManifest, + updatedManifest + ); ++ ++ const updatedPackage = { ++ ...pkg, ++ version: version.toString(), ++ }; ++ ++ const strategy = this.strategiesByPath[updatedPackage.path]; ++ const latestRelease = this.releasesByPath[updatedPackage.path]; ++ const basePullRequest = strategy ++ ? await strategy.buildReleasePullRequest([], latestRelease, false, [], { ++ newVersion: version, ++ }) ++ : undefined; ++ ++ if (basePullRequest) { ++ return this.updateCandidate( ++ { ++ path: pkg.path, ++ pullRequest: basePullRequest, ++ config: { ++ releaseType: 'rust', ++ }, ++ }, ++ pkg, ++ updatedVersions ++ ); ++ } ++ + const pullRequest: ReleasePullRequest = { + title: PullRequestTitle.ofTargetBranch(this.targetBranch), + body: new PullRequestBody([ +@@ -367,6 +401,18 @@ + protected pathFromPackage(pkg: CrateInfo): string { + return pkg.path; + } ++ ++ async preconfigure( ++ strategiesByPath: Record, ++ _commitsByPath: Record, ++ _releasesByPath: Record ++ ): Promise> { ++ // Using preconfigure to siphon releases and strategies. ++ this.strategiesByPath = strategiesByPath; ++ this.releasesByPath = _releasesByPath; ++ ++ return strategiesByPath; ++ } + } + + function getChangelogDepsNotes( diff --git a/justfile b/justfile index 47210df..8fdd7ef 100644 --- a/justfile +++ b/justfile @@ -49,8 +49,8 @@ tauri *ARGS: [doc('build the tauri app for testing')] tauri-b-for-tests: #!/bin/bash - if [ -n "$VERBOSE" ]; then set -x; fi - set -euo pipefail + if [ -n "$TRACE" ]; then set -x; fi + set -euov pipefail just tauri build --bundles=none test -f $PATH_TAURI_RELEASE_BINARY @@ -78,7 +78,7 @@ webdriver-url: [windows] webdriver-download: init #!/bin/bash - if [ -n "$VERBOSE" ]; then set -x; fi + if [ -n "$TRACE" ]; then set -x; fi set -euo pipefail version=$(just browser-version) @@ -110,7 +110,7 @@ webdriver-download: init [unix] webdriver-download: #!/bin/bash - if [ -n "$VERBOSE" ]; then set -x; fi + if [ -n "$TRACE" ]; then set -x; fi set -euo pipefail if [ -n "$PATH_WEBDRIVER_BINARY" ] && [ -f $PATH_WEBDRIVER_BINARY ]; then echo "Webdriver found at: '$PATH_WEBDRIVER_BINARY'" @@ -164,6 +164,56 @@ clippy-fix extra="": fmt: cargo fmt -- +export RELEASE_PLEASE_REV := "ace2bd5dc778f83c33ad5dee6807db5d0afdba36" +export RELEASE_PLEASE_TOKEN := env_var('RELEASE_PLEASE_TOKEN') + +[group('release')] +[doc('cleans release-please dir')] +[confirm] +clean-release-please: + rm -rf .github/release-please + +[group('release')] +[doc('pulls and builds release-please with patches')] +build-release-please: + #!/bin/bash + if [ -n "$TRACE" ]; then set -x; fi + set -euov pipefail + cd .github/ + # clone only if the directory doesn't exist + [ -d release-please ] || git clone git@github.com:googleapis/release-please.git + cd release-please + git checkout $RELEASE_PLEASE_REV + # apply patches only if they haven't been applied + patch_files=$(ls ../patches/release-please/**.patch) + for patch_file in "${patch_files[@]}"; do + if git apply --check $patch_file; then + git apply $patch_file + fi + done + npm install + +[group('release')] +[doc('run PR with release-please')] +release-please-pr: + #!/bin/bash + set -euov pipefail + # if token is not set, then exit + if [ -z "$RELEASE_PLEASE_TOKEN" ]; then + echo "RELEASE_PLEASE_TOKEN is not set" + exit 1 + fi + cd .github/release-please + git checkout $RELEASE_PLEASE_REV + node ./build/src/bin/release-please.js release-pr \ + --repo-url=https://github.com/bukowa/ck3oop \ + --config-file=.github/release-please-config.json \ + --manifest-file=.github/.release-please-manifest.json \ + --token=$RELEASE_PLEASE_TOKEN \ + --monorepo-tags + +[group('release')] +[doc('mark correct release as latest')] release-mark-latest: #!/bin/bash release_id=$(