https://github.com/zeshuaro/semantic-release-pub
semantic-release plugin to publish a Dart or Flutter package.
https://github.com/zeshuaro/semantic-release-pub
dart flutter publish release semantic-release version
Last synced: 4 months ago
JSON representation
semantic-release plugin to publish a Dart or Flutter package.
- Host: GitHub
- URL: https://github.com/zeshuaro/semantic-release-pub
- Owner: zeshuaro
- License: mit
- Created: 2023-09-16T02:18:12.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T13:01:06.000Z (about 1 year ago)
- Last Synced: 2024-05-01T16:10:19.323Z (about 1 year ago)
- Topics: dart, flutter, publish, release, semantic-release, version
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/semantic-release-pub
- Size: 1.42 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# semantic-release-pub
[](https://www.npmjs.com/package/semantic-release-pub)
[](https://github.com/zeshuaro/semantic-release-pub/blob/main/LICENSE)
[](https://github.com/zeshuaro/semantic-release-pub/actions/workflows/github-actions.yml)
[](https://codecov.io/github/zeshuaro/semantic-release-pub)
[](https://app.codacy.com/gh/zeshuaro/semantic-release-pub/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://github.com/prettier/prettier)[](https://github.com/sponsors/zeshuaro)
[](https://www.buymeacoffee.com/zeshuaro)
[](https://ko-fi.com/zeshuaro)
[](https://liberapay.com/zeshuaro/)
[](https://patreon.com/zeshuaro)
[](https://paypal.me/JoshuaTang)[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.
| Step | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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. |
| `prepare` | Update the `pubspec.yaml` version. |
| `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. |## Installation
Install via `npm`:
```bash
npm install --save-dev semantic-release-pub
```Or via `yarn`:
```bash
yarn add --dev semantic-release-pub
```## Usage
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):
```json
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"semantic-release-pub"
]
}
```## Configuration
### `pub.dev` authentication
You can publish to `pub.dev` using either Google Service Account or GitHub Actions OIDC.
Note that when using GitHub Actions OIDC, `pub.dev` only allows authentication when the workflow is triggered by a `tag` event. See [here](https://github.com/dart-lang/pub-dev/issues/8507) for more details.
#### Google Service Account
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`.
1. [Create a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects), if you don’t have an existing project.
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:
```bash
gcloud iam service-accounts create pub-dev \
--description='Service account to be impersonated when publishing to pub.dev' \
--display-name='pub-dev'
```3. Grant the service account permission to publish your package.
> To complete this step, you must have uploader permission on the package or be an admin of the publisher that owns the package.
1. Navigate to the package Admin tab (pub.dev/packages//admin).
2. Click Enable publishing with Google Cloud Service account.
3. Type the email of the service account into the Service account email field.
> You created this account in the previous step: `pub-dev@$PROJECT_ID.iam.gserviceaccount.com`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:
```bash
gcloud iam service-accounts keys create key-file.json \
PROJECT_ID.iam.gserviceaccount.com
```5. Copy the content of the JSON key file and set it as an environment variable under `GOOGLE_SERVICE_ACCOUNT_KEY`.
#### GitHub Actions OIDC
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.
1. Enable automated publishing.
> To complete this step, you must have uploader permission on the package or be an admin of the publisher that owns the package.
1. Navigate to the package Admin tab (pub.dev/packages//admin).
2. Click Enable publishing from GitHub Actions.
3. Then fill in the necessary information.
2. In your workflow, add the `id-token` permission.```yaml
jobs:
publish:
permissions:
id-token: write
```### Environment variables
| Variable | Description |
| ---------------------------- | ------------------------------------------------------------------------------------------------------- |
| `GOOGLE_SERVICE_ACCOUNT_KEY` | The google service account key created from the above steps. Not required if using GitHub Actions OIDC. |### Options
| Option | Description | Default |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `cli` | The `dart` or `flutter` CLI to use to publish the package to the registry. | `dart` |
| `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
| `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` |
| `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` |### Examples
#### Publishing a Flutter package
```json
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-pub",
{
"cli": "flutter"
}
]
]
}
```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.
#### Using GitHub Actions OIDC
```json
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-pub",
{
"useGithubOidc": true
}
]
]
}
```