semantic-release-pub 0.11.18 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/prepare.js +6 -5
- package/dist/publish.js +15 -15
- package/dist/utils.js +20 -12
- package/dist/verifyConditions.js +5 -5
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -126,6 +126,8 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
126
126
|
| `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
|
|
127
127
|
| `updateBuildNumber` | Whether to write build number for every newly bumped version in `pubspec.yaml`. Note that the build number will always be increased by one. Learn more on [Flutter docs](https://docs.flutter.dev/deployment/android#updating-the-apps-version-number). | `false` |
|
|
128
128
|
| `useGithubOidc` | Whether to use GitHub OIDC. If set to `true`, authentication to `pub.dev` will be done using GitHub OIDC. Otherwise, the `GOOGLE_SERVICE_ACCOUNT_KEY` will be used. | `false` |
|
|
129
|
+
| `pkgRoot` | The path to the package root directory. Useful for monorepos where the package is not at the repository root. | `.` |
|
|
130
|
+
| `registryUrl` | The URL of the pub registry to publish to. Useful for private registries such as [unpub](https://pub.dev/packages/unpub). The URL is used as the token audience for OIDC authentication and as the target for `dart pub token add`. | `https://pub.dev` |
|
|
129
131
|
|
|
130
132
|
### Examples
|
|
131
133
|
|
package/dist/prepare.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
2
|
import SemanticReleaseError from "@semantic-release/error";
|
|
3
|
-
import { getConfig, getPubspecFromString,
|
|
3
|
+
import { getConfig, getPubspecFromString, getPubspecPath, getPubspecString, } from "./utils.js";
|
|
4
4
|
export const prepare = async (pluginConfig, { nextRelease: { version }, logger }) => {
|
|
5
|
-
const { updateBuildNumber } = getConfig(pluginConfig);
|
|
6
|
-
const
|
|
5
|
+
const { updateBuildNumber, pkgRoot } = getConfig(pluginConfig);
|
|
6
|
+
const pubspecPath = getPubspecPath(pkgRoot);
|
|
7
|
+
const data = getPubspecString(pkgRoot);
|
|
7
8
|
const pubspec = getPubspecFromString(data);
|
|
8
9
|
const pubspecVersionEscaped = pubspec.version.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
9
10
|
let nextVersion = version;
|
|
@@ -16,6 +17,6 @@ export const prepare = async (pluginConfig, { nextRelease: { version }, logger }
|
|
|
16
17
|
nextVersion = `${version}+${buildNumber + 1}`;
|
|
17
18
|
}
|
|
18
19
|
const newData = data.replace(new RegExp(`version:[ \t]+['"]?${pubspecVersionEscaped}['"]?`), `version: ${nextVersion}`);
|
|
19
|
-
logger.log(`Writing version ${nextVersion} to ${
|
|
20
|
-
writeFileSync(
|
|
20
|
+
logger.log(`Writing version ${nextVersion} to ${pubspecPath}`);
|
|
21
|
+
writeFileSync(pubspecPath, newData);
|
|
21
22
|
};
|
package/dist/publish.js
CHANGED
|
@@ -3,41 +3,41 @@ import { execa } from "execa";
|
|
|
3
3
|
import { getConfig, getGithubIdentityToken, getGoogleIdentityToken, getPubspec, } from "./utils.js";
|
|
4
4
|
const SEMANTIC_RELEASE_PUB_TOKEN = "SEMANTIC_RELEASE_PUB_TOKEN";
|
|
5
5
|
export const publish = async (pluginConfig, { nextRelease: { version }, logger }) => {
|
|
6
|
-
const { cli, publishPub, useGithubOidc } = getConfig(pluginConfig);
|
|
6
|
+
const { cli, publishPub, useGithubOidc, pkgRoot, registryUrl } = getConfig(pluginConfig);
|
|
7
7
|
if (!publishPub) {
|
|
8
8
|
logger.log(`Skipping publishing to pub.dev as publishPub is ${publishPub}`);
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const pubspec = getPubspec();
|
|
12
|
-
const pubToken = await getPubToken(useGithubOidc, logger);
|
|
13
|
-
await setPubToken(cli, pubToken);
|
|
14
|
-
logger.log(`Publishing version ${version} to
|
|
15
|
-
await execa(cli, ["pub", "publish", "--force"]);
|
|
16
|
-
logger.log(`Published ${pubspec.name}@${version} on
|
|
11
|
+
const pubspec = getPubspec(pkgRoot);
|
|
12
|
+
const pubToken = await getPubToken(useGithubOidc, registryUrl, logger);
|
|
13
|
+
await setPubToken(cli, pubToken, registryUrl);
|
|
14
|
+
logger.log(`Publishing version ${version} to ${registryUrl}`);
|
|
15
|
+
await execa(cli, ["pub", "publish", "--force"], { cwd: pkgRoot });
|
|
16
|
+
logger.log(`Published ${pubspec.name}@${version} on ${registryUrl}`);
|
|
17
17
|
return {
|
|
18
18
|
name: "pub.dev package",
|
|
19
|
-
url:
|
|
19
|
+
url: `${registryUrl}/packages/${pubspec.name}/versions/${version}`,
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
const getPubToken = async (useGithubOidc, logger) => {
|
|
22
|
+
const getPubToken = async (useGithubOidc, registryUrl, logger) => {
|
|
23
23
|
if (useGithubOidc) {
|
|
24
|
-
logger.log(
|
|
25
|
-
return await getGithubIdentityToken();
|
|
24
|
+
logger.log(`Using GitHub OIDC token to publish to ${registryUrl}`);
|
|
25
|
+
return await getGithubIdentityToken(registryUrl);
|
|
26
26
|
}
|
|
27
|
-
logger.log(
|
|
27
|
+
logger.log(`Using Google identity token to publish to ${registryUrl}`);
|
|
28
28
|
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
29
29
|
if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
|
|
30
30
|
throw new SemanticReleaseError("Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY");
|
|
31
31
|
}
|
|
32
|
-
return await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
32
|
+
return await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY, registryUrl);
|
|
33
33
|
};
|
|
34
|
-
const setPubToken = async (cli, idToken) => {
|
|
34
|
+
const setPubToken = async (cli, idToken, registryUrl) => {
|
|
35
35
|
process.env[SEMANTIC_RELEASE_PUB_TOKEN] = idToken;
|
|
36
36
|
await execa(cli, [
|
|
37
37
|
"pub",
|
|
38
38
|
"token",
|
|
39
39
|
"add",
|
|
40
|
-
|
|
40
|
+
registryUrl,
|
|
41
41
|
`--env-var=${SEMANTIC_RELEASE_PUB_TOKEN}`,
|
|
42
42
|
]);
|
|
43
43
|
};
|
package/dist/utils.js
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { getIDToken } from "@actions/core";
|
|
3
4
|
import SemanticReleaseError from "@semantic-release/error";
|
|
4
5
|
import { JWT } from "google-auth-library";
|
|
5
6
|
import { parse } from "yaml";
|
|
6
7
|
import { Pubspec, ServiceAccount } from "./schemas.js";
|
|
7
|
-
|
|
8
|
+
const PUBSPEC_PATH = "pubspec.yaml";
|
|
9
|
+
export const PUB_DEV_URL = "https://pub.dev";
|
|
8
10
|
const DEFAULT_CONFIG = {
|
|
9
11
|
cli: "dart",
|
|
10
12
|
publishPub: true,
|
|
11
13
|
updateBuildNumber: false,
|
|
12
14
|
useGithubOidc: false,
|
|
15
|
+
pkgRoot: ".",
|
|
16
|
+
registryUrl: PUB_DEV_URL,
|
|
13
17
|
};
|
|
14
|
-
const PUB_DEV_AUDIENCE = "https://pub.dev";
|
|
15
18
|
export const getConfig = (config) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
20
|
+
return {
|
|
21
|
+
...merged,
|
|
22
|
+
registryUrl: merged.registryUrl.replace(/\/$/, ""),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const getPubspecPath = (pkgRoot) => join(pkgRoot, PUBSPEC_PATH);
|
|
26
|
+
export const getGoogleIdentityToken = async (serviceAccountStr, registryUrl) => {
|
|
19
27
|
const serviceAccountJson = getServiceAccount(serviceAccountStr);
|
|
20
28
|
const jwtClient = new JWT({
|
|
21
29
|
email: serviceAccountJson.client_email,
|
|
22
30
|
key: serviceAccountJson.private_key,
|
|
23
|
-
scopes:
|
|
31
|
+
scopes: registryUrl,
|
|
24
32
|
});
|
|
25
33
|
const creds = await jwtClient.authorize();
|
|
26
34
|
if (!creds.id_token) {
|
|
@@ -28,17 +36,17 @@ export const getGoogleIdentityToken = async (serviceAccountStr) => {
|
|
|
28
36
|
}
|
|
29
37
|
return creds.id_token;
|
|
30
38
|
};
|
|
31
|
-
export const getGithubIdentityToken = async () => {
|
|
32
|
-
return getIDToken(
|
|
39
|
+
export const getGithubIdentityToken = async (registryUrl) => {
|
|
40
|
+
return getIDToken(registryUrl);
|
|
33
41
|
};
|
|
34
|
-
export const getPubspecString = () => {
|
|
35
|
-
return readFileSync(
|
|
42
|
+
export const getPubspecString = (pkgRoot) => {
|
|
43
|
+
return readFileSync(getPubspecPath(pkgRoot), "utf-8");
|
|
36
44
|
};
|
|
37
45
|
export const getPubspecFromString = (data) => {
|
|
38
46
|
return Pubspec.parse(parse(data));
|
|
39
47
|
};
|
|
40
|
-
export const getPubspec = () => {
|
|
41
|
-
const data = getPubspecString();
|
|
48
|
+
export const getPubspec = (pkgRoot) => {
|
|
49
|
+
const data = getPubspecString(pkgRoot);
|
|
42
50
|
return getPubspecFromString(data);
|
|
43
51
|
};
|
|
44
52
|
const getServiceAccount = (serviceAccountStr) => {
|
package/dist/verifyConditions.js
CHANGED
|
@@ -2,19 +2,19 @@ import SemanticReleaseError from "@semantic-release/error";
|
|
|
2
2
|
import { execa } from "execa";
|
|
3
3
|
import { getConfig, getGithubIdentityToken, getGoogleIdentityToken, } from "./utils.js";
|
|
4
4
|
export const verifyConditions = async (pluginConfig, { logger }) => {
|
|
5
|
-
const { cli, publishPub, useGithubOidc } = getConfig(pluginConfig);
|
|
5
|
+
const { cli, publishPub, useGithubOidc, registryUrl } = getConfig(pluginConfig);
|
|
6
6
|
if (publishPub) {
|
|
7
|
-
await verifyPublishToken(useGithubOidc);
|
|
7
|
+
await verifyPublishToken(useGithubOidc, registryUrl);
|
|
8
8
|
await verifyCommand(cli);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
logger.log(`Skipping publish token and ${cli} CLI verification as publishPub is ${publishPub}`);
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
const verifyPublishToken = async (useGithubOidc) => {
|
|
14
|
+
const verifyPublishToken = async (useGithubOidc, registryUrl) => {
|
|
15
15
|
if (useGithubOidc) {
|
|
16
16
|
try {
|
|
17
|
-
await getGithubIdentityToken();
|
|
17
|
+
await getGithubIdentityToken(registryUrl);
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
throw new SemanticReleaseError(`Failed to get GitHub OIDC token: ${error}`);
|
|
@@ -25,7 +25,7 @@ const verifyPublishToken = async (useGithubOidc) => {
|
|
|
25
25
|
if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
|
|
26
26
|
throw new SemanticReleaseError("Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY");
|
|
27
27
|
}
|
|
28
|
-
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
28
|
+
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY, registryUrl);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
const verifyCommand = async (command) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-release-pub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "semantic-release plugin to publish a Dart or Flutter package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "zeshuaro@gmail.com",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"lint:write": "biome check src tests --write"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=24.
|
|
32
|
+
"node": ">=24.16.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@actions/core": "^3.0.1",
|
|
36
36
|
"@semantic-release/error": "^4.0.0",
|
|
37
37
|
"execa": "^9.6.1",
|
|
38
|
-
"google-auth-library": "^10.
|
|
38
|
+
"google-auth-library": "^10.7.0",
|
|
39
39
|
"yaml": "^2.9.0",
|
|
40
40
|
"zod": "^4.4.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@biomejs/biome": "2.4.
|
|
43
|
+
"@biomejs/biome": "2.4.16",
|
|
44
44
|
"@semantic-release/changelog": "6.0.3",
|
|
45
45
|
"@semantic-release/git": "10.0.1",
|
|
46
46
|
"@tsconfig/node-ts": "^23.6.4",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@types/common-tags": "1.8.4",
|
|
51
51
|
"@types/semantic-release__error": "3.0.3",
|
|
52
52
|
"@types/signale": "1.4.7",
|
|
53
|
-
"@vitest/coverage-v8": "4.1.
|
|
53
|
+
"@vitest/coverage-v8": "4.1.8",
|
|
54
54
|
"common-tags": "1.8.2",
|
|
55
55
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
56
|
-
"semantic-release": "25.0.
|
|
56
|
+
"semantic-release": "25.0.5",
|
|
57
57
|
"typescript": "6.0.3",
|
|
58
|
-
"vitest": "4.1.
|
|
58
|
+
"vitest": "4.1.8",
|
|
59
59
|
"vitest-mock-extended": "4.0.0"
|
|
60
60
|
}
|
|
61
61
|
}
|