Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/merge-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ jobs:
release-branch: release/${{ inputs.version }}
repo: ${{ matrix.repo }}
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}
deps-pattern: zenoh.*
deps-git-url: https://github.com/eclipse-zenoh/zenoh.git
deps-branch: main
deps-pattern: |
^zenoh(?!-flat$).*
^zenoh-flat$
deps-git-url: |
https://github.com/eclipse-zenoh/zenoh.git
https://github.com/eclipse-zenoh/zenoh-flat.git
deps-branch: |
main
main

- name: Checkout zenoh-c merge release branch
if: ${{ matrix.repo == 'eclipse-zenoh/zenoh-c' }}
Expand Down
29 changes: 29 additions & 0 deletions __tests__/set-git-branch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, test } from "@jest/globals";

import { parseDependencies } from "../src/set-git-branch";

describe("parseDependencies", () => {
test("parses aligned dependency mappings", () => {
const dependencies = parseDependencies(
["^zenoh(?!-flat$).*", "^zenoh-flat$"],
["https://github.com/eclipse-zenoh/zenoh.git", "https://github.com/eclipse-zenoh/zenoh-flat.git"],
["main", "main"],
);

expect(dependencies).toHaveLength(2);
expect(dependencies[0].pattern.test("zenoh-ext")).toBe(true);
expect(dependencies[0].pattern.test("zenoh-flat")).toBe(false);
expect(dependencies[0].gitUrl).toBe("https://github.com/eclipse-zenoh/zenoh.git");
expect(dependencies[1].pattern.test("zenoh-flat")).toBe(true);
expect(dependencies[1].gitUrl).toBe("https://github.com/eclipse-zenoh/zenoh-flat.git");
});

test("requires aligned dependency mappings", () => {
expect(() => parseDependencies(["zenoh.*"], ["https://example.com/zenoh.git"], [])).toThrow(
"deps-pattern, deps-git-url, and deps-branch must all be provided",
);
expect(() =>
parseDependencies(["zenoh.*"], ["https://example.com/zenoh.git", "https://example.com/other.git"], ["main"]),
).toThrow("deps-pattern, deps-git-url, and deps-branch must have the same number of lines");
});
Comment thread
milyin marked this conversation as resolved.
});
34 changes: 27 additions & 7 deletions dist/set-git-branch-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25183,6 +25183,13 @@ function getInput(name, options) {
}
return val.trim();
}
function getMultilineInput(name, options) {
const inputs = getInput(name, options).split("\n").filter((x) => x !== "");
if (options && options.trimWhitespace === false) {
return inputs;
}
return inputs.map((input) => input.trim());
}
function setFailed(message) {
process.exitCode = ExitCode.Failure;
error(message);
Expand Down Expand Up @@ -68077,6 +68084,19 @@ async function installBinaryCached(name) {
}

// src/set-git-branch.ts
function parseDependencies(patterns, gitUrls, branches) {
if (patterns.length === 0 || gitUrls.length === 0 || branches.length === 0) {
throw new Error("deps-pattern, deps-git-url, and deps-branch must all be provided");
}
if (patterns.length !== gitUrls.length || patterns.length !== branches.length) {
throw new Error("deps-pattern, deps-git-url, and deps-branch must have the same number of lines");
}
return patterns.map((pattern, index) => ({
pattern: new RegExp(pattern),
gitUrl: gitUrls[index],
branch: branches[index]
}));
}
function setup() {
const version3 = getInput("version", { required: true });
const releaseBranch = getInput("release-branch", { required: true });
Expand All @@ -68085,9 +68105,9 @@ function setup() {
const toolchain = getInput("toolchain", { required: false });
const githubToken = getInput("github-token", { required: true });
const githubUser = getInput("github-user");
const depsPattern = getInput("deps-pattern");
const depsGitUrl = getInput("deps-git-url");
const depsBranch = getInput("deps-branch");
const depsPatterns = getMultilineInput("deps-pattern");
const depsGitUrls = getMultilineInput("deps-git-url");
const depsBranches = getMultilineInput("deps-branch");
return {
version: version3,
releaseBranch,
Expand All @@ -68096,9 +68116,7 @@ function setup() {
toolchain: toolchain === "" ? "" : `+${toolchain}`,
githubToken,
githubUser: githubUser === "" ? "eclipse-zenoh-bot" : githubUser,
depsRegExp: depsPattern === "" ? void 0 : new RegExp(depsPattern),
depsGitUrl: depsGitUrl === "" ? void 0 : depsGitUrl,
depsBranch: depsBranch === "" ? void 0 : depsBranch
dependencies: parseDependencies(depsPatterns, depsGitUrls, depsBranches)
};
}
async function main(input) {
Expand All @@ -68113,7 +68131,9 @@ async function main(input) {
const pathsToCheck = [];
let path12;
for (path12 of cargoPaths) {
await setGitBranch(path12, input.depsRegExp, input.depsGitUrl, input.depsBranch);
for (const dependency of input.dependencies) {
await setGitBranch(path12, dependency.pattern, dependency.gitUrl, dependency.branch);
}
if (sh("git diff", { cwd: repo, check: false })) {
sh("find . -name 'Cargo.toml' | xargs git add", { cwd: repo });
sh(`git commit --message 'chore: Update git/branch ${path12}'`, { cwd: repo, env: gitEnv });
Expand Down
3 changes: 3 additions & 0 deletions set-git-branch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ inputs:
required: false
default: eclipse-zenoh-bot
deps-pattern:
description: "Multiline list of regular expressions for dependencies (one per line)"
required: true
deps-git-url:
description: "Multiline list of git URLs matching deps-pattern (one per line)"
required: true
deps-branch:
description: "Multiline list of branches matching deps-pattern (one per line)"
required: true
runs:
using: node24
Expand Down
39 changes: 29 additions & 10 deletions src/set-git-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@ export type Input = {
toolchain: string;
githubToken: string;
githubUser?: string;
depsRegExp: RegExp;
depsGitUrl: string;
depsBranch: string;
dependencies: Dependency[];
};

export type Dependency = {
pattern: RegExp;
gitUrl: string;
branch: string;
};

export function parseDependencies(patterns: string[], gitUrls: string[], branches: string[]): Dependency[] {
if (patterns.length === 0 || gitUrls.length === 0 || branches.length === 0) {
throw new Error("deps-pattern, deps-git-url, and deps-branch must all be provided");
}
if (patterns.length !== gitUrls.length || patterns.length !== branches.length) {
throw new Error("deps-pattern, deps-git-url, and deps-branch must have the same number of lines");
}

return patterns.map((pattern, index) => ({
pattern: new RegExp(pattern),
gitUrl: gitUrls[index],
branch: branches[index],
}));
}
Comment thread
milyin marked this conversation as resolved.

export function setup(): Input {
const version = core.getInput("version", { required: true });
const releaseBranch = core.getInput("release-branch", { required: true });
Expand All @@ -28,9 +47,9 @@ export function setup(): Input {
const toolchain = core.getInput("toolchain", { required: false });
const githubToken = core.getInput("github-token", { required: true });
const githubUser = core.getInput("github-user");
const depsPattern = core.getInput("deps-pattern");
const depsGitUrl = core.getInput("deps-git-url");
const depsBranch = core.getInput("deps-branch");
const depsPatterns = core.getMultilineInput("deps-pattern");
const depsGitUrls = core.getMultilineInput("deps-git-url");
const depsBranches = core.getMultilineInput("deps-branch");

return {
version,
Expand All @@ -40,9 +59,7 @@ export function setup(): Input {
toolchain: toolchain === "" ? "" : `+${toolchain}`,
githubToken,
githubUser: githubUser === "" ? "eclipse-zenoh-bot" : githubUser,
depsRegExp: depsPattern === "" ? undefined : new RegExp(depsPattern),
depsGitUrl: depsGitUrl === "" ? undefined : depsGitUrl,
depsBranch: depsBranch === "" ? undefined : depsBranch,
dependencies: parseDependencies(depsPatterns, depsGitUrls, depsBranches),
};
}

Expand All @@ -63,7 +80,9 @@ export async function main(input: Input) {
const pathsToCheck: string[] = [];
let path: string;
for (path of cargoPaths) {
await cargo.setGitBranch(path, input.depsRegExp, input.depsGitUrl, input.depsBranch);
for (const dependency of input.dependencies) {
await cargo.setGitBranch(path, dependency.pattern, dependency.gitUrl, dependency.branch);
}
if (sh("git diff", { cwd: repo, check: false })) {
sh("find . -name 'Cargo.toml' | xargs git add", { cwd: repo });
sh(`git commit --message 'chore: Update git/branch ${path}'`, { cwd: repo, env: gitEnv });
Expand Down
Loading