-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增 支持查询版本信息 新增 支持通过右键菜单复制策略标题和简短描述 新增 完整重启Edge功能 新增 发布新版本时同步向Gitee推送提交并创建发行版 优化 支持枚举的策略现在显示已选选项名称而不是策略值 优化 Github Action执行逻辑 优化 繁体中文翻译文本 调整 主页排版 调整 编辑字符串或整型策略时现在显示一个保存按钮 调整 限制策略编辑控件最大宽度 调整 限制窗口最小尺寸 调整 使用SDK内置转换器替换自制转换器 调整 Release附件命名 调整 README.md 更新 策略配置文件至122.0.2365.3版本 更新 Github Action依赖版本
- Loading branch information
Showing
42 changed files
with
1,184 additions
and
427 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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
const fs = require('fs'); | ||
const {execSync} = require('child_process'); | ||
const github = require('@actions/github'); | ||
const {Octokit} = require('@octokit/rest'); | ||
|
||
function notice(msg) { | ||
console.log(`* ${msg}`); | ||
} | ||
|
||
function retry(fn, retryCount = 0) { | ||
return fn().catch((e) => { | ||
if (retryCount >= 3) { | ||
throw e; | ||
} | ||
console.error(e); | ||
console.warn(`第 ${retryCount + 1} 次执行失败,正在重试……`); | ||
return retry(fn, retryCount + 1); | ||
}); | ||
} | ||
|
||
(async () => { | ||
const owner = github.context.repo.owner; | ||
const repo = github.context.repo.repo; | ||
|
||
await Promise.all(['x64', 'x86', 'arm64'].map((arch) => { | ||
execSync(`dotnet publish -p:Platform=${arch} -p:PublishProfile=Properties/PublishProfiles/win-${arch}.pubxml`); | ||
notice(`${arch} 架构软件包生成完成。`); | ||
execSync(`7z a -tzip Publish-${arch}.zip ./bin/publish/win-${arch}/*`); | ||
execSync(`7z a -t7z Publish-${arch}.7z ./bin/publish/win-${arch}/*`); | ||
notice(`${arch} 架构软件包压缩完成。`); | ||
})); | ||
|
||
const files = [ | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x64.zip', | ||
path: 'Publish-x64.zip', | ||
contentType: 'application/zip' | ||
}, | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x64.7z', | ||
path: 'Publish-x64.7z', | ||
contentType: 'application/7z' | ||
}, | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x86.zip', | ||
path: 'Publish-x86.zip', | ||
contentType: 'application/zip' | ||
}, | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x86.7z', | ||
path: 'Publish-x86.7z', | ||
contentType: 'application/7z' | ||
}, | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-arm64.zip', | ||
path: 'Publish-arm64.zip', | ||
contentType: 'application/zip' | ||
}, | ||
{ | ||
name: 'EdgePolicyManager-v${PUBLISH_VERSION}-arm64.7z', | ||
path: 'Publish-arm64.7z', | ||
contentType: 'application/7z' | ||
} | ||
]; | ||
|
||
function handleEnv(str) { | ||
return str.replace(/\$\{(.+?)}/g, (_, name) => { | ||
return process.env[name]; | ||
}); | ||
} | ||
|
||
// GitHub Release | ||
let releaseInfo; | ||
{ | ||
const githubO = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN | ||
}); | ||
|
||
const release = await githubO.repos.createRelease({ | ||
owner, repo, | ||
tag_name: `v${process.env.PUBLISH_VERSION}`, | ||
name: `Release ${process.env.PUBLISH_VERSION}`, | ||
body: `## 更新日志\n\n概述:**${process.env.COMMIT_TITLE}**\n\n<details>\n\n${process.env.COMMIT_BODY}\n\n</details>\n\n<hr>\n\n> 发布时间:${process.env.PUBLISH_DATETIME}\n\n> 策略版本:${process.env.EDGE_POLICY_VERSION}`, | ||
draft: false, | ||
prerelease: false | ||
}); | ||
|
||
const releaseId = release.data.id; | ||
|
||
for (const file of files) { | ||
// 上传到upload_url | ||
await githubO.repos.uploadReleaseAsset({ | ||
release_id: releaseId, | ||
owner, repo, | ||
name: handleEnv(file.name), | ||
data: fs.readFileSync(file.path) | ||
}); | ||
} | ||
|
||
releaseInfo = await githubO.repos.getRelease({ | ||
release_id: releaseId, | ||
owner, repo | ||
}); | ||
} | ||
notice('GitHub Release 发布完成。'); | ||
|
||
// Gitee Release | ||
{ | ||
const giteeO = new Octokit({ | ||
baseUrl: 'https://gitee.com/api/v5', | ||
auth: process.env.GITEE_TOKEN | ||
}); | ||
|
||
function fileSizeString(size) { | ||
if (size < 1024) { | ||
return `${size} B`; | ||
} else if (size < 1024 * 1024) { | ||
return `${(size / 1024).toFixed(2)} KB`; | ||
} else if (size < 1024 * 1024 * 1024) { | ||
return `${(size / 1024 / 1024).toFixed(2)} MB`; | ||
} else if (size < 1024 * 1024 * 1024 * 1024) { | ||
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`; | ||
} else { | ||
return `${(size / 1024 / 1024 / 1024 / 1024).toFixed(2)} TB`; | ||
} | ||
} | ||
|
||
let assetsTable = "|附件|大小|\n|---|---|\n", | ||
assetIcon = "![asset icon](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20width%3D%2216%22%3E%3Cpath%20d%3D%22m8.878.392%205.25%203.045c.54.314.872.89.872%201.514v6.098a1.75%201.75%200%200%201-.872%201.514l-5.25%203.045a1.75%201.75%200%200%201-1.756%200l-5.25-3.045A1.75%201.75%200%200%201%201%2011.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75%201.75%200%200%201%201.756%200ZM7.875%201.69l-4.63%202.685L8%207.133l4.755-2.758-4.63-2.685a.248.248%200%200%200-.25%200ZM2.5%205.677v5.372c0%20.09.047.171.125.216l4.625%202.683V8.432Zm6.25%208.271%204.625-2.683a.25.25%200%200%200%20.125-.216V5.677L8.75%208.432Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E)"; | ||
for (const asset of releaseInfo.data.assets) { | ||
assetsTable += `|${assetIcon} [${asset.name}](${asset.browser_download_url})|${fileSizeString(asset.size)}|\n`; | ||
} | ||
|
||
await retry(() => giteeO.repos.createRelease({ | ||
owner, repo, | ||
tag_name: `v${process.env.PUBLISH_VERSION}`, | ||
target_commitish: process.env.CONFIG === 'debug' ? 'test' : 'master', | ||
name: `发行版 ${process.env.PUBLISH_VERSION}`, | ||
body: `## 更新日志\n\n概述:**${process.env.COMMIT_TITLE}**\n\n<details>\n\n${process.env.COMMIT_BODY}\n\n</details>\n\n<hr>\n\n> 发布时间:${process.env.PUBLISH_DATETIME}\n\n> 策略版本:${process.env.EDGE_POLICY_VERSION}\n\n${assetsTable}`, | ||
prerelease: false | ||
})); | ||
} | ||
notice('Gitee Release 发布完成。'); | ||
})(); |
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,40 @@ | ||
const fs = require('fs'); | ||
const {XMLParser, XMLBuilder} = require('fast-xml-parser'); | ||
|
||
(async () => { | ||
const {PUBLISH_VERSION} = process.env; | ||
|
||
const csprojPath = './PolicyManager.csproj'; | ||
const csprojData = fs.readFileSync(csprojPath); | ||
|
||
// 解析XML | ||
const options = { | ||
ignoreAttributes: false, | ||
attributeNamePrefix: '@', | ||
suppressEmptyNode: true, | ||
format: process.env.CONFIG === 'debug' | ||
}; | ||
|
||
const parser = new XMLParser(options); | ||
const csprojObj = parser.parse(csprojData); | ||
|
||
// 修改版本号 | ||
if (csprojObj.Project?.PropertyGroup) { | ||
const config = csprojObj.Project.PropertyGroup.find((item) => item["Version"]); | ||
if (!config) { | ||
console.log(JSON.stringify(csprojObj.Project.PropertyGroup)); | ||
throw new Error('Cannot find version property.'); | ||
} | ||
config["Version"] = PUBLISH_VERSION; | ||
} else { | ||
console.log(JSON.stringify(csprojObj)); | ||
throw new Error('Cannot find PropertyGroup.'); | ||
} | ||
|
||
// 转换为XML字符串 | ||
const builder = new XMLBuilder(options); | ||
const xml = builder.build(csprojObj); | ||
|
||
// 写回.csproj文件 | ||
fs.writeFileSync(csprojPath, xml); | ||
})(); |
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 |
---|---|---|
|
@@ -8,10 +8,15 @@ on: | |
jobs: | ||
publish: | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
node-version: [ 20.x ] | ||
env: | ||
CONFIG: Release | ||
|
||
steps: | ||
- name: 检出代码 | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
|
||
- name: 获取发布信息 | ||
run: | | ||
|
@@ -30,109 +35,40 @@ jobs: | |
} >> "$GITHUB_ENV" | ||
shell: bash | ||
|
||
- name: 创建 Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ env.PUBLISH_VERSION }} | ||
release_name: Release ${{ env.PUBLISH_VERSION }} | ||
body: | | ||
## 更新日志 | ||
概述:**${{ env.COMMIT_TITLE }}** | ||
<details> | ||
${{ env.COMMIT_BODY }} | ||
</details> | ||
<hr> | ||
> 发布时间:${{ env.PUBLISH_DATETIME }} | ||
> 策略版本:${{ env.EDGE_POLICY_VERSION }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: 安装 .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: 生成软件包 | ||
- name: 修改版本号 | ||
run: | | ||
dotnet publish -p:Platform=x64 -p:PublishProfile=Properties/PublishProfiles/win-x64.pubxml | ||
dotnet publish -p:Platform=x86 -p:PublishProfile=Properties/PublishProfiles/win-x86.pubxml | ||
dotnet publish -p:Platform=ARM64 -p:PublishProfile=Properties/PublishProfiles/win-arm64.pubxml | ||
npm i fast-xml-parser | ||
node .github/workflows/edit_version.js | ||
- name: 压缩软件包 | ||
- name: 克隆完整仓库 | ||
run: | | ||
7z a -tzip -mx=9 Publish-x64.zip ./bin/publish/win-x64/* | ||
7z a -t7z -mx=9 Publish-x64.7z ./bin/publish/win-x64/* | ||
7z a -tzip -mx=9 Publish-x86.zip ./bin/publish/win-x86/* | ||
7z a -t7z -mx=9 Publish-x86.7z ./bin/publish/win-x86/* | ||
7z a -tzip -mx=9 Publish-arm64.zip ./bin/publish/win-arm64/* | ||
7z a -t7z -mx=9 Publish-arm64.7z ./bin/publish/win-arm64/* | ||
git fetch --unshallow | ||
- name: 上传软件包(x64-zip) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-x64.zip | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.zip | ||
asset_content_type: application/zip | ||
|
||
- name: 上传软件包(x64-7z) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-x64.7z | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.7z | ||
asset_content_type: application/7z | ||
- name: 优化 Gitee 连接 | ||
run: | | ||
echo 182.255.33.134 gitee.com >> C:\Windows\System32\drivers\etc\hosts | ||
ipconfig /flushdns | ||
- name: 上传软件包(x86-zip) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: 同步分支到 Gitee | ||
uses: nick-fields/retry@v3 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-x86.zip | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.zip | ||
asset_content_type: application/zip | ||
|
||
- name: 上传软件包(x86-7z) | ||
uses: actions/upload-release-asset@v1 | ||
timeout_minutes: 5 | ||
max_attempts: 3 | ||
command: | | ||
git fetch --unshallow | ||
git push -f "https://NXY666:$env:[email protected]/NXY666/EdgePolicyManager.git" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-x86.7z | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.7z | ||
asset_content_type: application/7z | ||
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} | ||
|
||
- name: 上传软件包(arm64-zip) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: 安装 .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-arm64.zip | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.zip | ||
asset_content_type: application/zip | ||
dotnet-version: '8.0.x' | ||
|
||
- name: 上传软件包(arm64-7z) | ||
uses: actions/upload-release-asset@v1 | ||
- name: 发布软件包 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Publish-arm64.7z | ||
asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.7z | ||
asset_content_type: application/7z | ||
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} | ||
run: | | ||
npm i @actions/github @octokit/rest | ||
node .github/workflows/create_release.js |
Oops, something went wrong.