Merge branch 'main' into write-results-to-a-file

This commit is contained in:
Grant Birkinbine 2023-12-13 10:04:14 -07:00 committed by GitHub
commit f88aee4953
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1116 additions and 602 deletions

View file

@ -0,0 +1,9 @@
---
"wrangler-action": patch
---
Fixes issues with semver comparison, where version parts were treated lexicographically instead of numerically.
Bulk secret uploading was introduced in wrangler `3.4.0`, and this action tries to check if the version used is greater than `3.4.0`, and then if so, using the new bulk secret API which is faster. Due to a bug in the semver comparison, `3.19.0` was being considered less than `3.4.0`, and then using an older and slower method for uploading secrets.
Now the semver comparison is fixed, the faster bulk method is used for uploading secrets when available.

1655
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -29,17 +29,18 @@
"check": "prettier --check ."
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@cloudflare/workers-types": "^4.20230814.0",
"@types/node": "^20.5.0",
"@vercel/ncc": "^0.36.1",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
"@cloudflare/workers-types": "^4.20231121.0",
"@types/node": "^20.10.4",
"@vercel/ncc": "^0.38.1",
"prettier": "^3.1.0",
"semver": "^7.5.4",
"typescript": "^5.3.3",
"vitest": "^1.0.3"
}
}

View file

@ -26,7 +26,30 @@ describe("checkWorkingDirectory", () => {
expect(() =>
checkWorkingDirectory("/does/not/exist"),
).toThrowErrorMatchingInlineSnapshot(
'"Directory /does/not/exist does not exist."',
`[Error: Directory /does/not/exist does not exist.]`,
);
});
});
describe("semverCompare", () => {
test.each([
["1.2.3", "1.2.3", false],
["1.2.2", "1.2.3", true],
["2.0.0", "3.0.0", true],
["3.1.0", "3.1.1", true],
["3.1.0", "3.5.0", true],
["3.1.0", "3.10.0", true],
["3.1.0", "3.15.0", true],
["3.10.0", "3.1.0", false],
["3.20.0", "3.2.0", false],
["3.1.0", "latest", true],
["4.0.0", "latest", true],
])(
"should semver compare %s vs %s correctly, expecting %s",
(version1, version2, expected) => {
const isVersion1LessThanVersion2 = semverCompare(version1, version2);
expect(isVersion1LessThanVersion2).toBe(expected);
},
);
});

View file

@ -1,5 +1,6 @@
import { existsSync } from "node:fs";
import * as path from "node:path";
import semverGt from "semver/functions/gt";
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
@ -7,18 +8,7 @@ import * as path from "node:path";
export function semverCompare(version1: string, version2: string) {
if (version2 === "latest") return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
return false;
return semverGt(version2, version1);
}
export function checkWorkingDirectory(workingDirectory = ".") {