semantic-release-pub 0.2.1 → 0.3.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 +67 -1
- package/dist/prepare.d.ts +1 -2
- package/dist/prepare.js +6 -6
- package/dist/publish.d.ts +2 -1
- package/dist/publish.js +9 -6
- package/dist/types.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
| Step | Description |
|
|
13
13
|
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
14
14
|
| `verifyConditions` | Verify the presence of the `GOOGLE_SERVICE_ACCOUNT_KEY` environment variable, the ability to exchange an identity from the service account, and the `dart` or `flutter` executable. |
|
|
15
|
-
| `prepare` | Update the `pubspec.
|
|
15
|
+
| `prepare` | Update the `pubspec.yaml` version. |
|
|
16
16
|
| `publish` | Publish the [Dart](https://dart.dev/tools/pub/publishing) or [Flutter](https://docs.flutter.dev/packages-and-plugins/developing-packages#publish) package to the registry. |
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
@@ -42,3 +42,69 @@ The plugin can be configured in the [semantic-release configuration file](https:
|
|
|
42
42
|
]
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
### `pub.dev` authentication
|
|
49
|
+
|
|
50
|
+
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`.
|
|
51
|
+
|
|
52
|
+
1. [Create a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects), if you don’t have an existing project.
|
|
53
|
+
|
|
54
|
+
2. Create a [service account](https://cloud.google.com/iam/docs/service-account-overview) either through the Google Cloud Console under `IAM and admin > Service accounts` or as follow:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
gcloud iam service-accounts create pub-dev \
|
|
58
|
+
--description='Service account to be impersonated when publishing to pub.dev' \
|
|
59
|
+
--display-name='pub-dev'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
3. Grant the service account permission to publish your package.
|
|
63
|
+
|
|
64
|
+
> To complete this step, you must have uploader permission on the package or be an admin of the publisher that owns the package.
|
|
65
|
+
|
|
66
|
+
1. Navigate to the Admin tab (pub.dev/packages/<package>/admin).
|
|
67
|
+
2. Click Enable publishing with Google Cloud Service account.
|
|
68
|
+
3. Type the email of the service account into the Service account email field.
|
|
69
|
+
> You created this account in the previous step: `pub-dev@$PROJECT_ID.iam.gserviceaccount.com`
|
|
70
|
+
|
|
71
|
+
4. Create exported service account keys for the service account either through the Google Cloud Console under `Service account actions > Manage keys > Add key > Create new key > JSON > Create` or as follow:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
gcloud iam service-accounts keys create key-file.json \
|
|
75
|
+
PROJECT_ID.iam.gserviceaccount.com
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
5. Copy the content of the JSON key file and set it as an environment variable under `GOOGLE_SERVICE_ACCOUNT_KEY`.
|
|
79
|
+
|
|
80
|
+
### Environment variables
|
|
81
|
+
|
|
82
|
+
| Variable | Description |
|
|
83
|
+
| ---------------------------- | ------------------------------------------------------------ |
|
|
84
|
+
| `GOOGLE_SERVICE_ACCOUNT_KEY` | The google service account key created from the above steps. |
|
|
85
|
+
|
|
86
|
+
### Options
|
|
87
|
+
|
|
88
|
+
| Option | Description | Default |
|
|
89
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------- | ------- |
|
|
90
|
+
| `cli` | The `dart` or `flutter` CLI to use to publish the package to the registry. | `dart` |
|
|
91
|
+
| `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
|
|
92
|
+
|
|
93
|
+
### Examples
|
|
94
|
+
|
|
95
|
+
#### Publishing a Flutter package
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"plugins": [
|
|
100
|
+
"@semantic-release/commit-analyzer",
|
|
101
|
+
"@semantic-release/release-notes-generator",
|
|
102
|
+
[
|
|
103
|
+
"semantic-release-pub",
|
|
104
|
+
{
|
|
105
|
+
"cli": "flutter"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
```
|
package/dist/prepare.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { PrepareContext } from 'semantic-release';
|
|
2
|
-
|
|
3
|
-
export declare const prepare: (pluginConfig: PluginConfig, { nextRelease }: PrepareContext) => Promise<void>;
|
|
2
|
+
export declare const prepare: ({ nextRelease: { version }, logger }: PrepareContext) => Promise<void>;
|
package/dist/prepare.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { parse } from 'yaml';
|
|
3
3
|
import { Pubspec } from './schemas.js';
|
|
4
|
-
|
|
5
|
-
export const prepare = async (
|
|
6
|
-
const
|
|
7
|
-
const data = readFileSync(pubspecPath, 'utf-8');
|
|
4
|
+
const PUBSPEC_PATH = 'pubspec.yaml';
|
|
5
|
+
export const prepare = async ({ nextRelease: { version }, logger }) => {
|
|
6
|
+
const data = readFileSync(PUBSPEC_PATH, 'utf-8');
|
|
8
7
|
const pubspec = Pubspec.parse(parse(data));
|
|
9
|
-
const newData = data.replace(new RegExp(
|
|
10
|
-
|
|
8
|
+
const newData = data.replace(new RegExp(`version:[ \t]+${pubspec.version}`), `version: ${version}`);
|
|
9
|
+
logger.log(`Writing version ${version} to ${PUBSPEC_PATH}`);
|
|
10
|
+
writeFileSync(PUBSPEC_PATH, newData);
|
|
11
11
|
};
|
package/dist/publish.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { PublishContext } from 'semantic-release';
|
|
1
2
|
import { PluginConfig } from './types.js';
|
|
2
|
-
export declare const publish: (pluginConfig: PluginConfig) => Promise<void>;
|
|
3
|
+
export declare const publish: (pluginConfig: PluginConfig, { nextRelease: { version }, logger }: PublishContext) => Promise<void>;
|
package/dist/publish.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { execa } from 'execa';
|
|
2
2
|
import { getConfig, getGoogleIdentityToken } from './utils.js';
|
|
3
3
|
const SEMANTIC_RELEASE_PUB_TOKEN = 'SEMANTIC_RELEASE_PUB_TOKEN';
|
|
4
|
-
export const publish = async (pluginConfig) => {
|
|
5
|
-
const { cli } = getConfig(pluginConfig);
|
|
4
|
+
export const publish = async (pluginConfig, { nextRelease: { version }, logger }) => {
|
|
5
|
+
const { cli, publishPub } = getConfig(pluginConfig);
|
|
6
|
+
if (!publishPub) {
|
|
7
|
+
logger.log(`Skipping publishing to pub.dev as publishPub is ${publishPub}`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
7
11
|
const idToken = await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
8
12
|
await setPubToken(cli, idToken);
|
|
9
|
-
|
|
13
|
+
logger.log(`Publishing version ${version} to pub.dev`);
|
|
14
|
+
await execa(cli, ['pub', 'publish', '--force']);
|
|
15
|
+
logger.log('Published package');
|
|
10
16
|
};
|
|
11
17
|
const setPubToken = async (cli, idToken) => {
|
|
12
18
|
process.env[SEMANTIC_RELEASE_PUB_TOKEN] = idToken;
|
|
@@ -18,6 +24,3 @@ const setPubToken = async (cli, idToken) => {
|
|
|
18
24
|
`--env-var=${SEMANTIC_RELEASE_PUB_TOKEN}`
|
|
19
25
|
]);
|
|
20
26
|
};
|
|
21
|
-
const publishToPub = async (cli) => {
|
|
22
|
-
await execa(cli, ['pub', 'publish', '--force']);
|
|
23
|
-
};
|
package/dist/types.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { JWT } from 'google-auth-library';
|
|
|
3
3
|
import { ServiceAccount } from './schemas.js';
|
|
4
4
|
const DEFAULT_CONFIG = {
|
|
5
5
|
cli: 'dart',
|
|
6
|
-
|
|
6
|
+
publishPub: true
|
|
7
7
|
};
|
|
8
8
|
const PUB_DEV_AUDIENCE = 'https://pub.dev';
|
|
9
9
|
export const getConfig = (config) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-release-pub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@types/common-tags": "^1.8.2",
|
|
45
45
|
"@types/semantic-release": "^20.0.1",
|
|
46
46
|
"@types/semantic-release__error": "^3.0.0",
|
|
47
|
+
"@types/signale": "^1.4.4",
|
|
47
48
|
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
48
49
|
"@typescript-eslint/parser": "^6.7.2",
|
|
49
50
|
"@vitest/coverage-v8": "^0.34.4",
|