如何从 Azure Pipeline 将 Dart 包发布到 pub.dev

问题描述 投票:0回答:1

我想从基于 yaml 的 Azure Pipeline 将 Dart 包发布到 pub.dev。 我查看了以下有关 Dart 包自动发布的文档,但它没有提到 Azure Pipelines。 https://dart.dev/tools/pub/automated-publishing

此外,我猜测我的 Azure DevOps 项目需要 pub.dev 的服务连接(就像我们目前为 NuGet 包提供 NuGet.org 的服务连接一样),但我没有看到任何与 pub 相关的内容。 dev 在可用服务连接列表中。

如何设置从 Azure DevOps 到 pub.dev 的自动 dart 包部署管道?

flutter dart azure-devops azure-pipelines dart-pub
1个回答
0
投票

截至目前,

dart
SDK 尚未安装在 Microsoft 托管的代理上,并且没有开箱即用的管道任务供我们验证对 Google Cloud 的访问并发布包 pub.dev。

根据您的要求和使用导出的服务帐户密钥从任何地方发布的文档,我测试了下面的工作流程,该工作流程对我有用。

  1. 在 Google Cloud 中创建一个服务帐户(在我的例子中是
    sa-devops
    );然后创建并下载密钥json文件; (保持密钥安全,因为它们是长期秘密;它们在某些环境中可能更容易使用,但如果意外泄露也会带来更大的风险) [![在此处输入图像描述][1]][1]
  2. 在软件包的
    Admin
    选项卡中启用使用 Google Cloud Service 帐户进行发布,并输入服务帐户电子邮件; [![在此处输入图像描述][2]][2]
  3. 将密钥文件(在我的示例中为
    GCloudKey.json
    )上传到Azure Pipelines的
    Secure File
    库中; [![在此处输入图像描述][3]][3]
  4. 使用下面的管道在
    dart
    Microsoft 托管代理上安装
    ubuntu-latest
    -> 下载安全密钥文件 -> 根据密钥文件验证对 Google Cloud 的访问 -> 将新版本的测试包发布到 pub.dev;
    pool:
      vmImage: ubuntu-latest
    
    stages:
    - stage: PublishToPubDev
      jobs:
      - job: Dart_Auth_Publish
        steps:
        - script: |
            sudo apt update
            sudo apt install apt-transport-https
            sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
            sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
            sudo apt update
            sudo apt install dart
          displayName: 'Install Dart'
        - script: |
            dart --version
            gcloud version
          displayName: 'Verify Dart and GCloud Installation'
        - task: DownloadSecureFile@1
          inputs:
            secureFile: 'GCloudKey.json'
          name: DownloadGCloudKey
        - script: |
            echo The downloaded GCloudkey file is $(DownloadGCloudKey.secureFilePath)
            gcloud auth activate-service-account --key-file=$(DownloadGCloudKey.secureFilePath)
            gcloud auth print-identity-token --audiences=https://pub.dev | dart pub token add https://pub.dev
            dart pub publish --force
          displayName: Publish to pub.dev
          workingDirectory: XXXXtestpackage # The directory in $(System.DefaultWorkingDirectory) where my package is located
    
    


  [1]: https://i.stack.imgur.com/syBpX.png
  [2]: https://i.stack.imgur.com/bDyJ9.png
  [3]: https://i.stack.imgur.com/EtC31.png
© www.soinside.com 2019 - 2024. All rights reserved.