-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
263 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
name: build apk | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
TAG: | ||
description: 'Set a Verson' | ||
required: true | ||
default: '1.0' | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- main | ||
- master | ||
tags-ignore: | ||
- v** | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Release build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/checkout@v3 | ||
|
||
# - name: Use Node.js | ||
# uses: actions/setup-node@v3 | ||
# - name: Install dependencies | ||
# run: npm install -g gitmoji-changelog | ||
- name: Setup JDK | ||
uses: actions/setup-java@v1 | ||
with: | ||
|
@@ -57,9 +63,7 @@ jobs: | |
for name in $(ls releases/*-signed.apk);do mv -f $name ${name%-signed.apk}.apk ;done | ||
ls releases | ||
- name: Release to github | ||
uses: ncipollo/[email protected] | ||
with: | ||
allowUpdates: true | ||
artifacts: "releases/*-release.apk" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.event.inputs.TAG }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
dart scripts/github.dart --token=${{ secrets.GITHUB_TOKEN }} --fun=release --artifacts=releases/*-release.apk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
name: build mac | ||
name: build mac-dmg | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
TAG: | ||
description: 'Set a Verson' | ||
required: true | ||
default: '1.0' | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- main | ||
- master | ||
tags-ignore: | ||
- v** | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: "Build MacOS" | ||
runs-on: macos-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/checkout@v3 | ||
|
||
# - name: Use Node.js | ||
# uses: actions/setup-node@v3 | ||
# - name: Install dependencies | ||
# run: npm install -g gitmoji-changelog | ||
|
||
- name: Setup flutter | ||
uses: subosito/[email protected] | ||
|
@@ -49,23 +55,29 @@ jobs: | |
- name: Compress artifacts | ||
run: zip -r macos-${{ github.event.inputs.TAG }}.zip build/macos/Build/Products/Release | ||
|
||
- name: Upload artifacts to release | ||
uses: svenstaro/[email protected] | ||
with: | ||
# GitHub token. | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
# Local file to upload. | ||
file: macos-${{ github.event.inputs.TAG }}.zip | ||
# Tag to use as a release. | ||
tag: ${{ github.event.inputs.TAG }} | ||
- name: Release to github | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
dart scripts/github.dart --token=${{ secrets.GITHUB_TOKEN }} --fun=release --artifacts=build/macos/Build/Products/Release/rescue_my_beauty.dmg | ||
- name: Upload DMG to release | ||
uses: svenstaro/[email protected] | ||
with: | ||
# GitHub token. | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
# Local file to upload. | ||
file: build/macos/Build/Products/Release/rescue_my_beauty.dmg | ||
asset_name: rescue_my_beauty-macos-${{ github.event.inputs.TAG }}.dmg | ||
# Tag to use as a release. | ||
tag: ${{ github.event.inputs.TAG }} | ||
# - name: Upload artifacts to release | ||
# uses: svenstaro/[email protected] | ||
# with: | ||
# # GitHub token. | ||
# repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
# # Local file to upload. | ||
# file: macos-${{ github.event.inputs.TAG }}.zip | ||
# # Tag to use as a release. | ||
# tag: ${{ github.event.inputs.TAG }} | ||
# | ||
# - name: Upload DMG to release | ||
# uses: svenstaro/[email protected] | ||
# with: | ||
# # GitHub token. | ||
# repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
# # Local file to upload. | ||
# file: build/macos/Build/Products/Release/rescue_my_beauty.dmg | ||
# asset_name: rescue_my_beauty-macos-${{ github.event.inputs.TAG }}.dmg | ||
# # Tag to use as a release. | ||
# tag: ${{ github.event.inputs.TAG }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
name: build windows | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
TAG: | ||
description: 'Set a Tag' | ||
required: true | ||
default: '' | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- main | ||
- master | ||
tags-ignore: | ||
- v** | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Release build | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
# - name: Use Node.js | ||
# uses: actions/setup-node@v3 | ||
# - name: Install dependencies | ||
# run: npm install -g gitmoji-changelog | ||
- name: Setup JDK | ||
uses: actions/setup-java@v1 | ||
with: | ||
|
@@ -32,10 +39,15 @@ jobs: | |
flutter build windows --release --no-tree-shake-icons | ||
dir build/windows/runner/Release | ||
Compress-Archive -Path build/windows/runner/Release/* windows-win32-release.zip -Force | ||
- name: Release build | ||
uses: ncipollo/[email protected] | ||
with: | ||
allowUpdates: true | ||
artifacts: "*-release.zip" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.event.inputs.TAG }} | ||
- name: Release to github | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
dart scripts/github.dart --token=${{ secrets.GITHUB_TOKEN }} --fun=release --artifacts=*-release.zip | ||
# - name: Release build | ||
# uses: ncipollo/[email protected] | ||
# with: | ||
# allowUpdates: true | ||
# artifacts: "*-release.zip" | ||
# token: ${{ secrets.GITHUB_TOKEN }} | ||
# tag: ${{ github.event.inputs.TAG }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:glob/glob.dart'; | ||
import 'package:glob/list_local_fs.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:process_run/shell.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
enum Fun { | ||
release, | ||
} | ||
|
||
Future<void> main(List<String> arguments) async { | ||
var parser = ArgParser() | ||
..addOption('fun', abbr: 'f', allowed: Fun.values.map((e) => e.name)) | ||
..addOption('token', abbr: 't') | ||
..addOption('artifacts', abbr: 'a'); | ||
print(arguments); | ||
|
||
var parse = parser.parse(arguments); | ||
var token = parse['token']; | ||
var artifacts = parse['artifacts']; | ||
var shell = Shell(); | ||
var result = await shell.run("git remote -v"); | ||
var urlParts = | ||
result.first.stdout.toString().trim().split("\n").last.split("/"); | ||
var repo = [ | ||
urlParts[urlParts.length - 2], | ||
urlParts[urlParts.length - 1].split(" ").first.replaceAll(".git", '') | ||
].join("/"); | ||
switch (Fun.values.firstWhere((e) => e.name == parse['fun'])) { | ||
case Fun.release: | ||
await _release( | ||
shell: shell, | ||
repo: repo, | ||
token: token, | ||
artifacts: artifacts, | ||
); | ||
break; | ||
} | ||
} | ||
|
||
Future<void> _release({ | ||
required Shell shell, | ||
required String token, | ||
required String repo, | ||
required String artifacts, | ||
}) async { | ||
await shell.run("git remote set-url origin https://$token@github.com/$repo"); | ||
var result = await shell.run("git show -s"); | ||
var commitId = | ||
RegExp(r"\s([a-z\d]{40})\s").firstMatch(result.first.stdout)?.group(1); | ||
if (commitId == null) { | ||
throw StateError("Can't get ref."); | ||
} | ||
result = await shell.run('git log --pretty=format:"%an;%ae" $commitId -1'); | ||
var pair = result.first.stdout.toString().split(";"); | ||
var ref = commitId.substring(0, 7); | ||
var root = Directory.current; | ||
var pubspec = File(join(root.path, 'pubspec.yaml')); | ||
var yaml = loadYaml(pubspec.readAsStringSync()); | ||
var version = yaml['version'] as String; | ||
var verArr = version.split('+'); | ||
var tag = "v${verArr.first}_$ref"; | ||
// result = await shell.run("git branch"); | ||
// var branch = result.first.stdout | ||
// .toString() | ||
// .split("\n") | ||
// .firstWhere((e) => e.startsWith("*")) | ||
// .split(" ") | ||
// .last; | ||
result = await shell.run("git ls-remote --tags"); | ||
var tags = result.first.stdout.toString(); | ||
var has = | ||
tags.split("\n").any((s) => s.split("refs/tags/").last.startsWith(tag)); | ||
if (!has) { | ||
try { | ||
await shell.run("git" | ||
" -c user.name=${pair[0]}" | ||
" -c user.email=${pair[1]}" | ||
" tag $tag"); | ||
await shell.run("git push origin $tag"); | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
dynamic id; | ||
|
||
/// 检查tag是否发布 | ||
try { | ||
var response = await shell.run( | ||
'gh api -H "Accept: application/vnd.github+json" /repos/$repo/releases/tags/$tag'); | ||
id = jsonDecode(response.first.stdout.toString())?['id']; | ||
} catch (e) { | ||
print(e); | ||
} | ||
print('tag id: $id'); | ||
|
||
/// tag未发布则创建release | ||
if (id == null) { | ||
try { | ||
var response = await shell | ||
.run('gh api --method POST -H "Accept: application/vnd.github+json" ' | ||
'/repos/$repo/releases ' | ||
'-f tag_name=$tag ' | ||
'-f target_commitish=master ' | ||
'-f name=$tag ' | ||
'-f body="" ' | ||
'-F draft=false ' | ||
'-F prerelease=false ' | ||
'-F generate_release_notes=false'); | ||
id = jsonDecode(response.first.stdout.toString())?['id']; | ||
|
||
// /// 发布Changelog | ||
// var logResponse = await shell.run('gitmoji-changelog ${verArr.first}'); | ||
// if (logResponse.first.stdout.toString().contains("success")) { | ||
// await shell.run( | ||
// 'git commit CHANGELOG.md -m"update changelog_${verArr.first}"'); | ||
// await shell.run('git push origin'); | ||
// } | ||
|
||
} catch (e) { | ||
print(e); | ||
} | ||
if (id == null) { | ||
throw StateError(result.first.stdout); | ||
} | ||
} | ||
print('release id: $id'); | ||
|
||
/// 获取所有文件 | ||
var files = Glob(artifacts, recursive: true).listSync(root: root.path); | ||
print("filesLength ${files.length}"); | ||
|
||
/// 获取当前release的所有文件 | ||
var assetsResult = await shell.run( | ||
'gh api -H "Accept: application/vnd.github+json" /repos/$repo/releases/$id/assets'); | ||
|
||
var assets = jsonDecode(assetsResult.first.stdout.toString()) as List?; | ||
print('assets: ${assets?.map((e) => e['name'])}'); | ||
|
||
for (var file in files) { | ||
if (file is File) { | ||
var filePath = file.absolute.path; | ||
var fileName = basename(filePath); | ||
print('prepare upload: $filePath'); | ||
var exist = assets?.firstWhereOrNull((e) { | ||
return e['name'] == fileName; | ||
}); | ||
if (exist != null) { | ||
print('exist asset: ${exist?['name']}'); | ||
// delete exist assert | ||
var deleteResponse = await shell.run( | ||
'gh api -H "Accept: application/vnd.github+json" --method DELETE /repos/$repo/releases/assets/${exist?['id']}'); | ||
|
||
print('delete end: ${deleteResponse.first.stdout}'); | ||
} | ||
// upload asset. | ||
var uploadResponse = await shell.run('gh release upload $tag $filePath'); | ||
|
||
print('upload end: ${uploadResponse.first.stdout}, $filePath'); | ||
} | ||
} | ||
print('task end'); | ||
exit(0); | ||
} |