Skip to content

Commit

Permalink
tools(release): add justfile recipe to run release-please with cu…
Browse files Browse the repository at this point in the history
…stom git patches

googleapis/release-please#2320

Signed-off-by: Bukowa <gitbukowa@gmail.com>
  • Loading branch information
bukowa committed Jun 26, 2024
1 parent 56a3171 commit 147af64
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release-please
Original file line number Diff line number Diff line change
@@ -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<CrateInfo> {
+ private strategiesByPath: Record<string, Strategy> = {};
+ private releasesByPath: Record<string, Release> = {};
+
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<string, Strategy>,
+ _commitsByPath: Record<string, Commit[]>,
+ _releasesByPath: Record<string, Release>
+ ): Promise<Record<string, Strategy>> {
+ // Using preconfigure to siphon releases and strategies.
+ this.strategiesByPath = strategiesByPath;
+ this.releasesByPath = _releasesByPath;
+
+ return strategiesByPath;
+ }
}

function getChangelogDepsNotes(
58 changes: 54 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'"
Expand Down Expand Up @@ -164,6 +164,56 @@ clippy-fix extra="":
fmt:
cargo fmt --

export RELEASE_PLEASE_REV := "ace2bd5dc778f83c33ad5dee6807db5d0afdba36"
export RELEASE_PLEASE_TOKEN := env_var_or_default('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=$(
Expand Down

0 comments on commit 147af64

Please sign in to comment.