semantic-release-pub 0.12.0 → 0.13.1
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 +1 -0
- package/dist/publish.js +13 -13
- package/dist/utils.js +11 -6
- package/dist/verifyConditions.js +5 -5
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -127,6 +127,7 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
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
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` |
|
|
130
131
|
|
|
131
132
|
### Examples
|
|
132
133
|
|
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, pkgRoot } = 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
11
|
const pubspec = getPubspec(pkgRoot);
|
|
12
|
-
const pubToken = await getPubToken(useGithubOidc, logger);
|
|
13
|
-
await setPubToken(cli, pubToken);
|
|
14
|
-
logger.log(`Publishing version ${version} to
|
|
12
|
+
const pubToken = await getPubToken(useGithubOidc, registryUrl, logger);
|
|
13
|
+
await setPubToken(cli, pubToken, registryUrl);
|
|
14
|
+
logger.log(`Publishing version ${version} to ${registryUrl}`);
|
|
15
15
|
await execa(cli, ["pub", "publish", "--force"], { cwd: pkgRoot });
|
|
16
|
-
logger.log(`Published ${pubspec.name}@${version} on
|
|
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
|
@@ -6,24 +6,29 @@ import { JWT } from "google-auth-library";
|
|
|
6
6
|
import { parse } from "yaml";
|
|
7
7
|
import { Pubspec, ServiceAccount } from "./schemas.js";
|
|
8
8
|
const PUBSPEC_PATH = "pubspec.yaml";
|
|
9
|
+
export const PUB_DEV_URL = "https://pub.dev";
|
|
9
10
|
const DEFAULT_CONFIG = {
|
|
10
11
|
cli: "dart",
|
|
11
12
|
publishPub: true,
|
|
12
13
|
updateBuildNumber: false,
|
|
13
14
|
useGithubOidc: false,
|
|
14
15
|
pkgRoot: ".",
|
|
16
|
+
registryUrl: PUB_DEV_URL,
|
|
15
17
|
};
|
|
16
|
-
const PUB_DEV_AUDIENCE = "https://pub.dev";
|
|
17
18
|
export const getConfig = (config) => {
|
|
18
|
-
|
|
19
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
20
|
+
return {
|
|
21
|
+
...merged,
|
|
22
|
+
registryUrl: merged.registryUrl.replace(/\/$/, ""),
|
|
23
|
+
};
|
|
19
24
|
};
|
|
20
25
|
export const getPubspecPath = (pkgRoot) => join(pkgRoot, PUBSPEC_PATH);
|
|
21
|
-
export const getGoogleIdentityToken = async (serviceAccountStr) => {
|
|
26
|
+
export const getGoogleIdentityToken = async (serviceAccountStr, registryUrl) => {
|
|
22
27
|
const serviceAccountJson = getServiceAccount(serviceAccountStr);
|
|
23
28
|
const jwtClient = new JWT({
|
|
24
29
|
email: serviceAccountJson.client_email,
|
|
25
30
|
key: serviceAccountJson.private_key,
|
|
26
|
-
scopes:
|
|
31
|
+
scopes: registryUrl,
|
|
27
32
|
});
|
|
28
33
|
const creds = await jwtClient.authorize();
|
|
29
34
|
if (!creds.id_token) {
|
|
@@ -31,8 +36,8 @@ export const getGoogleIdentityToken = async (serviceAccountStr) => {
|
|
|
31
36
|
}
|
|
32
37
|
return creds.id_token;
|
|
33
38
|
};
|
|
34
|
-
export const getGithubIdentityToken = async () => {
|
|
35
|
-
return getIDToken(
|
|
39
|
+
export const getGithubIdentityToken = async (registryUrl) => {
|
|
40
|
+
return getIDToken(registryUrl);
|
|
36
41
|
};
|
|
37
42
|
export const getPubspecString = (pkgRoot) => {
|
|
38
43
|
return readFileSync(getPubspecPath(pkgRoot), "utf-8");
|
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.1",
|
|
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.17.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.
|
|
43
|
+
"@biomejs/biome": "2.5.0",
|
|
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.9",
|
|
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.9",
|
|
59
59
|
"vitest-mock-extended": "4.0.0"
|
|
60
60
|
}
|
|
61
61
|
}
|