semantic-release-pub 0.9.6 → 0.10.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 +47 -4
- package/dist/publish.js +13 -5
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +5 -0
- package/dist/verifyConditions.js +23 -8
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -54,6 +54,31 @@ The plugin can be configured in the [semantic-release configuration file](https:
|
|
|
54
54
|
|
|
55
55
|
### `pub.dev` authentication
|
|
56
56
|
|
|
57
|
+
You can publish to `pub.dev` using either GitHub Actions OIDC or Google Service Account.
|
|
58
|
+
|
|
59
|
+
#### GitHub Actions OIDC
|
|
60
|
+
|
|
61
|
+
The following instructions are referenced from the [documentation](https://dart.dev/tools/pub/automated-publishing#configuring-automated-publishing-from-github-actions-on-pub-dev) of Dart. Below are the key steps to allow authentication to `pub.dev` via GitHub Actions OIDC.
|
|
62
|
+
|
|
63
|
+
1. Enable automated publishing.
|
|
64
|
+
|
|
65
|
+
> To complete this step, you must have uploader permission on the package or be an admin of the publisher that owns the package.
|
|
66
|
+
|
|
67
|
+
1. Navigate to the package Admin tab (pub.dev/packages/<package>/admin).
|
|
68
|
+
2. Click Enable publishing from GitHub Actions.
|
|
69
|
+
3. Then fill in the necessary information.
|
|
70
|
+
|
|
71
|
+
2. In your workflow, add the `id-token` permission.
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
jobs:
|
|
75
|
+
publish:
|
|
76
|
+
permissions:
|
|
77
|
+
id-token: write
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Google Service Account
|
|
81
|
+
|
|
57
82
|
The following instructions are referenced from the [documentation](https://dart.dev/tools/pub/automated-publishing#publish-using-exported-service-account-keys) of Dart. Below are the key steps to allow authentication to `pub.dev`.
|
|
58
83
|
|
|
59
84
|
1. [Create a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects), if you don’t have an existing project.
|
|
@@ -70,7 +95,7 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
70
95
|
|
|
71
96
|
> To complete this step, you must have uploader permission on the package or be an admin of the publisher that owns the package.
|
|
72
97
|
|
|
73
|
-
1. Navigate to the Admin tab (pub.dev/packages/<package>/admin).
|
|
98
|
+
1. Navigate to the package Admin tab (pub.dev/packages/<package>/admin).
|
|
74
99
|
2. Click Enable publishing with Google Cloud Service account.
|
|
75
100
|
3. Type the email of the service account into the Service account email field.
|
|
76
101
|
> You created this account in the previous step: `pub-dev@$PROJECT_ID.iam.gserviceaccount.com`
|
|
@@ -86,9 +111,9 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
86
111
|
|
|
87
112
|
### Environment variables
|
|
88
113
|
|
|
89
|
-
| Variable | Description
|
|
90
|
-
| ---------------------------- |
|
|
91
|
-
| `GOOGLE_SERVICE_ACCOUNT_KEY` | The google service account key created from the above steps. |
|
|
114
|
+
| Variable | Description |
|
|
115
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `GOOGLE_SERVICE_ACCOUNT_KEY` | The google service account key created from the above steps. Not required if using GitHub Actions OIDC. |
|
|
92
117
|
|
|
93
118
|
### Options
|
|
94
119
|
|
|
@@ -97,6 +122,7 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
97
122
|
| `cli` | The `dart` or `flutter` CLI to use to publish the package to the registry. | `dart` |
|
|
98
123
|
| `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
|
|
99
124
|
| `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` |
|
|
125
|
+
| `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` |
|
|
100
126
|
|
|
101
127
|
### Examples
|
|
102
128
|
|
|
@@ -118,3 +144,20 @@ The following instructions are referenced from the [documentation](https://dart.
|
|
|
118
144
|
```
|
|
119
145
|
|
|
120
146
|
See [here](https://github.com/zeshuaro/firestore_cache/pull/162) for a sample pull request utilising this plugin and `semantic-release` to publish a Flutter package.
|
|
147
|
+
|
|
148
|
+
#### Using GitHub Actions OIDC
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"plugins": [
|
|
153
|
+
"@semantic-release/commit-analyzer",
|
|
154
|
+
"@semantic-release/release-notes-generator",
|
|
155
|
+
[
|
|
156
|
+
"semantic-release-pub",
|
|
157
|
+
{
|
|
158
|
+
"useGithubOidc": true
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
```
|
package/dist/publish.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { execa } from "execa";
|
|
2
|
-
import { getConfig, getGoogleIdentityToken, getPubspec } from "./utils.js";
|
|
2
|
+
import { getConfig, getGithubIdentityToken, getGoogleIdentityToken, getPubspec, } from "./utils.js";
|
|
3
3
|
const SEMANTIC_RELEASE_PUB_TOKEN = "SEMANTIC_RELEASE_PUB_TOKEN";
|
|
4
4
|
export const publish = async (pluginConfig, { nextRelease: { version }, logger }) => {
|
|
5
|
-
const { cli, publishPub } = getConfig(pluginConfig);
|
|
5
|
+
const { cli, publishPub, useGithubOidc } = getConfig(pluginConfig);
|
|
6
6
|
if (!publishPub) {
|
|
7
7
|
logger.log(`Skipping publishing to pub.dev as publishPub is ${publishPub}`);
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
const pubspec = getPubspec();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
await setPubToken(cli, idToken);
|
|
11
|
+
const pubToken = await getPubToken(useGithubOidc, logger);
|
|
12
|
+
await setPubToken(cli, pubToken);
|
|
14
13
|
logger.log(`Publishing version ${version} to pub.dev`);
|
|
15
14
|
await execa(cli, ["pub", "publish", "--force"]);
|
|
16
15
|
logger.log(`Published ${pubspec.name}@${version} on pub.dev`);
|
|
@@ -19,6 +18,15 @@ export const publish = async (pluginConfig, { nextRelease: { version }, logger }
|
|
|
19
18
|
url: `https://pub.dev/packages/${pubspec.name}/versions/${version}`,
|
|
20
19
|
};
|
|
21
20
|
};
|
|
21
|
+
const getPubToken = async (useGithubOidc, logger) => {
|
|
22
|
+
if (useGithubOidc) {
|
|
23
|
+
logger.log("Using GitHub OIDC token to publish to pub.dev");
|
|
24
|
+
return await getGithubIdentityToken();
|
|
25
|
+
}
|
|
26
|
+
logger.log("Using Google identity token to publish to pub.dev");
|
|
27
|
+
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
28
|
+
return await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
29
|
+
};
|
|
22
30
|
const setPubToken = async (cli, idToken) => {
|
|
23
31
|
process.env[SEMANTIC_RELEASE_PUB_TOKEN] = idToken;
|
|
24
32
|
await execa(cli, [
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PluginConfig } from "./types.js";
|
|
|
2
2
|
export declare const PUBSPEC_PATH = "pubspec.yaml";
|
|
3
3
|
export declare const getConfig: (config: PluginConfig) => PluginConfig;
|
|
4
4
|
export declare const getGoogleIdentityToken: (serviceAccountStr: string) => Promise<string>;
|
|
5
|
+
export declare const getGithubIdentityToken: () => Promise<string>;
|
|
5
6
|
export declare const getPubspecString: () => string;
|
|
6
7
|
export declare const getPubspecFromString: (data: string) => {
|
|
7
8
|
name?: string;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import core from "@actions/core";
|
|
1
2
|
import SemanticReleaseError from "@semantic-release/error";
|
|
2
3
|
import { readFileSync } from "fs";
|
|
3
4
|
import { JWT } from "google-auth-library";
|
|
@@ -8,6 +9,7 @@ const DEFAULT_CONFIG = {
|
|
|
8
9
|
cli: "dart",
|
|
9
10
|
publishPub: true,
|
|
10
11
|
updateBuildNumber: false,
|
|
12
|
+
useGithubOidc: false,
|
|
11
13
|
};
|
|
12
14
|
const PUB_DEV_AUDIENCE = "https://pub.dev";
|
|
13
15
|
export const getConfig = (config) => {
|
|
@@ -22,6 +24,9 @@ export const getGoogleIdentityToken = async (serviceAccountStr) => {
|
|
|
22
24
|
}
|
|
23
25
|
return creds.id_token;
|
|
24
26
|
};
|
|
27
|
+
export const getGithubIdentityToken = async () => {
|
|
28
|
+
return core.getIDToken(PUB_DEV_AUDIENCE);
|
|
29
|
+
};
|
|
25
30
|
export const getPubspecString = () => {
|
|
26
31
|
return readFileSync(PUBSPEC_PATH, "utf-8");
|
|
27
32
|
};
|
package/dist/verifyConditions.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import SemanticReleaseError from "@semantic-release/error";
|
|
2
2
|
import { execa } from "execa";
|
|
3
|
-
import { getConfig, getGoogleIdentityToken } from "./utils.js";
|
|
3
|
+
import { getConfig, getGithubIdentityToken, getGoogleIdentityToken, } from "./utils.js";
|
|
4
4
|
export const verifyConditions = async (pluginConfig, { logger }) => {
|
|
5
|
-
const { cli, publishPub } = getConfig(pluginConfig);
|
|
6
|
-
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
5
|
+
const { cli, publishPub, useGithubOidc } = getConfig(pluginConfig);
|
|
7
6
|
if (publishPub) {
|
|
8
|
-
|
|
9
|
-
throw new SemanticReleaseError("Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY");
|
|
10
|
-
}
|
|
11
|
-
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
7
|
+
await verifyPublishToken(useGithubOidc);
|
|
12
8
|
await verifyCommand(cli);
|
|
13
9
|
}
|
|
14
10
|
else {
|
|
15
|
-
logger.log(`Skipping
|
|
11
|
+
logger.log(`Skipping publish token and ${cli} CLI verification as publishPub is ${publishPub}`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const verifyPublishToken = async (useGithubOidc) => {
|
|
15
|
+
if (useGithubOidc) {
|
|
16
|
+
try {
|
|
17
|
+
await getGithubIdentityToken();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new SemanticReleaseError(`Failed to get GitHub OIDC token: ${error}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
25
|
+
if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
|
|
26
|
+
throw new SemanticReleaseError("Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
30
|
+
}
|
|
16
31
|
}
|
|
17
32
|
};
|
|
18
33
|
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.10.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,12 +29,13 @@
|
|
|
29
29
|
"format": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .ts --fix src tests && prettier --write src/**/*.ts tests/**/*.ts"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=22.13.
|
|
32
|
+
"node": ">=22.13.1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@actions/core": "^1.11.1",
|
|
35
36
|
"@semantic-release/error": "^4.0.0",
|
|
36
37
|
"execa": "^9.5.2",
|
|
37
|
-
"google-auth-library": "^9.15.
|
|
38
|
+
"google-auth-library": "^9.15.1",
|
|
38
39
|
"yaml": "^2.7.0",
|
|
39
40
|
"zod": "^3.24.1"
|
|
40
41
|
},
|
|
@@ -45,12 +46,12 @@
|
|
|
45
46
|
"@types/semantic-release": "20.0.6",
|
|
46
47
|
"@types/semantic-release__error": "3.0.3",
|
|
47
48
|
"@types/signale": "1.4.7",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
49
|
-
"@typescript-eslint/parser": "8.
|
|
50
|
-
"@vitest/coverage-v8": "3.0.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "8.21.0",
|
|
50
|
+
"@typescript-eslint/parser": "8.21.0",
|
|
51
|
+
"@vitest/coverage-v8": "3.0.4",
|
|
51
52
|
"common-tags": "1.8.2",
|
|
52
53
|
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
53
|
-
"eslint": "9.
|
|
54
|
+
"eslint": "9.19.0",
|
|
54
55
|
"eslint-config-prettier": "^10.0.1",
|
|
55
56
|
"eslint-config-semistandard": "17.0.0",
|
|
56
57
|
"eslint-config-standard": "17.1.0",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"prettier": "3.4.2",
|
|
61
62
|
"semantic-release": "24.2.1",
|
|
62
63
|
"typescript": "5.7.3",
|
|
63
|
-
"vitest": "3.0.
|
|
64
|
+
"vitest": "3.0.4",
|
|
64
65
|
"vitest-mock-extended": "2.0.2"
|
|
65
66
|
}
|
|
66
67
|
}
|