Skip to content

Commit

Permalink
Merge pull request #273 from ZettaScaleLabs/set-git-branch-action
Browse files Browse the repository at this point in the history
Improvements to set-git-branch action
  • Loading branch information
kydos authored Feb 12, 2025
2 parents 9ad9fc3 + c6ee8fb commit d0dfe74
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 43 deletions.
31 changes: 24 additions & 7 deletions .github/workflows/merge-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,17 +76,28 @@ 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
echo "pull-request-operation=none" >> $GITHUB_OUTPUT
exit 0
elif [[ $output == *"pull request for branch"* ]]; then
echo "pull-request-operation=updated" >> $GITHUB_OUTPUT
pr_number="${output##*/pull/}"
echo "pull-request-number=$pr_number" >> $GITHUB_OUTPUT
fi
fi
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN_WORKFLOW }}

Expand All @@ -97,6 +114,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 }}"
5 changes: 3 additions & 2 deletions dist/build-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/build-crates-standalone-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/bump-crates-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/publish-crates-cargo-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/publish-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/publish-crates-eclipse-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/publish-crates-github-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions dist/publish-crates-homebrew-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 13 additions & 10 deletions dist/set-git-branch-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -81612,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", { 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`);
(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);
Expand Down
7 changes: 5 additions & 2 deletions src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 10 additions & 8 deletions src/set-git-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", { cwd: repo, check: false })) {
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 });
Expand Down

0 comments on commit d0dfe74

Please sign in to comment.