Skip to content

Commit

Permalink
fix: update cargo.toDebianVersion to handle cmake (#234)
Browse files Browse the repository at this point in the history
* fix: update cargo.toDebianVersion to handle cmake

For cmake versions we have to use the tweak version component to
differentiate between release candidate packages.

* chore: lint

* fix: camelCase and add ~pre. prefix

* retrigger ci

* chore: add ci status check
  • Loading branch information
diogomatsubara authored Oct 17, 2024
1 parent a8374c1 commit 4c916ea
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 19 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ jobs:

- name: Check that dist/ is correctly generated
run: git diff --quiet HEAD -- dist

# NOTE: In GitHub repository settings, the "Require status checks to pass
# before merging" branch protection rule ensures that commits are only merged
# from branches where specific status checks have passed. These checks are
# specified manually as a list of workflow job names. Thus we use this extra
# job to signal whether all CI checks have passed.
ci:
name: CI status checks
runs-on: ubuntu-latest
needs: main
if: always()
steps:
- name: Check whether all jobs pass
run: echo '${{ toJson(needs) }}' | jq -e 'all(.result == "success")'
12 changes: 11 additions & 1 deletion __tests__/cargo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,21 @@ describe("cargo", () => {
const tmp = await downloadGitHubRepo("eclipse-zenoh/zenoh", SHA_ZENOH);

const version = "1.2.3-beta.1";
const debian_version = "1.2.3~beta.1-1";
await cargo.bumpDependencies(tmp, /zenoh.*/, version);

expect(toml.get(`${tmp}/Cargo.toml`, ["workspace", "dependencies", "zenoh", "version"])).toEqual(version);
expect(toml.get(`${tmp}/zenoh/Cargo.toml`, ["package", "metadata", "deb", "depends"])).toEqual(
`zenohd (=${version}), zenoh-plugin-rest (=${version}), zenoh-plugin-storage-manager (=${version})`,
`zenohd (=${debian_version}), zenoh-plugin-rest (=${debian_version}), zenoh-plugin-storage-manager (=${debian_version})`,
);
});

test("toDebianVersion()", async () => {
expect(cargo.toDebianVersion("1.0.0.0")).toEqual("1.0.0~dev-1");
expect(cargo.toDebianVersion("1.0.0.11")).toEqual("1.0.0~pre.11-1");
expect(cargo.toDebianVersion("1.0.0-rc.1")).toEqual("1.0.0~rc.1-1");
expect(cargo.toDebianVersion("1.0.0")).toEqual("1.0.0");
expect(cargo.toDebianVersion("1.0.0.1")).toEqual("1.0.0~pre.1-1");
expect(cargo.toDebianVersion("1.0.0.1", 2)).toEqual("1.0.0~pre.1-2");
});
});
22 changes: 20 additions & 2 deletions dist/build-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127537,8 +127537,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/build-crates-standalone-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127521,8 +127521,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/bump-crates-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81243,8 +81243,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/publish-crates-cargo-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81132,8 +81132,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/publish-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127516,8 +127516,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/publish-crates-eclipse-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127597,8 +127597,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/publish-crates-github-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127597,8 +127597,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
22 changes: 20 additions & 2 deletions dist/publish-crates-homebrew-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127501,8 +127501,26 @@ function buildDebian(path, target, version) {
* @returns Modified version.
*/
function toDebianVersion(version, revision) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
}
else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
}
else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}
/**
* Check if Package is already published in crates.io
Expand Down
20 changes: 18 additions & 2 deletions src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,24 @@ export function buildDebian(path: string, target: string, version: string) {
* @returns Modified version.
*/
export function toDebianVersion(version: string, revision?: number): string {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
return `${version.replace("-", "~")}-${revision ?? 1}`;
let debVersion = version;
// Check if version is semver or cmake version
if (version.includes("-")) {
// HACK(fuzzypixelz): This is an oversimplification of the Debian Policy
debVersion = `${version.replace("-", "~")}-${revision ?? 1}`;
} else {
// check cmake version has tweak component
if (version.split(".").length == 4) {
if (version.endsWith(".0")) {
const pos = version.lastIndexOf(".0");
debVersion = `${version.substring(0, pos)}~dev-${revision ?? 1}`;
} else if (parseInt(version.substring(version.lastIndexOf(".") + 1)) > 0) {
const pos = version.lastIndexOf(".");
debVersion = `${version.substring(0, pos)}~pre.${version.substring(pos + 1)}-${revision ?? 1}`;
}
}
}
return `${debVersion}`;
}

/**
Expand Down

0 comments on commit 4c916ea

Please sign in to comment.