一、创建package或plugin
先创建一个package或者plugin
二、手动上传第一个版本到pub.dev
flutter packages pub publish --server=https://pub.dartlang.org
三、在admin配置自动化发布
打开pub.dev中的对应的package按照以下图片配置
四、在项目跟目录配置发布脚本
1、在项目根目录创建 .github/workflows/publish.yml文件
2、文件脚本如下:
name: Publish to Pub.dev# 流程触发时机,create当有标签tag创建时触发,如 v1.0.0。当然也可以选择别的触发时机,如 push,release 等
on: create
# push:
# branches:
# - masterjobs:publishing:runs-on: ubuntu-lateststeps:# 拉取仓库代码- name: "Checkout"uses: actions/checkout # 发布插件- name: Dart and Flutter Package Publisheruses: k-paxian/dart-package-publisherwith:accessToken: ${{ secrets.OAUTH_ACCESS_TOKEN }}refreshToken: ${{ secrets.OAUTH_REFRESH_TOKEN }}suppressBuildRunner: trueflutter: trueskipTests: trueforce: true
k-paxian/dart-package-publisher的参数请看GitHub:dart-package-publisher
五、在github的项目设置中设置token
1、打开github中对应项目的setting
2、分别添加token:OAUTH_ACCESS_TOKEN和OAUTH_REFRESH_TOKEN
在文件目录找到pub-credentials复制这两个token
On Mac OS:
~/Library/Application Support/dart/pub-credentials.json
On Windows:
%APPDATA%/dart/pub-credentials.json
六、测试
1、提交代码或者创建tag测试CI脚本执行是否发布成功
git tag v0.4.0
git push --tags
七、报错
Package validation found the following potential issue:
374* `dart analyze` found the following issue(s):
375 Analyzing lib, pubspec.yaml...
376
377 warning - lib/version_xupdate/utils/common.dart:89:32 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion
378 warning - lib/version_xupdate/utils/common.dart:91:19 - The '!' will have no effect because the receiver can't be null. Try removing the '!' operator. - unnecessary_non_null_assertion
379 info - lib/version_xupdate/dialog/number_progress.dart:29:3 - Constructors in '@immutable' clas[...]e identifier. Try changing the name to follow the lowerCamelCase style. - constant_identifier_names
380 info - lib/zupdate.dart:86:3 - The constant name 'DOWNLOAD_ERROR' isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase style. - constant_identifier_names
381 info - lib/zupdate.dart:91:3 - The constant name 'CHECKSUM_ERROR' isn't a lowerCamelCase identifier. Try changing the name to follow the lowerCamelCase style. - constant_identifier_names
382
383 37 issues found.
384
385Package has 1 warning.
386pub finished with exit code 65
387Error: Dry 🏃 Failed, skip real publishing.
解决办法:脚本中with需要设置参数:force: true