Skip to content

Latest commit

 

History

History
120 lines (88 loc) · 7.44 KB

README.md

File metadata and controls

120 lines (88 loc) · 7.44 KB

semantic-release-pub

npm License GitHub Actions codecov Codacy Badge Code Style

Github-sponsors BuyMeACoffee Ko-Fi LiberaPay Patreon PayPal

semantic-release plugin to publish a Dart or Flutter 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 or Flutter package to the registry.

Installation

Install via npm:

npm install --save-dev semantic-release-pub

Or via yarn:

yarn add --dev semantic-release-pub

Usage

The plugin can be configured in the semantic-release configuration file:

{
  "plugins": [
    "@semantic-release/commit-analyzer", 
    "@semantic-release/release-notes-generator", 
    "semantic-release-pub"
  ]
}

Configuration

pub.dev authentication

The following instructions are referenced from the documentation of Dart. Below are the key steps to allow authentication to pub.dev.

  1. Create a Google Cloud project, if you don’t have an existing project.

  2. Create a service account either through the Google Cloud Console under IAM and admin > Service accounts or as follow:

    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 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:

    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.

Environment variables

Variable Description
GOOGLE_SERVICE_ACCOUNT_KEY The google service account key created from the above steps.

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. false

Examples

Publishing a Flutter package

{
  "plugins": [
    "@semantic-release/commit-analyzer", 
    "@semantic-release/release-notes-generator", 
    [
      "semantic-release-pub",
      {
        "cli": "flutter"
      }
    ]
  ]
}

See here for a sample pull request utilising this plugin and semantic-release to publish a Flutter package.