semantic-release-pub 0.2.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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/prepare.d.ts +3 -0
- package/dist/prepare.js +11 -0
- package/dist/publish.d.ts +2 -0
- package/dist/publish.js +23 -0
- package/dist/schemas.d.ts +20 -0
- package/dist/schemas.js +6 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +28 -0
- package/dist/verifyConditions.d.ts +2 -0
- package/dist/verifyConditions.js +20 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 zeshuaro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# semantic-release-pub
|
|
2
|
+
|
|
3
|
+
[semantic-release](https://github.com/semantic-release/semantic-release) plugin to publish a [Dart](https://dart.dev/guides/libraries/create-packages) or [Flutter](https://docs.flutter.dev/packages-and-plugins/developing-packages) package.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/semantic-release-pub)
|
|
6
|
+
[](https://github.com/zeshuaro/semantic-release-pub/blob/main/LICENSE)
|
|
7
|
+
[](https://github.com/zeshuaro/semantic-release-pub/actions/workflows/github-actions.yml)
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=semantic-release-pub)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=semantic-release-pub)
|
|
10
|
+
[](https://github.com/prettier/prettier)
|
|
11
|
+
|
|
12
|
+
| Step | Description |
|
|
13
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
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.yml` version. |
|
|
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
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install via `npm`:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save-dev semantic-release-pub
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or via `yarn`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yarn add --dev semantic-release-pub
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
The plugin can be configured in the [semantic-release configuration file](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration):
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"plugins": [
|
|
39
|
+
"@semantic-release/commit-analyzer",
|
|
40
|
+
"@semantic-release/release-notes-generator",
|
|
41
|
+
"semantic-release-pub"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/prepare.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { parse } from 'yaml';
|
|
3
|
+
import { Pubspec } from './schemas.js';
|
|
4
|
+
import { getConfig } from './utils.js';
|
|
5
|
+
export const prepare = async (pluginConfig, { nextRelease }) => {
|
|
6
|
+
const { pubspecPath } = getConfig(pluginConfig);
|
|
7
|
+
const data = readFileSync(pubspecPath, 'utf-8');
|
|
8
|
+
const pubspec = Pubspec.parse(parse(data));
|
|
9
|
+
const newData = data.replace(new RegExp(`^version:.*${pubspec.version}`), `version: ${nextRelease.version}`);
|
|
10
|
+
writeFileSync(pubspecPath, newData);
|
|
11
|
+
};
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { getConfig, getGoogleIdentityToken } from './utils.js';
|
|
3
|
+
const SEMANTIC_RELEASE_PUB_TOKEN = 'SEMANTIC_RELEASE_PUB_TOKEN';
|
|
4
|
+
export const publish = async (pluginConfig) => {
|
|
5
|
+
const { cli } = getConfig(pluginConfig);
|
|
6
|
+
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
7
|
+
const idToken = await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
8
|
+
await setPubToken(cli, idToken);
|
|
9
|
+
await publishToPub(cli);
|
|
10
|
+
};
|
|
11
|
+
const setPubToken = async (cli, idToken) => {
|
|
12
|
+
process.env[SEMANTIC_RELEASE_PUB_TOKEN] = idToken;
|
|
13
|
+
await execa(cli, [
|
|
14
|
+
'pub',
|
|
15
|
+
'token',
|
|
16
|
+
'add',
|
|
17
|
+
'https://pub.dev',
|
|
18
|
+
`--env-var=${SEMANTIC_RELEASE_PUB_TOKEN}`
|
|
19
|
+
]);
|
|
20
|
+
};
|
|
21
|
+
const publishToPub = async (cli) => {
|
|
22
|
+
await execa(cli, ['pub', 'publish', '--force']);
|
|
23
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ServiceAccount: z.ZodObject<{
|
|
3
|
+
client_email: z.ZodString;
|
|
4
|
+
private_key: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
client_email?: string;
|
|
7
|
+
private_key?: string;
|
|
8
|
+
}, {
|
|
9
|
+
client_email?: string;
|
|
10
|
+
private_key?: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type ServiceAccount = z.infer<typeof ServiceAccount>;
|
|
13
|
+
export declare const Pubspec: z.ZodObject<{
|
|
14
|
+
version: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
version?: string;
|
|
17
|
+
}, {
|
|
18
|
+
version?: string;
|
|
19
|
+
}>;
|
|
20
|
+
export type Pubspec = z.infer<typeof Pubspec>;
|
package/dist/schemas.js
ADDED
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import SemanticReleaseError from '@semantic-release/error';
|
|
2
|
+
import { JWT } from 'google-auth-library';
|
|
3
|
+
import { ServiceAccount } from './schemas.js';
|
|
4
|
+
const DEFAULT_CONFIG = {
|
|
5
|
+
cli: 'dart',
|
|
6
|
+
pubspecPath: 'pubspec.yml'
|
|
7
|
+
};
|
|
8
|
+
const PUB_DEV_AUDIENCE = 'https://pub.dev';
|
|
9
|
+
export const getConfig = (config) => {
|
|
10
|
+
return { ...DEFAULT_CONFIG, ...config };
|
|
11
|
+
};
|
|
12
|
+
export const getGoogleIdentityToken = async (serviceAccountStr) => {
|
|
13
|
+
const serviceAccountJson = getServiceAccount(serviceAccountStr);
|
|
14
|
+
const jwtClient = new JWT(serviceAccountJson.client_email, undefined, serviceAccountJson.private_key, PUB_DEV_AUDIENCE);
|
|
15
|
+
const creds = await jwtClient.authorize();
|
|
16
|
+
if (!creds.id_token) {
|
|
17
|
+
throw new SemanticReleaseError('Failed to retrieve identity token from Google');
|
|
18
|
+
}
|
|
19
|
+
return creds.id_token;
|
|
20
|
+
};
|
|
21
|
+
const getServiceAccount = (serviceAccountStr) => {
|
|
22
|
+
try {
|
|
23
|
+
return ServiceAccount.parse(JSON.parse(serviceAccountStr));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new SemanticReleaseError(`Invalid service account: ${error}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import SemanticReleaseError from '@semantic-release/error';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { getConfig, getGoogleIdentityToken } from './utils.js';
|
|
4
|
+
export const verifyConditions = async (pluginConfig) => {
|
|
5
|
+
const { cli } = getConfig(pluginConfig);
|
|
6
|
+
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
|
|
7
|
+
if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
|
|
8
|
+
throw new SemanticReleaseError('Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY');
|
|
9
|
+
}
|
|
10
|
+
await verifyCommand(cli);
|
|
11
|
+
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
|
|
12
|
+
};
|
|
13
|
+
const verifyCommand = async (command) => {
|
|
14
|
+
try {
|
|
15
|
+
await execa(command);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new SemanticReleaseError(`${command} returned an error: ${error}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "semantic-release-pub",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "semantic-release plugin to publish a Dart or Flutter package",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "zeshuaro@gmail.com",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"homepage": "https://github.com/zeshuaro/semantic-release-pub",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/zeshuaro/semantic-release-pub"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"dart",
|
|
16
|
+
"flutter",
|
|
17
|
+
"publish",
|
|
18
|
+
"registry",
|
|
19
|
+
"semantic-release",
|
|
20
|
+
"version"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/*"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"test": "vitest run tests --coverage",
|
|
28
|
+
"lint": "eslint --ext .ts src tests && prettier --check src/**/*.ts tests/**/*.ts",
|
|
29
|
+
"format": "eslint --ext .ts --fix src tests && prettier --write src/**/*.ts tests/**/*.ts"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@semantic-release/error": "^4.0.0",
|
|
36
|
+
"execa": "^8.0.1",
|
|
37
|
+
"google-auth-library": "^9.0.0",
|
|
38
|
+
"yaml": "^2.3.2",
|
|
39
|
+
"zod": "^3.22.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
43
|
+
"@semantic-release/git": "^10.0.1",
|
|
44
|
+
"@types/common-tags": "^1.8.2",
|
|
45
|
+
"@types/semantic-release": "^20.0.1",
|
|
46
|
+
"@types/semantic-release__error": "^3.0.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
48
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
49
|
+
"@vitest/coverage-v8": "^0.34.4",
|
|
50
|
+
"common-tags": "^1.8.2",
|
|
51
|
+
"conventional-changelog-conventionalcommits": "^7.0.2",
|
|
52
|
+
"eslint": "^8.13.0",
|
|
53
|
+
"eslint-config-semistandard": "^17.0.0",
|
|
54
|
+
"eslint-config-standard": "^17.0.0",
|
|
55
|
+
"eslint-plugin-import": "^2.26.0",
|
|
56
|
+
"eslint-plugin-n": "^15.0.0",
|
|
57
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
58
|
+
"prettier": "^3.0.3",
|
|
59
|
+
"semantic-release": "^21.1.2",
|
|
60
|
+
"typescript": "^5.1.6",
|
|
61
|
+
"vitest": "^0.34.4",
|
|
62
|
+
"vitest-mock-extended": "^1.2.1"
|
|
63
|
+
}
|
|
64
|
+
}
|