From 322cbf4868500e8ae8db303c9e629209a5dfb24a Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 16:07:55 +0100 Subject: [PATCH 1/6] fix: don't add git/branch to workspace deps --- dist/build-crates-debian-main.js | 5 +++-- dist/build-crates-standalone-main.js | 5 +++-- dist/bump-crates-main.js | 5 +++-- dist/publish-crates-cargo-main.js | 5 +++-- dist/publish-crates-debian-main.js | 5 +++-- dist/publish-crates-eclipse-main.js | 5 +++-- dist/publish-crates-github-main.js | 5 +++-- dist/publish-crates-homebrew-main.js | 5 +++-- dist/set-git-branch-main.js | 5 +++-- src/cargo.ts | 7 +++++-- 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/dist/build-crates-debian-main.js b/dist/build-crates-debian-main.js index cf136881..3b4bc14e 100644 --- a/dist/build-crates-debian-main.js +++ b/dist/build-crates-debian-main.js @@ -128159,8 +128159,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/build-crates-standalone-main.js b/dist/build-crates-standalone-main.js index b1fd8865..dfeedf77 100644 --- a/dist/build-crates-standalone-main.js +++ b/dist/build-crates-standalone-main.js @@ -128143,8 +128143,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/bump-crates-main.js b/dist/bump-crates-main.js index dc0ef5a6..10cdce6c 100644 --- a/dist/bump-crates-main.js +++ b/dist/bump-crates-main.js @@ -81394,8 +81394,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/publish-crates-cargo-main.js b/dist/publish-crates-cargo-main.js index 8c3fc3f3..0de7a4ff 100644 --- a/dist/publish-crates-cargo-main.js +++ b/dist/publish-crates-cargo-main.js @@ -81279,8 +81279,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/publish-crates-debian-main.js b/dist/publish-crates-debian-main.js index 1ba0e959..8a51c03a 100644 --- a/dist/publish-crates-debian-main.js +++ b/dist/publish-crates-debian-main.js @@ -128138,8 +128138,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/publish-crates-eclipse-main.js b/dist/publish-crates-eclipse-main.js index bace671e..f29b61bd 100644 --- a/dist/publish-crates-eclipse-main.js +++ b/dist/publish-crates-eclipse-main.js @@ -128219,8 +128219,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/publish-crates-github-main.js b/dist/publish-crates-github-main.js index f23b2edb..34cfc049 100644 --- a/dist/publish-crates-github-main.js +++ b/dist/publish-crates-github-main.js @@ -128219,8 +128219,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/publish-crates-homebrew-main.js b/dist/publish-crates-homebrew-main.js index bbf6ec7a..42c8fe92 100644 --- a/dist/publish-crates-homebrew-main.js +++ b/dist/publish-crates-homebrew-main.js @@ -128123,8 +128123,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/dist/set-git-branch-main.js b/dist/set-git-branch-main.js index 7de5c8e8..1e5ed2b4 100644 --- a/dist/set-git-branch-main.js +++ b/dist/set-git-branch-main.js @@ -81275,8 +81275,9 @@ async function setGitBranch(path, pattern, gitUrl, gitBranch) { } for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace"))) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } diff --git a/src/cargo.ts b/src/cargo.ts index a35b3136..c1848ed2 100644 --- a/src/cargo.ts +++ b/src/cargo.ts @@ -278,8 +278,11 @@ export async function setGitBranch(path: string, pattern: RegExp, gitUrl: string for (const dep in manifest.dependencies) { if (pattern.test(dep)) { - // if the dep has a path set, don't set the git/branch to avoid ambiguities - if (!toml.get(manifestPath, prefix.concat("dependencies", dep, "path"))) { + // if the dep has a path set or is part of workspace, don't set the git/branch to avoid ambiguities + if ( + !toml.get(manifestPath, prefix.concat("dependencies", dep, "path")) || + !toml.get(manifestPath, prefix.concat("dependencies", dep, "workspace")) + ) { await toml.set(manifestPath, prefix.concat("dependencies", dep, "git"), gitUrl); await toml.set(manifestPath, prefix.concat("dependencies", dep, "branch"), gitBranch); } From 4f83edbeb8871525a6f8aa1919b4ef37b559211f Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 17:38:46 +0100 Subject: [PATCH 2/6] fix: treat failure cases in pr creation - when pr fails because there's nothing to do - when pr fails because there's already a PR --- .github/workflows/merge-release-branch.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/merge-release-branch.yml b/.github/workflows/merge-release-branch.yml index 1d2d9765..23b86cdb 100644 --- a/.github/workflows/merge-release-branch.yml +++ b/.github/workflows/merge-release-branch.yml @@ -70,17 +70,27 @@ jobs: - name: Create PR id: cpr run: | - pr_url=$(gh pr create \ + output=$(gh pr create \ --title "chore: Merge release/${{ inputs.version }} into main" \ - --body "Open new development line" \ + --body ":warning: This needs to be a merge commit :warning:" \ --head ${{ steps.compute-branch.outputs.branch }} \ --base main \ --label internal \ -R ${{ matrix.repo }} \ - ) - echo "pull-request-operation=created" >> $GITHUB_OUTPUT - pr_number="${pr_url##*/pull/}" - echo "pull-request-number=$pr_number" >> $GITHUB_OUTPUT + ) || exit_code=$? + if [[ ${exit_code} == 0 ]]; then + echo "pull-request-operation=created" >> $GITHUB_OUTPUT + pr_number="${output##*/pull/}" + echo "pull-request-number=$pr_number" >> $GITHUB_OUTPUT + else + if [[ $output == *"No commits between"* ]]; then + exit 0 + elif [[ $output == *"pull request for branch"* ]]; then + echo "pull-request-operation=updated" + pr_number="${output##*/pull/}" + echo "pull-request-number=$pr_number" + fi + fi env: GH_TOKEN: ${{ secrets.BOT_TOKEN_WORKFLOW }} From c01189dbe1ee120e73f20e333ce0f47bc9190ad6 Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 17:43:41 +0100 Subject: [PATCH 3/6] fix: set GITHUB_OUTPUT and conditional --- .github/workflows/merge-release-branch.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/merge-release-branch.yml b/.github/workflows/merge-release-branch.yml index 23b86cdb..a3ba03ee 100644 --- a/.github/workflows/merge-release-branch.yml +++ b/.github/workflows/merge-release-branch.yml @@ -84,11 +84,12 @@ jobs: echo "pull-request-number=$pr_number" >> $GITHUB_OUTPUT else if [[ $output == *"No commits between"* ]]; then + echo "pull-request-operation=none" >> $GITHUB_OUTPUT exit 0 elif [[ $output == *"pull request for branch"* ]]; then - echo "pull-request-operation=updated" + echo "pull-request-operation=updated" >> $GITHUB_OUTPUT pr_number="${output##*/pull/}" - echo "pull-request-number=$pr_number" + echo "pull-request-number=$pr_number" >> $GITHUB_OUTPUT fi fi env: @@ -107,6 +108,6 @@ jobs: # GH_TOKEN: ${{ secrets.BOT_TOKEN_WORKFLOW }} - name: Add the PR as annotation to workflow run - if: ${{ steps.cpr.outputs.pull-request-operation == 'created' }} + if: ${{ contains(fromJSON('["created", "updated"]'), steps.cpr.outputs.pull-request-operation ) }} run: > echo "::notice:: Created PR: https://github.com/${{ matrix.repo }}/pull/${{ steps.cpr.outputs.pull-request-number }}" \ No newline at end of file From b9909fbc16d2879b10957b95cd93584167420e08 Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 17:53:09 +0100 Subject: [PATCH 4/6] fix: only add changes if they are there --- dist/set-git-branch-main.js | 18 ++++++++++-------- src/set-git-branch.ts | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/dist/set-git-branch-main.js b/dist/set-git-branch-main.js index 1e5ed2b4..f33399ea 100644 --- a/dist/set-git-branch-main.js +++ b/dist/set-git-branch-main.js @@ -81613,14 +81613,16 @@ async function main(input) { .filter(r => r); for (const path of cargoPaths) { await _cargo__WEBPACK_IMPORTED_MODULE_4__/* .setGitBranch */ .B0(path, input.depsRegExp, input.depsGitUrl, input.depsBranch); - (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git add .", { cwd: repo }); - (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: _config__WEBPACK_IMPORTED_MODULE_5__/* .gitEnv */ .B }); - (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`cargo check --manifest-path ${path}/Cargo.toml`); - (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git commit Cargo.lock --message 'chore: Update Cargo lockfile'", { - cwd: repo, - env: _config__WEBPACK_IMPORTED_MODULE_5__/* .gitEnv */ .B, - check: false, - }); + if ((0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git diff --quiet", { cwd: repo })) { + (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git add .", { cwd: repo }); + (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: _config__WEBPACK_IMPORTED_MODULE_5__/* .gitEnv */ .B }); + (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`cargo check --manifest-path ${path}/Cargo.toml`); + (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git commit Cargo.lock --message 'chore: Update Cargo lockfile'", { + cwd: repo, + env: _config__WEBPACK_IMPORTED_MODULE_5__/* .gitEnv */ .B, + check: false, + }); + } } (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git push --force ${remote} eclipse-zenoh-bot/post-release-${input.version}`, { cwd: repo }); await cleanup(input); diff --git a/src/set-git-branch.ts b/src/set-git-branch.ts index c232b70b..1e5815a7 100644 --- a/src/set-git-branch.ts +++ b/src/set-git-branch.ts @@ -56,15 +56,17 @@ export async function main(input: Input) { for (const path of cargoPaths) { await cargo.setGitBranch(path, input.depsRegExp, input.depsGitUrl, input.depsBranch); - sh("git add .", { cwd: repo }); - sh(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: gitEnv }); + if (sh("git diff --quiet", { cwd: repo })) { + sh("git add .", { cwd: repo }); + sh(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: gitEnv }); - sh(`cargo check --manifest-path ${path}/Cargo.toml`); - sh("git commit Cargo.lock --message 'chore: Update Cargo lockfile'", { - cwd: repo, - env: gitEnv, - check: false, - }); + sh(`cargo check --manifest-path ${path}/Cargo.toml`); + sh("git commit Cargo.lock --message 'chore: Update Cargo lockfile'", { + cwd: repo, + env: gitEnv, + check: false, + }); + } } sh(`git push --force ${remote} eclipse-zenoh-bot/post-release-${input.version}`, { cwd: repo }); From 253672b18396b69b24d5ec348de4d7e42d88dfce Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 18:17:11 +0100 Subject: [PATCH 5/6] fix: setup rust toolchain Avoids using the cargo from the runner and setup the toolchain to 1.75.0 so when the set-git-branch action runs, it uses the same toolchain as zenoh --- .github/workflows/merge-release-branch.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/merge-release-branch.yml b/.github/workflows/merge-release-branch.yml index a3ba03ee..329c3a81 100644 --- a/.github/workflows/merge-release-branch.yml +++ b/.github/workflows/merge-release-branch.yml @@ -46,6 +46,12 @@ jobs: - eclipse-zenoh/zenoh-ts - eclipse-zenoh/zenoh-dissector steps: + - name: Setup rust toolchain + if: ${{ !contains(fromJSON('["eclipse-zenoh/zenoh", "eclipse-zenoh/zenoh-pico", "eclipse-zenoh/zenoh-cpp"]'), matrix.repo) }} + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: 1.75.0 + - name: Update git/branch in release branch if: ${{ !contains(fromJSON('["eclipse-zenoh/zenoh", "eclipse-zenoh/zenoh-pico", "eclipse-zenoh/zenoh-cpp"]'), matrix.repo) }} uses: ZettaScaleLabs/ci/set-git-branch@set-git-branch-action From c6ee8fb6dc6e6b7c46e5d14491f5387c7efe6213 Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Wed, 12 Feb 2025 19:10:48 +0100 Subject: [PATCH 6/6] fix: can't use return value of sh() --- dist/set-git-branch-main.js | 2 +- src/set-git-branch.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/set-git-branch-main.js b/dist/set-git-branch-main.js index f33399ea..55767e74 100644 --- a/dist/set-git-branch-main.js +++ b/dist/set-git-branch-main.js @@ -81613,7 +81613,7 @@ async function main(input) { .filter(r => r); for (const path of cargoPaths) { await _cargo__WEBPACK_IMPORTED_MODULE_4__/* .setGitBranch */ .B0(path, input.depsRegExp, input.depsGitUrl, input.depsBranch); - if ((0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git diff --quiet", { cwd: repo })) { + if ((0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git diff", { cwd: repo, check: false })) { (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)("git add .", { cwd: repo }); (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: _config__WEBPACK_IMPORTED_MODULE_5__/* .gitEnv */ .B }); (0,_command__WEBPACK_IMPORTED_MODULE_3__.sh)(`cargo check --manifest-path ${path}/Cargo.toml`); diff --git a/src/set-git-branch.ts b/src/set-git-branch.ts index 1e5815a7..f8d70cd2 100644 --- a/src/set-git-branch.ts +++ b/src/set-git-branch.ts @@ -56,7 +56,7 @@ export async function main(input: Input) { for (const path of cargoPaths) { await cargo.setGitBranch(path, input.depsRegExp, input.depsGitUrl, input.depsBranch); - if (sh("git diff --quiet", { cwd: repo })) { + if (sh("git diff", { cwd: repo, check: false })) { sh("git add .", { cwd: repo }); sh(`git commit --message 'chore: Update git/branch ${path}/Cargo.toml'`, { cwd: repo, env: gitEnv });